Rework test expressions

Fixes #11
This commit is contained in:
Max Brunsfeld 2018-05-24 11:46:57 -07:00
parent 7902804460
commit 065a4ec425
9 changed files with 76773 additions and 76012 deletions

View File

@ -10,3 +10,4 @@ Bash grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
* [Bash man page](http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_GRAMMAR) * [Bash man page](http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_GRAMMAR)
* [Shell command language specification](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html) * [Shell command language specification](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)
* [mvdnan/sh - a shell parser in go](https://github.com/mvdan/sh)

View File

@ -22,21 +22,6 @@ git diff --word-diff=color -- file1.txt file2.txt
(command (command_name (word)) (word)) (command (command_name (word)) (word))
(command (command_name (word)) (word) (word) (word) (word) (word))) (command (command_name (word)) (word) (word) (word) (word) (word)))
===============================
Commands with quoted arguments
===============================
echo "hello $(whoami), this is $(uname)"
echo 'hi'
---
(program
(command (command_name (word)) (string
(command_substitution (command (command_name (word))))
(command_substitution (command (command_name (word))))))
(command (command_name (word)) (raw_string)))
=============================== ===============================
Quoted command names Quoted command names
=============================== ===============================
@ -94,43 +79,6 @@ VAR2= echo
(variable_assignment (variable_name)) (variable_assignment (variable_name))
(command (variable_assignment (variable_name)) (command_name (word)))) (command (variable_assignment (variable_name)) (command_name (word))))
===================================
Pipelines
===================================
whoami | cat
cat foo | grep -v bar
---
(program
(pipeline
(command (command_name (word)))
(command (command_name (word))))
(pipeline
(command (command_name (word)) (word))
(command (command_name (word)) (word) (word))))
===================================
Lists
===================================
a | b && c && d; d e f || e g
---
(program
(list
(list
(pipeline
(command (command_name (word)))
(command (command_name (word))))
(command (command_name (word))))
(command (command_name (word))))
(list
(command (command_name (word)) (word) (word))
(command (command_name (word)) (word))))
=============================== ===============================
File redirects File redirects
=============================== ===============================

View File

@ -26,35 +26,6 @@ echo ]]] ===
(command (command_name (word)) (word)) (command (command_name (word)) (word))
(command (command_name (word)) (word) (word))) (command (command_name (word)) (word) (word)))
=============================
The regex operator
=============================
[[ "35d8b" =~ ^[0-9a-fA-F] ]]
[[ $CMD =~ (^|;)update_terminal_cwd($|;) ]]
[[ ! " ${completions[*]} " =~ " $alias_cmd " ]]
! [[ "$a" =~ ^a|b\ *c|d$ ]]
---
(program
(bracket_command
(string)
(regex))
(bracket_command
(simple_expansion (variable_name))
(regex))
(bracket_command
(word)
(string (expansion (subscript (variable_name) (word))))
(string (simple_expansion (variable_name))))
(command
(command_name (word))
(word)
(string (simple_expansion (variable_name)))
(regex)
(word)))
============================= =============================
Simple variable expansions Simple variable expansions
============================= =============================

View File

@ -1,3 +1,40 @@
===================================
Pipelines
===================================
whoami | cat
cat foo | grep -v bar
---
(program
(pipeline
(command (command_name (word)))
(command (command_name (word))))
(pipeline
(command (command_name (word)) (word))
(command (command_name (word)) (word) (word))))
===================================
Lists
===================================
a | b && c && d; d e f || e g
---
(program
(list
(list
(pipeline
(command (command_name (word)))
(command (command_name (word))))
(command (command_name (word))))
(command (command_name (word))))
(list
(command (command_name (word)) (word) (word))
(command (command_name (word)) (word))))
==================================== ====================================
While statements While statements
==================================== ====================================
@ -103,9 +140,9 @@ fi
(program (program
(if_statement (if_statement
(bracket_command (test_command (binary_expression
(string (command_substitution (command (command_name (word))))) (string (command_substitution (command (command_name (word)))))
(raw_string)) (raw_string)))
(command (command_name (word)) (word)))) (command (command_name (word)) (word))))
==================================== ====================================
@ -146,6 +183,60 @@ esac
(case_item (concatenation (word) (word)) (case_item (concatenation (word) (word))
(command (command_name (word)) (simple_expansion (special_variable_name)))))) (command (command_name (word)) (simple_expansion (special_variable_name))))))
=============================
Test commands
=============================
if [[ "$lsb_dist" != 'Ubuntu' || $(ver_to_int "$lsb_release") < $(ver_to_int '14.04') ]]; then
return 1
fi
---
(program
(if_statement
(test_command (binary_expression
(binary_expression
(binary_expression
(string (simple_expansion (variable_name)))
(raw_string))
(command_substitution (command
(command_name (word))
(string (simple_expansion (variable_name))))))
(command_substitution (command (command_name (word)) (raw_string)))))
(command (command_name (word)) (word))))
=============================
Test commands with regexes
=============================
[[ "35d8b" =~ ^[0-9a-fA-F] ]]
[[ $CMD =~ (^|;)update_terminal_cwd($|;) ]]
[[ ! " ${completions[*]} " =~ " $alias_cmd " ]]
! [[ "$a" =~ ^a|b\ *c|d$ ]]
---
(program
(test_command
(binary_expression
(string)
(regex)))
(test_command
(binary_expression
(simple_expansion (variable_name))
(regex)))
(test_command
(unary_expression
(binary_expression
(string (expansion (subscript (variable_name) (word))))
(string (simple_expansion (variable_name))))))
(negated_command
(test_command
(binary_expression
(string (simple_expansion (variable_name)))
(regex)))))
=============================== ===============================
Subshells Subshells
=============================== ===============================

View File

@ -17,7 +17,7 @@ module.exports = grammar({
inline: $ => [ inline: $ => [
$._statement, $._statement,
$._terminator, $._terminator,
$._expression, $._literal,
$._primary_expression, $._primary_expression,
$._simple_variable_name, $._simple_variable_name,
$._special_variable_name, $._special_variable_name,
@ -58,7 +58,8 @@ module.exports = grammar({
$.command, $.command,
$.declaration_command, $.declaration_command,
$.unset_command, $.unset_command,
$.bracket_command, $.test_command,
$.negated_command,
$.for_statement, $.for_statement,
$.while_statement, $.while_statement,
$.if_statement, $.if_statement,
@ -74,7 +75,7 @@ module.exports = grammar({
$._simple_variable_name, $._simple_variable_name,
optional(seq( optional(seq(
'in', 'in',
repeat1($._expression) repeat1($._literal)
)), )),
$._terminator, $._terminator,
$.do_group $.do_group
@ -122,7 +123,7 @@ module.exports = grammar({
case_statement: $ => seq( case_statement: $ => seq(
'case', 'case',
$._expression, $._literal,
optional($._terminator), optional($._terminator),
'in', 'in',
$._terminator, $._terminator,
@ -134,8 +135,8 @@ module.exports = grammar({
), ),
case_item: $ => seq( case_item: $ => seq(
$._expression, $._literal,
repeat(seq('|', $._expression)), repeat(seq('|', $._literal)),
')', ')',
optional(seq( optional(seq(
repeat($._terminated_statement), repeat($._terminated_statement),
@ -145,8 +146,8 @@ module.exports = grammar({
), ),
last_case_item: $ => seq( last_case_item: $ => seq(
$._expression, $._literal,
repeat(seq('|', $._expression)), repeat(seq('|', $._literal)),
')', ')',
optional(seq( optional(seq(
repeat($._terminated_statement), repeat($._terminated_statement),
@ -192,6 +193,43 @@ module.exports = grammar({
// Commands // Commands
negated_command: $ => seq(
'!',
choice(
$.command,
$.test_command
)
),
test_command: $ => seq(
choice(
seq('[', $._expression, ']'),
seq('[[', $._expression, ']]')
),
repeat(choice(
$.file_redirect,
$.heredoc_redirect,
$.herestring_redirect
))
),
declaration_command: $ => prec.left(seq(
choice('declare', 'typeset', 'export', 'readonly', 'local'),
repeat(choice(
$._literal,
$._simple_variable_name,
$.variable_assignment
))
)),
unset_command: $ => prec.left(seq(
choice('unset', 'unsetenv'),
repeat(choice(
$._literal,
$._simple_variable_name
))
)),
command: $ => prec.left(seq( command: $ => prec.left(seq(
repeat(choice( repeat(choice(
$.variable_assignment, $.variable_assignment,
@ -199,10 +237,10 @@ module.exports = grammar({
)), )),
$.command_name, $.command_name,
repeat(choice( repeat(choice(
$._expression, $._literal,
seq( seq(
choice('=~', '=='), choice('=~', '=='),
choice($.regex, $._expression) choice($.regex, $._literal)
) )
)), )),
repeat(choice( repeat(choice(
@ -213,62 +251,19 @@ module.exports = grammar({
optional($.heredoc_body) optional($.heredoc_body)
)), )),
command_name: $ => $._expression, command_name: $ => $._literal,
bracket_command: $ => {
const args = repeat1(choice(
$._expression,
seq(
choice('=~', '=='),
choice($.regex, $._expression)
)
))
return seq(
choice(
seq('[', args, ']'),
seq('[[', args, ']]')
),
repeat(choice(
$.file_redirect,
$.heredoc_redirect,
$.herestring_redirect
))
)
},
variable_assignment: $ => seq( variable_assignment: $ => seq(
choice( choice(
$.variable_name, $.variable_name,
$.subscript $.subscript
), ),
$._assignment
),
declaration_command: $ => prec.left(seq(
choice('declare', 'typeset', 'export', 'readonly', 'local'),
repeat(choice(
$._expression,
$._simple_variable_name,
$.variable_assignment
))
)),
unset_command: $ => prec.left(seq(
choice('unset', 'unsetenv'),
repeat(choice(
$._expression,
$._simple_variable_name
))
)),
_assignment: $ => seq(
choice( choice(
'=', '=',
'+=' '+='
), ),
choice( choice(
$._expression, $._literal,
$.array, $.array,
$._empty_value $._empty_value
) )
@ -277,7 +272,7 @@ module.exports = grammar({
subscript: $ => seq( subscript: $ => seq(
$.variable_name, $.variable_name,
'[', '[',
$._expression, $._literal,
optional($._concat), optional($._concat),
']', ']',
optional($._concat) optional($._concat)
@ -286,7 +281,7 @@ module.exports = grammar({
file_redirect: $ => prec.left(seq( file_redirect: $ => prec.left(seq(
optional($.file_descriptor), optional($.file_descriptor),
choice('<', '>', '>>', '&>', '&>>', '<&', '>&'), choice('<', '>', '>>', '&>', '&>>', '<&', '>&'),
$._expression $._literal
)), )),
heredoc_redirect: $ => seq( heredoc_redirect: $ => seq(
@ -309,12 +304,45 @@ module.exports = grammar({
herestring_redirect: $ => seq( herestring_redirect: $ => seq(
'<<<', '<<<',
$._expression $._literal
), ),
// Expressions // Expressions
_expression: $ => choice( _expression: $ => choice(
$._literal,
$.unary_expression,
$.binary_expression,
$.parenthesized_expression
),
binary_expression: $ => prec.left(choice(
seq(
$._expression,
choice('==', '=', '=~', '!=', '<', '>', '||', '&&', $.test_operator),
$._expression
),
seq(
$._expression,
choice('==', '=~'),
$.regex
)
)),
unary_expression: $ => prec.right(seq(
choice('!', $.test_operator),
$._expression
)),
parenthesized_expression: $ => seq(
'(',
$._expression,
')'
),
// Literals
_literal: $ => choice(
$.concatenation, $.concatenation,
$._primary_expression, $._primary_expression,
alias(prec(-2, $._special_characters), $.word) alias(prec(-2, $._special_characters), $.word)
@ -365,7 +393,7 @@ module.exports = grammar({
array: $ => seq( array: $ => seq(
'(', '(',
repeat($._expression), repeat($._literal),
')' ')'
), ),
@ -389,7 +417,7 @@ module.exports = grammar({
seq( seq(
$.variable_name, $.variable_name,
'=', '=',
optional($._expression) optional($._literal)
), ),
seq( seq(
choice( choice(
@ -402,7 +430,7 @@ module.exports = grammar({
alias($.regex_without_right_brace, $.regex) alias($.regex_without_right_brace, $.regex)
)), )),
repeat(choice( repeat(choice(
$._expression, $._literal,
':', ':?', '=', ':-', '%', '-', '#' ':', ':?', '=', ':-', '%', '-', '#'
)) ))
), ),
@ -432,7 +460,10 @@ module.exports = grammar({
seq('\\', noneOf('\\s')) seq('\\', noneOf('\\s'))
))), ))),
test_operator: $ => token(prec(1, seq('-', /[a-zA-Z]+/))),
regex: $ => /([^"\s]|\\.)([^\s]|\\.)*/, regex: $ => /([^"\s]|\\.)([^\s]|\\.)*/,
regex_without_right_brace: $ => /([^"\s}]|\\.)([^\s}]|\\.)*/, regex_without_right_brace: $ => /([^"\s}]|\\.)([^\s}]|\\.)*/,
_terminator: $ => choice(';', ';;', '\n', '&') _terminator: $ => choice(';', ';;', '\n', '&')

View File

@ -1,24 +1,19 @@
examples/bash-it/plugins/available/git.plugin.bash examples/bash-it/plugins/available/git.plugin.bash
examples/bash-it/plugins/available/extract.plugin.bash examples/bash-it/plugins/available/extract.plugin.bash
examples/bash-it/plugins/available/z_autoenv.plugin.bash
examples/bash-it/plugins/available/sshagent.plugin.bash examples/bash-it/plugins/available/sshagent.plugin.bash
examples/bash-it/plugins/available/go.plugin.bash examples/bash-it/plugins/available/go.plugin.bash
examples/bash-it/install.sh examples/bash-it/install.sh
examples/bash-it/completion/available/terraform.completion.bash
examples/bash-it/completion/available/go.completion.bash examples/bash-it/completion/available/go.completion.bash
examples/bash-it/completion/available/maven.completion.bash examples/bash-it/completion/available/maven.completion.bash
examples/bash-it/completion/available/svn.completion.bash examples/bash-it/completion/available/svn.completion.bash
examples/bash-it/completion/available/docker-compose.completion.bash examples/bash-it/completion/available/docker-compose.completion.bash
examples/bash-it/completion/available/jboss7.completion.bash examples/bash-it/completion/available/jboss7.completion.bash
examples/bash-it/completion/available/todo.completion.bash
examples/bash-it/completion/available/gh.completion.bash examples/bash-it/completion/available/gh.completion.bash
examples/bash-it/completion/available/bundler.completion.bash examples/bash-it/completion/available/bundler.completion.bash
examples/bash-it/completion/available/gradle.completion.bash examples/bash-it/completion/available/gradle.completion.bash
examples/bash-it/completion/available/drush.completion.bash examples/bash-it/completion/available/drush.completion.bash
examples/bash-it/completion/available/test_kitchen.completion.bash
examples/bash-it/completion/available/hub.completion.bash examples/bash-it/completion/available/hub.completion.bash
examples/bash-it/completion/available/docker-machine.completion.bash examples/bash-it/completion/available/docker-machine.completion.bash
examples/bash-it/completion/available/fabric-completion.bash
examples/bash-it/completion/available/git.completion.bash examples/bash-it/completion/available/git.completion.bash
examples/bash-it/completion/available/vagrant.completion.bash examples/bash-it/completion/available/vagrant.completion.bash
examples/bash-it/completion/available/defaults.completion.bash examples/bash-it/completion/available/defaults.completion.bash
@ -27,7 +22,6 @@ examples/bash-it/completion/available/salt.completion.bash
examples/bash-it/completion/available/vault.completion.bash examples/bash-it/completion/available/vault.completion.bash
examples/bash-it/completion/available/docker.completion.bash examples/bash-it/completion/available/docker.completion.bash
examples/bash-it/completion/available/tmux.completion.bash examples/bash-it/completion/available/tmux.completion.bash
examples/bash-it/completion/available/projects.completion.bash
examples/bash-it/completion/available/virsh.completion.bash examples/bash-it/completion/available/virsh.completion.bash
examples/bash-it/completion/available/apm.completion.bash examples/bash-it/completion/available/apm.completion.bash
examples/bash-it/completion/available/git_flow.completion.bash examples/bash-it/completion/available/git_flow.completion.bash
@ -39,7 +33,6 @@ examples/bash-it/test_lib/bats-support/src/output.bash
examples/bash-it/test_lib/bats-assert/src/assert.bash examples/bash-it/test_lib/bats-assert/src/assert.bash
examples/bash-it/test_lib/bats-file/src/temp.bash examples/bash-it/test_lib/bats-file/src/temp.bash
examples/bash-it/themes/hawaii50/hawaii50.theme.bash examples/bash-it/themes/hawaii50/hawaii50.theme.bash
examples/bash-it/themes/iterate/iterate.theme.bash
examples/bash-it/themes/dulcie/dulcie.theme.bash examples/bash-it/themes/dulcie/dulcie.theme.bash
examples/bash-it/themes/colors.theme.bash examples/bash-it/themes/colors.theme.bash
examples/bash-it/themes/rana/rana.theme.bash examples/bash-it/themes/rana/rana.theme.bash

634
src/grammar.json vendored
View File

@ -42,7 +42,11 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "bracket_command" "name": "test_command"
},
{
"type": "SYMBOL",
"name": "negated_command"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -103,7 +107,7 @@
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
} }
} }
] ]
@ -288,7 +292,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@ -350,7 +354,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -363,7 +367,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
} }
] ]
} }
@ -419,7 +423,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -432,7 +436,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
} }
] ]
} }
@ -684,6 +688,184 @@
] ]
} }
}, },
"negated_command": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "!"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "command"
},
{
"type": "SYMBOL",
"name": "test_command"
}
]
}
]
},
"test_command": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": "]"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "[["
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": "]]"
}
]
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "file_redirect"
},
{
"type": "SYMBOL",
"name": "heredoc_redirect"
},
{
"type": "SYMBOL",
"name": "herestring_redirect"
}
]
}
}
]
},
"declaration_command": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "declare"
},
{
"type": "STRING",
"value": "typeset"
},
{
"type": "STRING",
"value": "export"
},
{
"type": "STRING",
"value": "readonly"
},
{
"type": "STRING",
"value": "local"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "SYMBOL",
"name": "_simple_variable_name"
},
{
"type": "SYMBOL",
"name": "variable_assignment"
}
]
}
}
]
}
},
"unset_command": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "unset"
},
{
"type": "STRING",
"value": "unsetenv"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "SYMBOL",
"name": "_simple_variable_name"
}
]
}
}
]
}
},
"command": { "command": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 0, "value": 0,
@ -717,7 +899,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
}, },
{ {
"type": "SEQ", "type": "SEQ",
@ -744,7 +926,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
} }
] ]
} }
@ -790,149 +972,7 @@
}, },
"command_name": { "command_name": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
},
"bracket_command": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "=~"
},
{
"type": "STRING",
"value": "=="
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "regex"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
]
}
]
}
},
{
"type": "STRING",
"value": "]"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "[["
},
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "=~"
},
{
"type": "STRING",
"value": "=="
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "regex"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
]
}
]
}
},
{
"type": "STRING",
"value": "]]"
}
]
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "file_redirect"
},
{
"type": "SYMBOL",
"name": "heredoc_redirect"
},
{
"type": "SYMBOL",
"name": "herestring_redirect"
}
]
}
}
]
}, },
"variable_assignment": { "variable_assignment": {
"type": "SEQ", "type": "SEQ",
@ -950,107 +990,6 @@
} }
] ]
}, },
{
"type": "SYMBOL",
"name": "_assignment"
}
]
},
"declaration_command": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "declare"
},
{
"type": "STRING",
"value": "typeset"
},
{
"type": "STRING",
"value": "export"
},
{
"type": "STRING",
"value": "readonly"
},
{
"type": "STRING",
"value": "local"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "_simple_variable_name"
},
{
"type": "SYMBOL",
"name": "variable_assignment"
}
]
}
}
]
}
},
"unset_command": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "unset"
},
{
"type": "STRING",
"value": "unsetenv"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "_simple_variable_name"
}
]
}
}
]
}
},
"_assignment": {
"type": "SEQ",
"members": [
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -1069,7 +1008,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -1096,7 +1035,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@ -1181,7 +1120,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
} }
] ]
} }
@ -1259,11 +1198,164 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
} }
] ]
}, },
"_expression": { "_expression": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "SYMBOL",
"name": "unary_expression"
},
{
"type": "SYMBOL",
"name": "binary_expression"
},
{
"type": "SYMBOL",
"name": "parenthesized_expression"
}
]
},
"binary_expression": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"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": "&&"
},
{
"type": "SYMBOL",
"name": "test_operator"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "=="
},
{
"type": "STRING",
"value": "=~"
}
]
},
{
"type": "SYMBOL",
"name": "regex"
}
]
}
]
}
},
"unary_expression": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "!"
},
{
"type": "SYMBOL",
"name": "test_operator"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"parenthesized_expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ")"
}
]
},
"_literal": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -1501,7 +1593,7 @@
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
} }
}, },
{ {
@ -1605,7 +1697,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -1674,7 +1766,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_literal"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -1872,6 +1964,26 @@
} }
} }
}, },
"test_operator": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "-"
},
{
"type": "PATTERN",
"value": "[a-zA-Z]+"
}
]
}
}
},
"regex": { "regex": {
"type": "PATTERN", "type": "PATTERN",
"value": "([^\"\\s]|\\\\.)([^\\s]|\\\\.)*" "value": "([^\"\\s]|\\\\.)([^\\s]|\\\\.)*"
@ -1978,7 +2090,7 @@
"inline": [ "inline": [
"_statement", "_statement",
"_terminator", "_terminator",
"_expression", "_literal",
"_primary_expression", "_primary_expression",
"_simple_variable_name", "_simple_variable_name",
"_special_variable_name" "_special_variable_name"

151806
src/parser.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -9,13 +9,14 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
typedef uint16_t TSSymbol;
typedef uint16_t TSStateId;
#define ts_builtin_sym_error ((TSSymbol)-1) #define ts_builtin_sym_error ((TSSymbol)-1)
#define ts_builtin_sym_end 0 #define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef uint16_t TSSymbol;
typedef uint16_t TSStateId;
typedef struct { typedef struct {
bool visible : 1; bool visible : 1;
bool named : 1; bool named : 1;
@ -129,6 +130,7 @@ typedef struct TSLanguage {
*/ */
#define STATE(id) id #define STATE(id) id
#define ACTIONS(id) id #define ACTIONS(id) id
#define SHIFT(state_value) \ #define SHIFT(state_value) \