Support Parsing Function Declarations
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -64,12 +64,14 @@ export default grammar({
|
||||
instantiation: $ => seq($.typeRef, '(', optional($.parameter_list), ')', $.identifier),
|
||||
|
||||
// Declarations
|
||||
declaration: $ => seq(choice($.parserDeclaration, $.parserTypeDeclaration, $.type_declaration)),
|
||||
declaration: $ => seq(choice($.parserDeclaration, $.parserTypeDeclaration, $.type_declaration, $.function_declaration)),
|
||||
|
||||
type_declaration: $=> choice($.struct_declaration),
|
||||
struct_declaration: $ => seq($.struct, $.identifier, '{', optional($.struct_declaration_fields), '}'),
|
||||
struct_declaration_fields: $=> repeat1(seq($.variableDeclaration)),
|
||||
|
||||
function_declaration: $=> seq($.typeRef, $.identifier, $.parameters, $.statement),
|
||||
|
||||
// Make separate productions for the parser type and the parser type declaration because the latter can have type parameters.
|
||||
parserTypeDeclaration: $ => seq(optional($.annotations), $.parser, field('parser_name', $.identifier), optional($.typeParameters), $.parameters),
|
||||
parserDeclaration: $ => seq($.parserType, '{', optional($.parserLocalElements), $.parserStates, '}'),
|
||||
|
||||
@@ -265,3 +265,40 @@ struct Testing {
|
||||
)
|
||||
)
|
||||
|
||||
=========================
|
||||
Simple Function Declaration
|
||||
=========================
|
||||
bool functionb() {
|
||||
string fieldA;
|
||||
};
|
||||
---
|
||||
(p4program
|
||||
(declaration
|
||||
(function_declaration
|
||||
(typeRef
|
||||
(baseType
|
||||
(bool)
|
||||
)
|
||||
)
|
||||
(identifier)
|
||||
(parameters
|
||||
)
|
||||
(statement
|
||||
(blockStatement
|
||||
(statements
|
||||
(statement
|
||||
(variableDeclaration
|
||||
(typeRef
|
||||
(baseType
|
||||
(string)
|
||||
)
|
||||
)
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user