Skip to content

Commit

Permalink
Adds support for named arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
cfroystad committed May 3, 2021
1 parent eac70f9 commit bbd544c
Show file tree
Hide file tree
Showing 7 changed files with 49,251 additions and 49,277 deletions.
7 changes: 6 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,15 @@ module.exports = grammar({

arguments: $ => seq(
'(',
commaSep(choice($.variadic_unpacking, $._expression)),
commaSep($.argument),
')'
),

argument: $ => seq(
optional(seq(field('name', $.name), ':')),
choice($.variadic_unpacking, $._expression)
),

member_call_expression: $ => prec(PREC.CALL, seq(
field('object', $._dereferencable_expression),
'->',
Expand Down
69 changes: 47 additions & 22 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -5293,17 +5293,8 @@
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "variadic_unpacking"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
"type": "SYMBOL",
"name": "argument"
},
{
"type": "REPEAT",
Expand All @@ -5315,17 +5306,8 @@
"value": ","
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "variadic_unpacking"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
"type": "SYMBOL",
"name": "argument"
}
]
}
Expand All @@ -5343,6 +5325,49 @@
}
]
},
"argument": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "name"
}
},
{
"type": "STRING",
"value": ":"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "variadic_unpacking"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
]
},
"member_call_expression": {
"type": "PREC",
"value": 22,
Expand Down
46 changes: 36 additions & 10 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,23 @@
}
},
{
"type": "arguments",
"type": "argument",
"named": true,
"fields": {},
"fields": {
"name": {
"multiple": false,
"required": false,
"types": [
{
"type": "name",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": false,
"multiple": false,
"required": true,
"types": [
{
"type": "_expression",
Expand All @@ -397,6 +408,21 @@
]
}
},
{
"type": "arguments",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "argument",
"named": true
}
]
}
},
{
"type": "array_creation_expression",
"named": true,
Expand Down Expand Up @@ -4123,11 +4149,11 @@
},
{
"type": "boolean",
"named": false
"named": true
},
{
"type": "boolean",
"named": true
"named": false
},
{
"type": "break",
Expand Down Expand Up @@ -4339,11 +4365,11 @@
},
{
"type": "null",
"named": true
"named": false
},
{
"type": "null",
"named": false
"named": true
},
{
"type": "object",
Expand Down Expand Up @@ -4411,11 +4437,11 @@
},
{
"type": "string",
"named": true
"named": false
},
{
"type": "string",
"named": false
"named": true
},
{
"type": "switch",
Expand Down
Loading

0 comments on commit bbd544c

Please sign in to comment.