Name inlined rules as if they were hidden

This commit is contained in:
Max Brunsfeld 2017-07-15 22:23:38 -07:00
parent 5081293f65
commit e9afbb4381
2 changed files with 46 additions and 46 deletions

View File

@ -2,9 +2,9 @@ module.exports = grammar({
name: 'bash', name: 'bash',
inline: $ => [ inline: $ => [
$.statement, $._statement,
$.terminator, $._terminator,
$.expression, $._expression,
$._variable_name $._variable_name
], ],
@ -26,13 +26,13 @@ module.exports = grammar({
program: $ => repeat($._terminated_statement), program: $ => repeat($._terminated_statement),
_terminated_statement: $ => seq( _terminated_statement: $ => seq(
$.statement, $._statement,
$.terminator $._terminator
), ),
// Statements // Statements
statement: $ => choice( _statement: $ => choice(
$.environment_variable_assignment, $.environment_variable_assignment,
$.command, $.command,
$.bracket_command, $.bracket_command,
@ -90,16 +90,16 @@ module.exports = grammar({
case_statement: $ => seq( case_statement: $ => seq(
'case', 'case',
$.expression, $._expression,
optional($.terminator), optional($._terminator),
'in', 'in',
$.terminator, $._terminator,
repeat($.case_item), repeat($.case_item),
'esac' 'esac'
), ),
case_item: $ => seq( case_item: $ => seq(
$.expression, $._expression,
')', ')',
repeat($._terminated_statement), repeat($._terminated_statement),
';;' ';;'
@ -126,20 +126,20 @@ module.exports = grammar({
), ),
pipeline: $ => prec.left(1, seq( pipeline: $ => prec.left(1, seq(
$.statement, $._statement,
choice('|', '|&'), choice('|', '|&'),
$.statement $._statement
)), )),
list: $ => prec.left(seq( list: $ => prec.left(seq(
$.statement, $._statement,
choice('&&', '||'), choice('&&', '||'),
$.statement $._statement
)), )),
bracket_command: $ => choice( bracket_command: $ => choice(
seq('[', repeat1($.expression), ']'), seq('[', repeat1($._expression), ']'),
seq('[[', repeat1($.expression), ']]') seq('[[', repeat1($._expression), ']]')
), ),
// Commands // Commands
@ -158,7 +158,7 @@ module.exports = grammar({
), ),
optional(seq( optional(seq(
/\s+/, /\s+/,
repeat($.expression) repeat($._expression)
)), )),
repeat(choice( repeat(choice(
$.file_redirect, $.file_redirect,
@ -170,7 +170,7 @@ module.exports = grammar({
rename($.leading_word, 'variable_name'), rename($.leading_word, 'variable_name'),
'=', '=',
choice( choice(
$.expression, $._expression,
$._empty_value $._empty_value
) )
), ),
@ -178,7 +178,7 @@ module.exports = grammar({
file_redirect: $ => seq( file_redirect: $ => seq(
optional($.file_descriptor), optional($.file_descriptor),
choice('<', '>', '>>', '&>', '&>>', '<&', '>&'), choice('<', '>', '>>', '&>', '&>>', '<&', '>&'),
$.expression $._expression
), ),
heredoc_redirect: $ => seq( heredoc_redirect: $ => seq(
@ -201,7 +201,7 @@ module.exports = grammar({
// Expressions // Expressions
expression: $ => choice( _expression: $ => choice(
$.word, $.word,
$.string, $.string,
$.raw_string, $.raw_string,
@ -237,7 +237,7 @@ module.exports = grammar({
$._variable_name, $._variable_name,
optional(seq( optional(seq(
choice(':', ':?', '=', ':-'), choice(':', ':?', '=', ':-'),
$.expression $._expression
)), )),
'}' '}'
), ),
@ -255,7 +255,7 @@ module.exports = grammar({
process_substitution: $ => seq( process_substitution: $ => seq(
choice('<', '>'), choice('<', '>'),
'(', '(',
$.statement, $._statement,
')' ')'
), ),
@ -269,6 +269,6 @@ module.exports = grammar({
special_variable_name: $ => choice('*', '@', '#', '?', '-', '$', '!', '0', '_'), special_variable_name: $ => choice('*', '@', '#', '?', '-', '$', '!', '0', '_'),
terminator: $ => choice(';', ';;', '\n', '&'), _terminator: $ => choice(';', ';;', '\n', '&'),
} }
}); });

46
src/grammar.json vendored
View File

@ -13,15 +13,15 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "_statement"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "terminator" "name": "_terminator"
} }
] ]
}, },
"statement": { "_statement": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -228,14 +228,14 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "_expression"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "terminator" "name": "_terminator"
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -248,7 +248,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "terminator" "name": "_terminator"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -268,7 +268,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "_expression"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -372,7 +372,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "_statement"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@ -389,7 +389,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "_statement"
} }
] ]
} }
@ -402,7 +402,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "_statement"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@ -419,7 +419,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "_statement"
} }
] ]
} }
@ -438,7 +438,7 @@
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "_expression"
} }
}, },
{ {
@ -458,7 +458,7 @@
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "_expression"
} }
}, },
{ {
@ -539,7 +539,7 @@
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "_expression"
} }
} }
] ]
@ -588,7 +588,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "_expression"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -648,7 +648,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "_expression"
} }
] ]
}, },
@ -716,7 +716,7 @@
} }
] ]
}, },
"expression": { "_expression": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -856,7 +856,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "_expression"
} }
] ]
}, },
@ -949,7 +949,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "_statement"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -1014,7 +1014,7 @@
} }
] ]
}, },
"terminator": { "_terminator": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -1086,9 +1086,9 @@
} }
], ],
"inline": [ "inline": [
"statement", "_statement",
"terminator", "_terminator",
"expression", "_expression",
"_variable_name" "_variable_name"
] ]
} }