Handle heredocs followed by pipes or redirects

Fixes atom/language-shellscript#134
This commit is contained in:
Max Brunsfeld 2019-04-18 15:25:40 -07:00
parent da10d84aec
commit 53446e0e81
6 changed files with 119179 additions and 133584 deletions

View File

@ -160,9 +160,9 @@ wc -l $tmpfile
(program
(redirected_statement
(command (command_name (word)))
(heredoc_redirect (heredoc_start)))
(heredoc_redirect (heredoc_start))
(file_redirect (simple_expansion (variable_name))))
(heredoc_body
(simple_expansion (variable_name))
(simple_expansion (variable_name))
(expansion (variable_name)))
(command
@ -170,6 +170,24 @@ wc -l $tmpfile
(word)
(simple_expansion (variable_name))))
=================================
Heredocs with pipes
================================
one <<EOF | grep two
three
EOF
---
(program
(pipeline
(redirected_statement
(command (command_name (word)))
(heredoc_redirect (heredoc_start)))
(command (command_name (word)) (word)))
(heredoc_body))
======================================
Heredocs with escaped expansions
======================================

View File

@ -54,11 +54,11 @@ module.exports = grammar({
_statements: $ => prec(1, seq(
repeat(seq(
$._statement,
optional($.heredoc_body),
optional(seq('\n', $.heredoc_body)),
$._terminator
)),
$._statement,
optional($.heredoc_body),
optional(seq('\n', $.heredoc_body)),
optional($._terminator)
)),

View File

@ -16,7 +16,7 @@
"devDependencies": {
"nodemon": "^1.18.3",
"prebuild": "^7.6.1",
"tree-sitter-cli": "^0.13.1"
"tree-sitter-cli": "^0.14.5"
},
"scripts": {
"build": "tree-sitter generate && node-gyp build",

18
src/grammar.json vendored
View File

@ -32,9 +32,18 @@
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "SYMBOL",
"name": "heredoc_body"
}
]
},
{
"type": "BLANK"
@ -55,9 +64,18 @@
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "SYMBOL",
"name": "heredoc_body"
}
]
},
{
"type": "BLANK"

252705
src/parser.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@ extern "C" {
#define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
#ifndef TREE_SITTER_RUNTIME_H_
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSSymbol;
typedef struct TSLanguage TSLanguage;
#endif