Refactor Parser For Parameter Lists

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-04-02 01:28:27 -04:00
parent 8962235aca
commit 7cdbee1999
7 changed files with 32 additions and 8 deletions
+3 -2
View File
@@ -32,6 +32,7 @@ export default grammar({
parameter_list: $ => choice($.parameter, seq($.parameter_list, ',', $.parameter)), parameter_list: $ => choice($.parameter, seq($.parameter_list, ',', $.parameter)),
parameter: $ => choice(seq(optional($.annotations), optional($.direction), $.typeRef, $.identifier), seq(optional($.annotations), optional($.direction), $.typeRef, $.identifier, '=', $.expression)), parameter: $ => choice(seq(optional($.annotations), optional($.direction), $.typeRef, $.identifier), seq(optional($.annotations), optional($.direction), $.typeRef, $.identifier, '=', $.expression)),
direction: $ => choice($.in, $.out, $.inout), direction: $ => choice($.in, $.out, $.inout),
parameters: $=> seq('(', optional($.parameter_list), ')'),
// Common - Types // Common - Types
typeRef: $ => choice($.baseType, $.type_identifier), typeRef: $ => choice($.baseType, $.type_identifier),
@@ -39,7 +40,7 @@ export default grammar({
constructor_parameters: $ => seq('(', optional($.parameter_list), ')'), constructor_parameters: $ => seq('(', optional($.parameter_list), ')'),
// Common - Parsers // Common - Parsers
parserType: $ => seq(optional($.annotations), $.parser, field('parser_name', $.identifier), optional($.typeParameters), '(', optional($.parameter_list), ')'), parserType: $ => seq(optional($.annotations), $.parser, field('parser_name', $.identifier), optional($.typeParameters), $.parameters),
// Mark with higher precedence so that the local states are preferred when parsing! // Mark with higher precedence so that the local states are preferred when parsing!
// TODO: Test! // TODO: Test!
@@ -70,7 +71,7 @@ export default grammar({
struct_declaration_fields: $=> repeat1(seq($.variableDeclaration)), 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. // 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($.parameter_list), ')'), parserTypeDeclaration: $ => seq(optional($.annotations), $.parser, field('parser_name', $.identifier), optional($.typeParameters), $.parameters),
parserDeclaration: $ => seq($.parserType, '{', optional($.parserLocalElements), $.parserStates, '}'), parserDeclaration: $ => seq($.parserType, '{', optional($.parserLocalElements), $.parserStates, '}'),
variableDeclaration: $ => seq(optional($.annotations), $.typeRef, field('variable_name', $.identifier), optional(seq($.assignment, $.expression)), $._semicolon), variableDeclaration: $ => seq(optional($.annotations), $.typeRef, field('variable_name', $.identifier), optional(seq($.assignment, $.expression)), $._semicolon),
@@ -20,6 +20,7 @@ Simple Annotated Declaration
) )
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -66,6 +67,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -15,6 +15,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -61,6 +62,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -107,6 +109,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -153,6 +156,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -205,6 +209,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -16,6 +16,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -84,6 +85,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -147,6 +149,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -205,6 +208,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -258,6 +262,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
+3
View File
@@ -14,6 +14,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -48,6 +49,7 @@ parser imple(bool pname) {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters
(parameter_list (parameter_list
(parameter (parameter
(typeRef (typeRef
@@ -59,6 +61,7 @@ parser imple(bool pname) {
) )
) )
) )
)
(parserStates (parserStates
(parserState (parserState
(state) (state)
@@ -16,6 +16,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -69,6 +70,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -125,6 +127,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -195,6 +198,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -288,6 +292,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -14,6 +14,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -49,6 +50,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState
@@ -106,6 +108,7 @@ parser simple() {
(parserType (parserType
(parser) (parser)
(identifier) (identifier)
(parameters)
) )
(parserStates (parserStates
(parserState (parserState