Skip to content

Commit

Permalink
handle optional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Jan 9, 2024
1 parent a99b610 commit 155ed2f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = grammar({
)
),

shebang: _ => /#![^\n]*/,
shebang: (_) => /#![^\n]*/,

_last_statement: ($) => choice($.return_statement, $.break_statement),

Expand Down Expand Up @@ -574,7 +574,7 @@ module.exports = grammar({
prec.right(
PREC.FUNCTION,
seq(
"function(",
choice("function(", "fun("),
list_of($.emmy_function_parameter, ",", false),
")",
optional(seq(":", $.emmy_identifier))
Expand Down Expand Up @@ -643,6 +643,7 @@ module.exports = grammar({
/\s*---@field\s+/,
optional(seq(field("visibility", $.emmy_visibility), /\s+/)),
field("name", $.identifier),
optional("?"),
/\s+/,
field("type", $._emmy_type),

Expand Down
25 changes: 23 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3030,8 +3030,17 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "function("
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "function("
},
{
"type": "STRING",
"value": "fun("
}
]
},
{
"type": "SEQ",
Expand Down Expand Up @@ -3356,6 +3365,18 @@
"name": "identifier"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "?"
},
{
"type": "BLANK"
}
]
},
{
"type": "PATTERN",
"value": "\\s+"
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2937,6 +2937,10 @@
"type": "for_start",
"named": true
},
{
"type": "fun(",
"named": false
},
{
"type": "function(",
"named": false
Expand Down
Binary file modified src/parser.c
Binary file not shown.

0 comments on commit 155ed2f

Please sign in to comment.