diff --git a/grammar.js b/grammar.js index a6a48a9..185b543 100644 --- a/grammar.js +++ b/grammar.js @@ -193,7 +193,7 @@ module.exports = grammar({ PREC.assign, seq( field("left", $._lvalue), - ":=", + alias(":=", $.operator), field("right", $._expr), ), ), @@ -223,7 +223,7 @@ module.exports = grammar({ for_expression: ($) => seq( "for", field("index", $.identifier), - ":=", + alias(":=", $.operator), field("start", $._expr), "to", field("end", $._expr), @@ -325,7 +325,7 @@ module.exports = grammar({ "var", field("name", $.identifier), optional(seq(":", field("type", $._type_identifier))), - ":=", + alias(":=", $.operator), field("value", $._expr), ), diff --git a/src/grammar.json b/src/grammar.json index edb5155..f5b0dfc 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -822,8 +822,13 @@ } }, { - "type": "STRING", - "value": ":=" + "type": "ALIAS", + "content": { + "type": "STRING", + "value": ":=" + }, + "named": true, + "value": "operator" }, { "type": "FIELD", @@ -939,8 +944,13 @@ } }, { - "type": "STRING", - "value": ":=" + "type": "ALIAS", + "content": { + "type": "STRING", + "value": ":=" + }, + "named": true, + "value": "operator" }, { "type": "FIELD", @@ -1469,8 +1479,13 @@ ] }, { - "type": "STRING", - "value": ":=" + "type": "ALIAS", + "content": { + "type": "STRING", + "value": ":=" + }, + "named": true, + "value": "operator" }, { "type": "FIELD", diff --git a/src/node-types.json b/src/node-types.json index d8e1a14..e9aba88 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -389,6 +389,16 @@ } ] } + }, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "operator", + "named": true + } + ] } }, { @@ -811,6 +821,16 @@ } ] } + }, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "operator", + "named": true + } + ] } }, { @@ -2067,6 +2087,16 @@ } ] } + }, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "operator", + "named": true + } + ] } }, { @@ -2255,10 +2285,6 @@ "type": ":", "named": false }, - { - "type": ":=", - "named": false - }, { "type": ";", "named": false diff --git a/src/parser.c b/src/parser.c index a93aeb0..06ee35e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -136,7 +136,7 @@ static const char * const ts_symbol_names[] = { [anon_sym_of] = "of", [anon_sym_LBRACE] = "{", [anon_sym_RBRACE] = "}", - [anon_sym_COLON_EQ] = ":=", + [anon_sym_COLON_EQ] = "operator", [anon_sym_if] = "if", [anon_sym_then] = "then", [anon_sym_else] = "else", @@ -227,7 +227,7 @@ static const TSSymbol ts_symbol_map[] = { [anon_sym_of] = anon_sym_of, [anon_sym_LBRACE] = anon_sym_LBRACE, [anon_sym_RBRACE] = anon_sym_RBRACE, - [anon_sym_COLON_EQ] = anon_sym_COLON_EQ, + [anon_sym_COLON_EQ] = anon_sym_DASH, [anon_sym_if] = anon_sym_if, [anon_sym_then] = anon_sym_then, [anon_sym_else] = anon_sym_else, @@ -407,7 +407,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { }, [anon_sym_COLON_EQ] = { .visible = true, - .named = false, + .named = true, }, [anon_sym_if] = { .visible = true, diff --git a/test/corpus/comments.txt b/test/corpus/comments.txt index 62f2cc7..70e0b88 100644 --- a/test/corpus/comments.txt +++ b/test/corpus/comments.txt @@ -112,10 +112,12 @@ end (comment) (variable_declaration (identifier) + (operator) (integer_literal)) (comment) (variable_declaration (identifier) + (operator) (integer_literal)) (comment) (comment) diff --git a/test/corpus/control_flow.txt b/test/corpus/control_flow.txt index 1c22b63..f3426df 100644 --- a/test/corpus/control_flow.txt +++ b/test/corpus/control_flow.txt @@ -65,6 +65,7 @@ for i := 12 to nil do "42" (source_file (for_expression index: (identifier) + (operator) start: (integer_literal) end: (nil_literal) body: (string_literal))) @@ -134,6 +135,7 @@ for i := break to break do while break do break (source_file (for_expression (identifier) + (operator) (break_expression) (break_expression) (while_expression diff --git a/test/corpus/declarations.txt b/test/corpus/declarations.txt index 98bdd2b..6383f93 100644 --- a/test/corpus/declarations.txt +++ b/test/corpus/declarations.txt @@ -217,6 +217,7 @@ var a := 12 (source_file (variable_declaration name: (identifier) + (operator) value: (integer_literal))) ================================================================================ @@ -231,6 +232,7 @@ var a : int := 27 (variable_declaration name: (identifier) type: (type_identifier) + (operator) value: (integer_literal))) ================================================================================ @@ -245,9 +247,11 @@ var b := 27 (source_file (variable_declaration name: (identifier) + (operator) value: (integer_literal)) (variable_declaration name: (identifier) + (operator) value: (integer_literal))) ================================================================================ diff --git a/test/corpus/expressions.txt b/test/corpus/expressions.txt index 8d2520a..8555035 100644 --- a/test/corpus/expressions.txt +++ b/test/corpus/expressions.txt @@ -150,10 +150,12 @@ a := array[12] := record.field (source_file (assignment_expression left: (identifier) + (operator) right: (assignment_expression left: (array_value array: (identifier) index: (integer_literal)) + (operator) right: (record_value record: (identifier) field: (field_identifier)))))