Grammar: parameter_list: Refactor and Add Tests
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -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), ')'),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user