Skip to content

Commit

Permalink
Simplify embedded_braced_expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio de Jesus Ochoa Solano committed Aug 19, 2021
1 parent b6db7cf commit 8ac0c52
Show file tree
Hide file tree
Showing 20 changed files with 166,012 additions and 166,151 deletions.
34 changes: 10 additions & 24 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,35 +146,21 @@ const rules = {
'<<<',
$._heredoc_start,
opt(alias($._heredoc_start_newline, '\n')),
choice.rep($._heredoc_body, $.variable, $.embedded_brace_expression),
choice.rep($._heredoc_body, $.variable, $.embedded_braced_expression),
opt(alias($._heredoc_end_newline, '\n')),
$._heredoc_end,
),

embedded_brace_expression: $ => seq($._embedded_brace_expression, '}'),

_embedded_brace_expression: $ =>
choice(
alias(token(seq('{$', identifier)), $.variable),
alias($._embedded_brace_call_expression, $.call_expression),
alias($._embedded_brace_subscript_expression, $.subscript_expression),
alias($._embedded_brace_selection_expression, $.selection_expression),
),

_embedded_brace_call_expression: $ =>
seq($._embedded_brace_expression, $.arguments),

_embedded_brace_subscript_expression: $ =>
seq($._embedded_brace_expression, '[', opt($._expression), ']'),

_embedded_brace_selection_expression: $ =>
prec(
-1,
seq(
$._embedded_brace_expression,
field('selection_operator', choice('?->', '->')),
$._variablish,
embedded_braced_expression: $ =>
seq(
'{',
choice(
$.variable,
$.call_expression,
$.subscript_expression,
$.selection_expression,
),
'}',
),

braced_expression: $ => seq('{', $._expression, '}'),
Expand Down
138 changes: 15 additions & 123 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
},
{
"type": "SYMBOL",
"name": "embedded_brace_expression"
"name": "embedded_braced_expression"
}
]
}
Expand Down Expand Up @@ -443,148 +443,40 @@
}
]
},
"embedded_brace_expression": {
"embedded_braced_expression": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_embedded_brace_expression"
},
{
"type": "STRING",
"value": "}"
}
]
},
"_embedded_brace_expression": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{$"
},
{
"type": "PATTERN",
"value": "[a-zA-Z_\\x80-\\xff][a-zA-Z0-9_\\x80-\\xff]*"
}
]
}
},
"named": true,
"value": "variable"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_embedded_brace_call_expression"
},
"named": true,
"value": "call_expression"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_embedded_brace_subscript_expression"
},
"named": true,
"value": "subscript_expression"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_embedded_brace_selection_expression"
},
"named": true,
"value": "selection_expression"
}
]
},
"_embedded_brace_call_expression": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_embedded_brace_expression"
},
{
"type": "SYMBOL",
"name": "arguments"
}
]
},
"_embedded_brace_subscript_expression": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_embedded_brace_expression"
},
{
"type": "STRING",
"value": "["
"value": "{"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
"name": "variable"
},
{
"type": "BLANK"
"type": "SYMBOL",
"name": "call_expression"
},
{
"type": "SYMBOL",
"name": "subscript_expression"
},
{
"type": "SYMBOL",
"name": "selection_expression"
}
]
},
{
"type": "STRING",
"value": "]"
"value": "}"
}
]
},
"_embedded_brace_selection_expression": {
"type": "PREC",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_embedded_brace_expression"
},
{
"type": "FIELD",
"name": "selection_operator",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "?->"
},
{
"type": "STRING",
"value": "->"
}
]
}
},
{
"type": "SYMBOL",
"name": "_variablish"
}
]
}
},
"braced_expression": {
"type": "SEQ",
"members": [
Expand Down
30 changes: 7 additions & 23 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@
"fields": {
"function": {
"multiple": false,
"required": false,
"required": true,
"types": [
{
"type": "_expression",
Expand Down Expand Up @@ -841,25 +841,9 @@
"type": "arguments",
"named": true
},
{
"type": "call_expression",
"named": true
},
{
"type": "selection_expression",
"named": true
},
{
"type": "subscript_expression",
"named": true
},
{
"type": "type_arguments",
"named": true
},
{
"type": "variable",
"named": true
}
]
}
Expand Down Expand Up @@ -1207,7 +1191,7 @@
}
},
{
"type": "embedded_brace_expression",
"type": "embedded_braced_expression",
"named": true,
"fields": {},
"children": {
Expand Down Expand Up @@ -1695,7 +1679,7 @@
"required": false,
"types": [
{
"type": "embedded_brace_expression",
"type": "embedded_braced_expression",
"named": true
},
{
Expand Down Expand Up @@ -4198,11 +4182,11 @@
},
{
"type": "float",
"named": false
"named": true
},
{
"type": "float",
"named": true
"named": false
},
{
"type": "for",
Expand Down Expand Up @@ -4370,11 +4354,11 @@
},
{
"type": "string",
"named": true
"named": false
},
{
"type": "string",
"named": false
"named": true
},
{
"type": "super",
Expand Down
Loading

0 comments on commit 8ac0c52

Please sign in to comment.