Parse Struct Declarations
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -63,7 +63,11 @@ export default grammar({
|
||||
instantiation: $ => seq($.typeRef, '(', optional($.parameterList), ')', $.identifier),
|
||||
|
||||
// Declarations
|
||||
declaration: $ => seq(choice($.parserDeclaration, $.parserTypeDeclaration)),
|
||||
declaration: $ => seq(choice($.parserDeclaration, $.parserTypeDeclaration, $.type_declaration)),
|
||||
|
||||
type_declaration: $=> choice($.struct_declaration),
|
||||
struct_declaration: $ => seq($.struct, $.identifier, '{', optional($.struct_declaration_fields), '}'),
|
||||
struct_declaration_fields: $=> repeat1(seq($.variableDeclaration)),
|
||||
|
||||
// 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), '(', optional($.parameterList), ')'),
|
||||
|
||||
@@ -232,3 +232,31 @@ parser simple() {
|
||||
)
|
||||
)
|
||||
|
||||
=========================
|
||||
Simple Struct Type Declaration
|
||||
=========================
|
||||
struct Testing {
|
||||
string fieldA;
|
||||
};
|
||||
---
|
||||
(p4program
|
||||
(declaration
|
||||
(type_declaration
|
||||
(struct_declaration
|
||||
(struct)
|
||||
(identifier)
|
||||
(struct_declaration_fields
|
||||
(variableDeclaration
|
||||
(typeRef
|
||||
(baseType
|
||||
(string)
|
||||
)
|
||||
)
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user