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:
@@ -66,7 +66,7 @@ export default grammar({
|
|||||||
parserTypeDeclaration: $ => seq(optional($.annotations), $.parser, field('parser_name', $.identifier), optional($.typeParameters), '(', optional($.parameterList), ')'),
|
parserTypeDeclaration: $ => seq(optional($.annotations), $.parser, field('parser_name', $.identifier), optional($.typeParameters), '(', optional($.parameterList), ')'),
|
||||||
parserDeclaration: $ => seq($.parserType, optional($.constructorParameters), '{', optional($.parserLocalElements), $.parserStates, '}'),
|
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
|
// Statements
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ export default grammar({
|
|||||||
parserTransitionStatement: $ => seq($.transition, $.transitionSelectionExpression),
|
parserTransitionStatement: $ => seq($.transition, $.transitionSelectionExpression),
|
||||||
|
|
||||||
// Expressions
|
// 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
|
selectExpression: $ => seq($.select, '(', $.expression, ')', '{', $.selectBody, '}'), // TODO: Should be expression list and not just a single expression
|
||||||
transitionSelectionExpression: $ => choice($.identifier, $.selectExpression),
|
transitionSelectionExpression: $ => choice($.identifier, $.selectExpression),
|
||||||
keysetExpression: $ => $.expression,
|
keysetExpression: $ => $.expression,
|
||||||
@@ -92,6 +92,7 @@ export default grammar({
|
|||||||
// Tokens
|
// Tokens
|
||||||
semicolon: $ => ";",
|
semicolon: $ => ";",
|
||||||
colon: $ => ":",
|
colon: $ => ":",
|
||||||
|
assignment: $ => "=",
|
||||||
todo: $ => "todo",
|
todo: $ => "todo",
|
||||||
abstract: $ => "abstract",
|
abstract: $ => "abstract",
|
||||||
action: $ => "action",
|
action: $ => "action",
|
||||||
|
|||||||
@@ -47,3 +47,154 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
=========================
|
||||||
|
Simple Declaration (int)
|
||||||
|
=========================
|
||||||
|
parser simple() {
|
||||||
|
state start {
|
||||||
|
int l;
|
||||||
|
transition accept;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
---
|
||||||
|
(p4program
|
||||||
|
(declaration
|
||||||
|
(parserDeclaration
|
||||||
|
(parserType
|
||||||
|
(parser)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
(parserStates
|
||||||
|
(parserState
|
||||||
|
(state)
|
||||||
|
(identifier)
|
||||||
|
(parserLocalElements
|
||||||
|
(parserLocalElement
|
||||||
|
(variableDeclaration
|
||||||
|
(typeRef
|
||||||
|
(baseType
|
||||||
|
(int)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
(parserTransitionStatement
|
||||||
|
(transition)
|
||||||
|
(transitionSelectionExpression
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
=========================
|
||||||
|
Simple Declaration (string)
|
||||||
|
=========================
|
||||||
|
parser simple() {
|
||||||
|
state start {
|
||||||
|
string l;
|
||||||
|
transition accept;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
---
|
||||||
|
(p4program
|
||||||
|
(declaration
|
||||||
|
(parserDeclaration
|
||||||
|
(parserType
|
||||||
|
(parser)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
(parserStates
|
||||||
|
(parserState
|
||||||
|
(state)
|
||||||
|
(identifier)
|
||||||
|
(parserLocalElements
|
||||||
|
(parserLocalElement
|
||||||
|
(variableDeclaration
|
||||||
|
(typeRef
|
||||||
|
(baseType
|
||||||
|
(string)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
(parserTransitionStatement
|
||||||
|
(transition)
|
||||||
|
(transitionSelectionExpression
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
=========================
|
||||||
|
Simple Declaration (string with initial value)
|
||||||
|
=========================
|
||||||
|
parser simple() {
|
||||||
|
state start {
|
||||||
|
string l = "testing";
|
||||||
|
transition accept;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
---
|
||||||
|
(p4program
|
||||||
|
(declaration
|
||||||
|
(parserDeclaration
|
||||||
|
(parserType
|
||||||
|
(parser)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
(parserStates
|
||||||
|
(parserState
|
||||||
|
(state)
|
||||||
|
(identifier)
|
||||||
|
(parserLocalElements
|
||||||
|
(parserLocalElement
|
||||||
|
(variableDeclaration
|
||||||
|
(typeRef
|
||||||
|
(baseType
|
||||||
|
(string)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(identifier)
|
||||||
|
(assignment)
|
||||||
|
(expression
|
||||||
|
(string_literal)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
(parserTransitionStatement
|
||||||
|
(transition)
|
||||||
|
(transitionSelectionExpression
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user