@@ -68,13 +68,16 @@ export default grammar({
|
||||
instantiation: $ => seq($.typeRef, '(', optional($.parameter_list), ')', $.identifier),
|
||||
|
||||
// Declarations
|
||||
declaration: $ => seq(choice($.parserDeclaration, $.parserTypeDeclaration, $.type_declaration, $.function_declaration, $.control_declaration)),
|
||||
declaration: $ => seq(choice($.parserDeclaration, $.parserTypeDeclaration, $.type_declaration, $.function_declaration, $.control_declaration, $.extern_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),
|
||||
extern_declaration: $=> seq($.extern, $.declaration),
|
||||
|
||||
// The body is truly optional only in the extern case. This check is handled by the compiler.
|
||||
function_declaration: $=> seq($.typeRef, $.identifier, $.parameters, optional($.blockStatement)),
|
||||
|
||||
// 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),
|
||||
|
||||
@@ -282,7 +282,6 @@ bool functionb() {
|
||||
)
|
||||
(identifier)
|
||||
(parameters)
|
||||
(statement
|
||||
(blockStatement
|
||||
(statements
|
||||
(statement
|
||||
@@ -300,7 +299,6 @@ bool functionb() {
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=========================
|
||||
Function Declaration With Parameters
|
||||
@@ -340,7 +338,6 @@ bool functionb(bool a, int b) {
|
||||
)
|
||||
)
|
||||
)
|
||||
(statement
|
||||
(blockStatement
|
||||
(statements
|
||||
(statement
|
||||
@@ -358,7 +355,6 @@ bool functionb(bool a, int b) {
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
=========================
|
||||
Function Declaration With Parameters And Directions
|
||||
=========================
|
||||
@@ -416,7 +412,6 @@ bool functionb(in bool a, out int b, inout string c) {
|
||||
)
|
||||
)
|
||||
)
|
||||
(statement
|
||||
(blockStatement
|
||||
(statements
|
||||
(statement
|
||||
@@ -434,4 +429,66 @@ bool functionb(in bool a, out int b, inout string c) {
|
||||
)
|
||||
)
|
||||
)
|
||||
=========================
|
||||
Extern Function Declaration
|
||||
=========================
|
||||
extern bool functionb(in bool a, out int b, inout string c);
|
||||
---
|
||||
(p4program
|
||||
(declaration
|
||||
(extern_declaration
|
||||
(extern)
|
||||
(declaration
|
||||
(function_declaration
|
||||
(typeRef
|
||||
(baseType
|
||||
(bool)
|
||||
)
|
||||
)
|
||||
(identifier)
|
||||
(parameters
|
||||
(parameter_list
|
||||
(parameter_list
|
||||
(parameter_list
|
||||
(parameter
|
||||
(direction
|
||||
(in)
|
||||
)
|
||||
(typeRef
|
||||
(baseType
|
||||
(bool)
|
||||
)
|
||||
)
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
(parameter
|
||||
(direction
|
||||
(out)
|
||||
)
|
||||
(typeRef
|
||||
(baseType
|
||||
(int)
|
||||
)
|
||||
)
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
(parameter
|
||||
(direction
|
||||
(inout)
|
||||
)
|
||||
(typeRef
|
||||
(baseType
|
||||
(string)
|
||||
)
|
||||
)
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -43,7 +43,6 @@ int fun() {
|
||||
)
|
||||
(identifier)
|
||||
(parameters)
|
||||
(statement
|
||||
(blockStatement
|
||||
(statements
|
||||
(statement
|
||||
@@ -60,7 +59,6 @@ int fun() {
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
=========================
|
||||
Simple If Statement (No Else)
|
||||
=========================
|
||||
|
||||
Reference in New Issue
Block a user