From 46cf157ad8a9665cb943350e02cd1c6371925ca9 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 18 Oct 2018 11:12:43 -0700 Subject: [PATCH] Handle escaped expansions in heredocs Fixes #28 --- corpus/commands.txt | 12 ++++++++++++ src/scanner.cc | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/corpus/commands.txt b/corpus/commands.txt index bf8b322..29a4c47 100644 --- a/corpus/commands.txt +++ b/corpus/commands.txt @@ -169,3 +169,15 @@ wc -l $tmpfile (command_name (word)) (word) (simple_expansion (variable_name)))) + +====================================== +Heredocs with escaped expansions +====================================== + +cat << EOF +DEV_NAME=\$(lsblk) +EOF + +--- + +(program (redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body)) diff --git a/src/scanner.cc b/src/scanner.cc index eb392d7..02b2cf0 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -61,6 +61,13 @@ struct Scanner { return did_advance; } + case '\\': { + did_advance = true; + advance(lexer); + advance(lexer); + break; + } + case '$': { lexer->result_symbol = middle_type; return did_advance;