Skip to content

Commit 38147f5

Browse files
committed
Fix != operator definition
Problem: If a class declare the not-equal operator `!=`, the parsing is wrong. For instance, the folowing program: class A def !=(other); end end is parsed as if the method `!` was a defined with the body expression syntax leading to the following tree: (program [0, 0] - [3, 0] (class [0, 0] - [1, 20] name: (constant [0, 6] - [0, 7]) body: (body_statement [1, 2] - [1, 16] (method [1, 2] - [1, 15] name: (operator [1, 6] - [1, 7]) body: (parenthesized_statements [1, 8] - [1, 15] (identifier [1, 9] - [1, 14]))))) (identifier [2, 0] - [2, 3])) Solution: Declare `!=` as a possible operator definition.
1 parent 0ffe457 commit 38147f5

File tree

4 files changed

+133831
-133686
lines changed

4 files changed

+133831
-133686
lines changed

grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ module.exports = grammar({
10251025
)),
10261026

10271027
operator: _ => choice(
1028-
'..', '|', '^', '&', '<=>', '==', '===', '=~', '>', '>=', '<', '<=', '+',
1028+
'..', '|', '^', '&', '<=>', '==', '===', '=~', '>', '>=', '<', '<=', '+', '!=',
10291029
'-', '*', '/', '%', '!', '!~', '**', '<<', '>>', '~', '+@', '-@', '~@', '[]', '[]=', '`',
10301030
),
10311031

src/grammar.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)