Skip to content

Commit

Permalink
feat: add arguments node for call arguments
Browse files Browse the repository at this point in the history
This is mainly for being able to select the arguments for textobject queries.
  • Loading branch information
mfelsche authored and amaanq committed Apr 25, 2023
1 parent 048b8ab commit 5be42c8
Show file tree
Hide file tree
Showing 8 changed files with 86,854 additions and 86,624 deletions.
9 changes: 6 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,15 @@ module.exports = grammar({

call_expression: $ => prec(PREC.CALL, seq(
field('callee', $.expression),
$.arguments,
optional('?'),
)),
arguments: $ => seq(
token.immediate('('),
commaSep($.expression),
field('positional', commaSep($.expression)),
optional($.named_arguments),
')',
optional('?'),
)),
),

chain_expression: $ => prec.right(PREC.CALL, seq(
$.expression,
Expand Down
83 changes: 48 additions & 35 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3924,13 +3924,38 @@
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "("
}
"type": "SYMBOL",
"name": "arguments"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "?"
},
{
"type": "BLANK"
}
]
}
]
}
},
"arguments": {
"type": "SEQ",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "("
}
},
{
"type": "FIELD",
"name": "positional",
"content": {
"type": "CHOICE",
"members": [
{
Expand Down Expand Up @@ -3962,37 +3987,25 @@
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "named_arguments"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "?"
},
{
"type": "BLANK"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "named_arguments"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"chain_expression": {
"type": "PREC_RIGHT",
Expand Down
40 changes: 33 additions & 7 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,36 @@
]
}
},
{
"type": "arguments",
"named": true,
"fields": {
"positional": {
"multiple": true,
"required": false,
"types": [
{
"type": ",",
"named": false
},
{
"type": "expression",
"named": true
}
]
}
},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "named_arguments",
"named": true
}
]
}
},
{
"type": "array_literal",
"named": true,
Expand Down Expand Up @@ -779,15 +809,11 @@
}
},
"children": {
"multiple": true,
"required": false,
"multiple": false,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "named_arguments",
"type": "arguments",
"named": true
}
]
Expand Down
Loading

0 comments on commit 5be42c8

Please sign in to comment.