tree-sitter-bash/src/grammar.json

1351 lines
28 KiB
JSON

{
"name": "bash",
"rules": {
"program": {
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
"_terminated_statement": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "SYMBOL",
"name": "_terminator"
}
]
},
"_statement": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "environment_variable_assignment"
},
{
"type": "SYMBOL",
"name": "command"
},
{
"type": "SYMBOL",
"name": "bracket_command"
},
{
"type": "SYMBOL",
"name": "for_statement"
},
{
"type": "SYMBOL",
"name": "while_statement"
},
{
"type": "SYMBOL",
"name": "if_statement"
},
{
"type": "SYMBOL",
"name": "case_statement"
},
{
"type": "SYMBOL",
"name": "pipeline"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "subshell"
},
{
"type": "SYMBOL",
"name": "function_definition"
}
]
},
"for_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "for"
},
{
"type": "SYMBOL",
"name": "word"
},
{
"type": "STRING",
"value": "in"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "SYMBOL",
"name": "do_group"
}
]
},
"while_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "while"
},
{
"type": "SYMBOL",
"name": "_terminated_statement"
},
{
"type": "SYMBOL",
"name": "do_group"
}
]
},
"do_group": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "do"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "STRING",
"value": "done"
}
]
},
"if_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "if"
},
{
"type": "SYMBOL",
"name": "_terminated_statement"
},
{
"type": "STRING",
"value": "then"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "elif_clause"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "else_clause"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "fi"
}
]
},
"elif_clause": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "elif"
},
{
"type": "SYMBOL",
"name": "_terminated_statement"
},
{
"type": "STRING",
"value": "then"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
}
]
},
"else_clause": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "else"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
}
]
},
"case_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "case"
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "case_item"
}
},
{
"type": "STRING",
"value": "esac"
}
]
},
"case_item": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "|"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
{
"type": "STRING",
"value": ")"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "STRING",
"value": ";;"
}
]
},
"function_definition": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "function"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "word"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "STRING",
"value": ")"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "compound_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "file_redirect"
},
{
"type": "BLANK"
}
]
}
]
},
"compound_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"subshell": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"pipeline": {
"type": "PREC_LEFT",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "|"
},
{
"type": "STRING",
"value": "|&"
}
]
},
{
"type": "SYMBOL",
"name": "_statement"
}
]
}
},
"list": {
"type": "PREC_LEFT",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "&&"
},
{
"type": "STRING",
"value": "||"
}
]
},
{
"type": "SYMBOL",
"name": "_statement"
}
]
}
},
"bracket_command": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "STRING",
"value": "]"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "[["
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "STRING",
"value": "]]"
}
]
}
]
},
"command": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "environment_variable_assignment"
},
{
"type": "SYMBOL",
"name": "file_redirect"
}
]
}
},
{
"type": "SYMBOL",
"name": "command_name"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "file_redirect"
},
{
"type": "SYMBOL",
"name": "heredoc_redirect"
}
]
}
}
]
}
},
"command_name": {
"type": "SYMBOL",
"name": "_expression"
},
"environment_variable_assignment": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "variable_name"
},
{
"type": "SYMBOL",
"name": "subscript"
}
]
},
{
"type": "STRING",
"value": "="
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "array"
},
{
"type": "SYMBOL",
"name": "_empty_value"
}
]
}
]
},
"subscript": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "variable_name"
},
{
"type": "STRING",
"value": "["
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": "]"
}
]
},
"file_redirect": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "file_descriptor"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "<"
},
{
"type": "STRING",
"value": ">"
},
{
"type": "STRING",
"value": ">>"
},
{
"type": "STRING",
"value": "&>"
},
{
"type": "STRING",
"value": "&>>"
},
{
"type": "STRING",
"value": "<&"
},
{
"type": "STRING",
"value": ">&"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"heredoc_redirect": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "<<"
},
{
"type": "STRING",
"value": "<<-"
}
]
},
{
"type": "SYMBOL",
"name": "heredoc"
}
]
},
"heredoc": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_simple_heredoc"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_heredoc_beginning"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "expansion"
},
{
"type": "SYMBOL",
"name": "simple_expansion"
},
{
"type": "SYMBOL",
"name": "_heredoc_middle"
}
]
}
},
{
"type": "SYMBOL",
"name": "_heredoc_end"
}
]
}
]
},
"_expression": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "word"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "raw_string"
},
{
"type": "SYMBOL",
"name": "expansion"
},
{
"type": "SYMBOL",
"name": "simple_expansion"
},
{
"type": "SYMBOL",
"name": "command_substitution"
},
{
"type": "SYMBOL",
"name": "process_substitution"
},
{
"type": "SYMBOL",
"name": "concatenation"
}
]
},
"concatenation": {
"type": "PREC",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "word"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "raw_string"
},
{
"type": "SYMBOL",
"name": "expansion"
},
{
"type": "SYMBOL",
"name": "simple_expansion"
},
{
"type": "SYMBOL",
"name": "command_substitution"
},
{
"type": "SYMBOL",
"name": "process_substitution"
}
]
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_concat"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "word"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "raw_string"
},
{
"type": "SYMBOL",
"name": "expansion"
},
{
"type": "SYMBOL",
"name": "simple_expansion"
},
{
"type": "SYMBOL",
"name": "command_substitution"
},
{
"type": "SYMBOL",
"name": "process_substitution"
}
]
}
]
}
}
]
}
},
"string": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^\"`$]+"
},
{
"type": "SYMBOL",
"name": "expansion"
},
{
"type": "SYMBOL",
"name": "simple_expansion"
},
{
"type": "SYMBOL",
"name": "command_substitution"
}
]
}
},
{
"type": "STRING",
"value": "\""
}
]
},
"array": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "word"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"raw_string": {
"type": "PATTERN",
"value": "'[^']*'"
},
"simple_expansion": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "SYMBOL",
"name": "_variable_name"
}
]
},
"expansion": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "${"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_variable_name"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "#"
},
{
"type": "SYMBOL",
"name": "_variable_name"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "#"
},
{
"type": "SYMBOL",
"name": "_variable_name"
},
{
"type": "STRING",
"value": "["
},
{
"type": "STRING",
"value": "@"
},
{
"type": "STRING",
"value": "]"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_variable_name"
},
{
"type": "STRING",
"value": "["
},
{
"type": "STRING",
"value": "@"
},
{
"type": "STRING",
"value": "]"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_variable_name"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "STRING",
"value": ":?"
},
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": ":-"
},
{
"type": "STRING",
"value": "%"
},
{
"type": "STRING",
"value": "/"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
]
},
{
"type": "STRING",
"value": "}"
}
]
},
"_variable_name": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "simple_variable_name"
},
"named": true,
"value": "variable_name"
},
{
"type": "SYMBOL",
"name": "special_variable_name"
}
]
},
"command_substitution": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "$("
},
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "STRING",
"value": ")"
}
]
},
{
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "`"
},
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "STRING",
"value": "`"
}
]
}
}
]
},
"process_substitution": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "<("
},
{
"type": "STRING",
"value": ">("
}
]
},
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "STRING",
"value": ")"
}
]
},
"word": {
"type": "TOKEN",
"content": {
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^#'\"<>{}()`$&;\\\\\\s]"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "PATTERN",
"value": "[^\\s]"
}
]
}
]
}
}
},
"comment": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -1,
"content": {
"type": "PATTERN",
"value": "#.*"
}
}
},
"simple_variable_name": {
"type": "PATTERN",
"value": "\\w+"
},
"special_variable_name": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "*"
},
{
"type": "STRING",
"value": "@"
},
{
"type": "STRING",
"value": "#"
},
{
"type": "STRING",
"value": "?"
},
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"value": "$"
},
{
"type": "STRING",
"value": "!"
},
{
"type": "STRING",
"value": "0"
},
{
"type": "STRING",
"value": "_"
}
]
},
"_terminator": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "STRING",
"value": ";;"
},
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "&"
}
]
}
},
"extras": [
{
"type": "SYMBOL",
"name": "comment"
},
{
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "\\s"
},
{
"type": "STRING",
"value": "\\\n"
}
]
}
}
],
"conflicts": [],
"externals": [
{
"type": "SYMBOL",
"name": "_simple_heredoc"
},
{
"type": "SYMBOL",
"name": "_heredoc_beginning"
},
{
"type": "SYMBOL",
"name": "_heredoc_middle"
},
{
"type": "SYMBOL",
"name": "_heredoc_end"
},
{
"type": "SYMBOL",
"name": "file_descriptor"
},
{
"type": "SYMBOL",
"name": "_empty_value"
},
{
"type": "SYMBOL",
"name": "_concat"
},
{
"type": "SYMBOL",
"name": "variable_name"
},
{
"type": "STRING",
"value": "\n"
}
],
"inline": [
"_statement",
"_terminator",
"_expression",
"_variable_name"
]
}