Skip to content

Commit

Permalink
Fix: Parses more one-line statements without/with many EOL.
Browse files Browse the repository at this point in the history
  • Loading branch information
acristoffers committed Jul 2, 2023
1 parent 4029fa7 commit ae09222
Show file tree
Hide file tree
Showing 8 changed files with 22,784 additions and 21,673 deletions.
21 changes: 13 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ module.exports = grammar({
seq(
choice('for', 'parfor'),
$.iterator,
$._end_of_line,
repeat($._end_of_line),
optional($.block),
'end'
),
Expand All @@ -501,7 +501,7 @@ module.exports = grammar({
',',
$.parfor_options,
')',
$._end_of_line,
repeat($._end_of_line),
optional($.block),
'end'
)
Expand All @@ -511,7 +511,7 @@ module.exports = grammar({
seq(
'while',
field('condition', $._expression),
$._end_of_line,
repeat($._end_of_line),
optional($.block),
'end'
),
Expand All @@ -521,16 +521,16 @@ module.exports = grammar({
'case',
// MATLAB says it should be a `switch_expr`, but then accepts any expression
field('condition', $._expression),
$._end_of_line,
repeat1($._end_of_line),
optional($.block)
),
otherwise_clause: ($) =>
seq('otherwise', $._end_of_line, optional($.block)),
seq('otherwise', repeat($._end_of_line), optional($.block)),
switch_statement: ($) =>
seq(
'switch',
field('condition', $._expression),
$._end_of_line,
repeat($._end_of_line),
repeat($.case_clause),
optional($.otherwise_clause),
'end'
Expand Down Expand Up @@ -703,11 +703,16 @@ module.exports = grammar({
),

catch_clause: ($) =>
seq('catch', optional($.identifier), $._end_of_line, optional($.block)),
seq(
'catch',
optional($.identifier),
repeat1($._end_of_line),
optional($.block)
),
try_statement: ($) =>
seq(
'try',
optional($._end_of_line),
repeat($._end_of_line),
optional($.block),
optional($.catch_clause),
'end'
Expand Down
64 changes: 40 additions & 24 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2228,8 +2228,11 @@
"name": "iterator"
},
{
"type": "SYMBOL",
"name": "_end_of_line"
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_end_of_line"
}
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -2277,8 +2280,11 @@
"value": ")"
},
{
"type": "SYMBOL",
"name": "_end_of_line"
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_end_of_line"
}
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -2316,8 +2322,11 @@
}
},
{
"type": "SYMBOL",
"name": "_end_of_line"
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_end_of_line"
}
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -2353,8 +2362,11 @@
}
},
{
"type": "SYMBOL",
"name": "_end_of_line"
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_end_of_line"
}
},
{
"type": "CHOICE",
Expand All @@ -2378,8 +2390,11 @@
"value": "otherwise"
},
{
"type": "SYMBOL",
"name": "_end_of_line"
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_end_of_line"
}
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -2411,8 +2426,11 @@
}
},
{
"type": "SYMBOL",
"name": "_end_of_line"
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_end_of_line"
}
},
{
"type": "REPEAT",
Expand Down Expand Up @@ -3686,8 +3704,11 @@
]
},
{
"type": "SYMBOL",
"name": "_end_of_line"
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_end_of_line"
}
},
{
"type": "CHOICE",
Expand All @@ -3711,16 +3732,11 @@
"value": "try"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_end_of_line"
},
{
"type": "BLANK"
}
]
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_end_of_line"
}
},
{
"type": "CHOICE",
Expand Down
Loading

0 comments on commit ae09222

Please sign in to comment.