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 (program
(redirected_statement (redirected_statement
(command (command_name (word))) (command (command_name (word)))
(heredoc_redirect (heredoc_start))) (heredoc_redirect (heredoc_start))
(file_redirect (simple_expansion (variable_name))))
(heredoc_body (heredoc_body
(simple_expansion (variable_name))
(simple_expansion (variable_name)) (simple_expansion (variable_name))
(expansion (variable_name))) (expansion (variable_name)))
(command (command
@ -170,6 +170,24 @@ wc -l $tmpfile
(word) (word)
(simple_expansion (variable_name)))) (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 Heredocs with escaped expansions
====================================== ======================================

View File

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

View File

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

26
src/grammar.json vendored
View File

@ -33,8 +33,17 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "heredoc_body" "members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "SYMBOL",
"name": "heredoc_body"
}
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -56,8 +65,17 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "heredoc_body" "members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "SYMBOL",
"name": "heredoc_body"
}
]
}, },
{ {
"type": "BLANK" "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 ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
#ifndef TREE_SITTER_RUNTIME_H_ #ifndef TREE_SITTER_API_H_
typedef uint16_t TSSymbol; typedef uint16_t TSSymbol;
typedef struct TSLanguage TSLanguage; typedef struct TSLanguage TSLanguage;
#endif #endif