Skip to content

Commit

Permalink
simplified function_declaration rule
Browse files Browse the repository at this point in the history
The repeat around the expression inside the function declaration doesn't
seem to be needed by any known example code. It can be added back again
later if a test case is found.
  • Loading branch information
bollian committed Feb 3, 2024
1 parent d1684bf commit d29af8b
Show file tree
Hide file tree
Showing 4 changed files with 4,660 additions and 7,732 deletions.
6 changes: 3 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ module.exports = grammar({

// function declarations are slightly different from $.function, which is for
// function literals
function_declaration: $ => prec.right(seq(
function_declaration: $ => seq(
'function',
field('name', $.identifier),
field('parameters', $.parameters_declaration),
'=', repeat1($.expression),
)),
'=', $.expression,
),

// statements are language constructs that can create objects
_statement: $ => choice(
Expand Down
67 changes: 30 additions & 37 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,44 +163,37 @@
]
},
"function_declaration": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "function"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "FIELD",
"name": "parameters",
"content": {
"type": "SYMBOL",
"name": "parameters_declaration"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "expression"
}
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "function"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
]
}
},
{
"type": "FIELD",
"name": "parameters",
"content": {
"type": "SYMBOL",
"name": "parameters_declaration"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "expression"
}
]
},
"_statement": {
"type": "CHOICE",
Expand Down
2 changes: 1 addition & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@
}
},
"children": {
"multiple": true,
"multiple": false,
"required": true,
"types": [
{
Expand Down
Loading

0 comments on commit d29af8b

Please sign in to comment.