Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

A certain way of writing Ternary removes Syntax Highlighting of null #386

Closed
1 task done
finn-matti opened this issue Mar 26, 2020 · 8 comments · Fixed by #399
Closed
1 task done

A certain way of writing Ternary removes Syntax Highlighting of null #386

finn-matti opened this issue Mar 26, 2020 · 8 comments · Fixed by #399

Comments

@finn-matti
Copy link

finn-matti commented Mar 26, 2020

Prerequisites

Description

Null value looses coloration when colon is written on same line

Steps to Reproduce

See screenshots.

Actual behavior:

Screenshot 2020-03-26 at 09 59 26

Expected behavior:

Screenshot 2020-03-26 at 09 59 40

Reproduces how often:

Every time.

Versions

  • Atom : 1.45.0
  • Electron: 4.2.7
  • Chrome : 69.0.3497.128
  • Node : 10.11.0
  • macOS: 10.15.4

Additional Information

I raised the same issue earlier here but was referred to report it here. The maintainer said:

Issue belongs to this repository: https://github.com/atom/language-php
And is caused by null : interpreted as goto label.

@finn-matti
Copy link
Author

finn-matti commented Mar 30, 2020

@darangi Why was this closed? Could you not reproduce it? A comment would have been nice.

EDIT: Disregard and apologies. I got confused by the old issue and thought this one got closed. But you just added a label.

@Aerijo
Copy link

Aerijo commented Mar 30, 2020

This issue is not closed

@lee-dohm
Copy link
Contributor

lee-dohm commented Apr 1, 2020

Are the labels on the screenshots backward? Is the complaint that the null keyword is colored? Or not colored?

@finn-matti
Copy link
Author

finn-matti commented Apr 1, 2020 via email

@KapitanOczywisty
Copy link
Contributor

@lee-dohm null : is treated as goto label and not colored as keyword + ternary.

@sadick254
Copy link
Contributor

Using tree-sitter-php would solve this issue. tree-sitter-php produces a consistent syntax tree irregardless of formatting

// example 1
$test = true ? null : 'hello world';
// example 2
$test = true ? null : 
  'hello world';
// example 3
$test = true ? 
  null : 
  'hello world';

All the examples will produce

(program (php_tag) 
  (expression_statement 
    (assignment_expression 
      left: (variable_name (name)) 
      right: (conditional_expression 
      condition: (boolean) 
      body: (null) 
      alternative: (string)))) (text_interpolation))

There is a PR already to add tree-sitter-php grammar

@KapitanOczywisty
Copy link
Contributor

@sadick254 PR is out of date and not complete. Above that, It will not solve issue in vscode.

It will be very hard to fix this issue since TM grammar is rather hopeless when comes to multi-line rules. I was trying to find solution to this, but failed.

KapitanOczywisty added a commit to KapitanOczywisty/language-php that referenced this issue Aug 29, 2020
@KapitanOczywisty
Copy link
Contributor

@finn-matti @sadick254 This took embarrassingly long time (a few hours at least, this time..), but I've fixed this and there will be PR shortly ;)

This wasn't that complicated after all, basically I had to make goto label rule with higher priority in ternary and what important without colon itself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants