Update Variable Declarations

Refactor a literal '=' to a production and allow expressions
of string-literal type.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-01-30 08:24:44 -05:00
parent 4c5b75bb4f
commit d8f6ff3b0b
2 changed files with 154 additions and 2 deletions
+3 -2
View File
@@ -66,7 +66,7 @@ export default grammar({
parserTypeDeclaration: $ => seq(optional($.annotations), $.parser, field('parser_name', $.identifier), optional($.typeParameters), '(', optional($.parameterList), ')'),
parserDeclaration: $ => seq($.parserType, optional($.constructorParameters), '{', optional($.parserLocalElements), $.parserStates, '}'),
variableDeclaration: $ => seq(optional($.annotations), $.typeRef, field('variable_name', $.identifier), optional(seq('=', $.expression))),
variableDeclaration: $ => seq(optional($.annotations), $.typeRef, field('variable_name', $.identifier), optional(seq($.assignment, $.expression))),
// Statements
@@ -84,7 +84,7 @@ export default grammar({
parserTransitionStatement: $ => seq($.transition, $.transitionSelectionExpression),
// Expressions
expression: $ => choice($.identifier, $.integer, $.true, $.false), // Very limited.
expression: $ => choice($.identifier, $.integer, $.true, $.false, $.string_literal), // Very limited.
selectExpression: $ => seq($.select, '(', $.expression, ')', '{', $.selectBody, '}'), // TODO: Should be expression list and not just a single expression
transitionSelectionExpression: $ => choice($.identifier, $.selectExpression),
keysetExpression: $ => $.expression,
@@ -92,6 +92,7 @@ export default grammar({
// Tokens
semicolon: $ => ";",
colon: $ => ":",
assignment: $ => "=",
todo: $ => "todo",
abstract: $ => "abstract",
action: $ => "action",