Grammar: parameter_list: Refactor and Add Tests

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-04-13 04:58:43 -04:00
parent b687454389
commit fcb3b4e304
2 changed files with 134 additions and 1 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ export default grammar({
// Common - Parameters
typeParameters: $ => seq('<', $.typeParameterList, '>'),
typeParameterList: $ => choice("[a-z]+", seq($.typeParameterList, ',', "[a-z]+")),
parameter_list: $ => choice($.parameter, seq($.parameter_list, ',', $.parameter)),
parameter_list: $ => choice(seq($.parameter_list, ',', $.parameter), $.parameter),
parameter: $ => choice(seq(optional($.annotations), optional($.direction), $.typeRef, $.identifier), seq(optional($.annotations), optional($.direction), $.typeRef, $.identifier, '=', $.expression)),
direction: $ => choice($.in, $.out, $.inout),
parameters: $=> seq('(', optional($.parameter_list), ')'),
+133
View File
@@ -272,6 +272,43 @@ bool functionb() {
string fieldA;
};
---
(p4program
(declaration
(function_declaration
(typeRef
(baseType
(bool)
)
)
(identifier)
(parameters)
(statement
(blockStatement
(statements
(statement
(variableDeclaration
(typeRef
(baseType
(string)
)
)
(identifier)
)
)
)
)
)
)
)
)
=========================
Function Declaration With Parameters
=========================
bool functionb(bool a, int b) {
string fieldA;
};
---
(p4program
(declaration
(function_declaration
@@ -282,6 +319,102 @@ bool functionb() {
)
(identifier)
(parameters
(parameter_list
(parameter_list
(parameter
(typeRef
(baseType
(bool)
)
)
(identifier)
)
)
(parameter
(typeRef
(baseType
(int)
)
)
(identifier)
)
)
)
(statement
(blockStatement
(statements
(statement
(variableDeclaration
(typeRef
(baseType
(string)
)
)
(identifier)
)
)
)
)
)
)
)
)
=========================
Function Declaration With Parameters And Directions
=========================
bool functionb(in bool a, out int b, inout string c) {
string fieldA;
};
---
(p4program
(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)
)
)
)
(statement
(blockStatement