atom / language-c

C support in Atom
Other
116 stars 154 forks source link

[C++] a < comparison followed by a >= comparison is tokenized wrongly #326

Closed Tralomine closed 5 years ago

Tralomine commented 5 years ago

Description

a < comparison followed by a >= comparison is tokenized wrongly

Steps to Reproduce

  1. try typing
    (x < x || x >= x)
  2. ???
  3. profit

image

Expected behavior: the comparisons operators should be all the same color and in only one token

Actual behavior: they are split and considered as

<span class="syntax--punctuation syntax--definition syntax--template syntax--bracket syntax--angle">&gt;</span>
<span class="syntax--keyword syntax--operator">=</span>

note: trying with multiples comparisons in this style always end with only the last one experiencing this behaviour

image

note: the first variable in the comparison is considered as

<span class="syntax--entity syntax--name syntax--function">x</span>

(and therefore is blue)

winstliu commented 5 years ago

Reproduced with the C++ tree-sitter grammar but not the C one.

Ben3eeE commented 5 years ago

Tree sitter parses this as:

template_function template_argument_list

Because there is a starting and ending angle bracket in the statement?

Which is scoped as punctuation.definition.template.bracket.angle because it isn't an operator when it's a template definition here: https://github.com/atom/language-c/blob/a355a4d4a019d5684c40072b81f24c89e58dc56f/grammars/tree-sitter-cpp.cson#L198-L201

The rule for > and < is only added to relational_expression to not conflict with templates: https://github.com/atom/language-c/blob/a355a4d4a019d5684c40072b81f24c89e58dc56f/grammars/tree-sitter-cpp.cson#L224-L225

maxbrunsfeld commented 5 years ago

Thanks for the report! The fix will ship in Atom 1.38 (and 1.38-beta0).