Changed Grammar
This commit is contained in:
parent
1d4dc219db
commit
ea76333cf5
1 changed files with 22 additions and 23 deletions
|
|
@ -99,14 +99,17 @@ module.exports = grammar({
|
||||||
|
|
||||||
_statements: $ => prec(1, seq(
|
_statements: $ => prec(1, seq(
|
||||||
repeat(seq(
|
repeat(seq(
|
||||||
$._statement,
|
field('stmt', $._statement),
|
||||||
$._terminator,
|
field('terminator', alias($._terminator, $.terminator)),
|
||||||
)),
|
)),
|
||||||
$._statement,
|
field('stmt', $._statement),
|
||||||
optional($._terminator),
|
field('terminator', optional(alias($._terminator, $.terminator))),
|
||||||
)),
|
)),
|
||||||
|
|
||||||
_terminated_statement: $ => repeat1(seq($._statement, $._terminator)),
|
_terminated_statement: $ => repeat1(seq(
|
||||||
|
field('stmt', $._statement),
|
||||||
|
field('terminator', alias($._terminator, $.terminator))
|
||||||
|
)),
|
||||||
|
|
||||||
// Statements
|
// Statements
|
||||||
|
|
||||||
|
|
@ -180,24 +183,24 @@ module.exports = grammar({
|
||||||
|
|
||||||
if_statement: $ => seq(
|
if_statement: $ => seq(
|
||||||
'if',
|
'if',
|
||||||
field('condition', $._terminated_statement),
|
field('condition', alias($._terminated_statement, $.statements)),
|
||||||
'then',
|
'then',
|
||||||
optional($._terminated_statement),
|
field('body', alias(optional($._terminated_statement), $.statements)),
|
||||||
repeat($.elif_clause),
|
field('elif', repeat($.elif_clause)),
|
||||||
optional($.else_clause),
|
field('else', optional($.else_clause)),
|
||||||
'fi',
|
'fi',
|
||||||
),
|
),
|
||||||
|
|
||||||
elif_clause: $ => seq(
|
elif_clause: $ => seq(
|
||||||
'elif',
|
'elif',
|
||||||
$._terminated_statement,
|
field('condition', alias($._terminated_statement, $.statements)),
|
||||||
'then',
|
'then',
|
||||||
optional($._terminated_statement),
|
field('body', alias(optional($._terminated_statement), $.statements)),
|
||||||
),
|
),
|
||||||
|
|
||||||
else_clause: $ => seq(
|
else_clause: $ => seq(
|
||||||
'else',
|
'else',
|
||||||
optional($._terminated_statement),
|
field('body', alias(optional($._terminated_statement), $.statements)),
|
||||||
),
|
),
|
||||||
|
|
||||||
case_statement: $ => seq(
|
case_statement: $ => seq(
|
||||||
|
|
@ -219,7 +222,7 @@ module.exports = grammar({
|
||||||
repeat(seq('|', field('value', choice($._literal, $._extglob_blob)))),
|
repeat(seq('|', field('value', choice($._literal, $._extglob_blob)))),
|
||||||
')',
|
')',
|
||||||
repeat('\n'),
|
repeat('\n'),
|
||||||
choice(field('cmds', $._statements)),
|
choice(field('body', alias($._statements, $.statements)),),
|
||||||
optional(';;')
|
optional(';;')
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
@ -229,7 +232,7 @@ module.exports = grammar({
|
||||||
repeat(seq('|', field('value', choice($._literal, $._extglob_blob)))),
|
repeat(seq('|', field('value', choice($._literal, $._extglob_blob)))),
|
||||||
')',
|
')',
|
||||||
repeat('\n'),
|
repeat('\n'),
|
||||||
choice(field('cmds', $._statements)),
|
choice(field('body', alias($._statements, $.statements))),
|
||||||
';;'
|
';;'
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
@ -288,7 +291,6 @@ module.exports = grammar({
|
||||||
'=',
|
'=',
|
||||||
field('value', choice(
|
field('value', choice(
|
||||||
$._literal,
|
$._literal,
|
||||||
|
|
||||||
$._empty_value,
|
$._empty_value,
|
||||||
alias($._comment_word, $.word),
|
alias($._comment_word, $.word),
|
||||||
)),
|
)),
|
||||||
|
|
@ -456,10 +458,11 @@ module.exports = grammar({
|
||||||
choice(
|
choice(
|
||||||
$._primary_expression,
|
$._primary_expression,
|
||||||
alias($._comment_word, $.word),
|
alias($._comment_word, $.word),
|
||||||
alias($._bare_dollar, '$'),
|
alias($._bare_dollar, $.word),
|
||||||
|
alias(/`\s*`/, '``')
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
optional(seq($._concat, '$')),
|
optional(seq($._concat, alias('$', $.word))),
|
||||||
)),
|
)),
|
||||||
|
|
||||||
string: $ => seq(
|
string: $ => seq(
|
||||||
|
|
@ -474,7 +477,7 @@ module.exports = grammar({
|
||||||
),
|
),
|
||||||
optional($._concat),
|
optional($._concat),
|
||||||
)),
|
)),
|
||||||
optional('$'),
|
optional(alias('$', $.string_content)),
|
||||||
'"',
|
'"',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
@ -482,11 +485,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
raw_string: _ => /'[^']*'/,
|
raw_string: _ => /'[^']*'/,
|
||||||
|
|
||||||
number: $ => choice(
|
number: _ => /[0-9]+/,
|
||||||
/-?(0x)?[0-9]+(#[0-9A-Za-z@_]+)?/,
|
|
||||||
// the base can be an expansion or command substitution
|
|
||||||
seq(/-?(0x)?[0-9]+#/, choice($.expansion, $.command_substitution)),
|
|
||||||
),
|
|
||||||
|
|
||||||
simple_expansion: $ => seq(
|
simple_expansion: $ => seq(
|
||||||
'$',
|
'$',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue