From f34d7e834ded2c0356e91d10eb3c87391d8f6701 Mon Sep 17 00:00:00 2001 From: Andreas Nordal Date: Mon, 4 Jun 2018 00:30:31 +0200 Subject: [PATCH] Quoting not needed inside double brackets Fixes #8 --- shellharden.rs | 8 ++++++++ test/expected/control_structures.bash | 18 ++++++++++++++++++ .../expected/unexpected_eof_doublebracket.bash | 5 +++++ test/original/control_structures.bash | 18 ++++++++++++++++++ .../original/unexpected_eof_doublebracket.bash | 1 + 5 files changed, 50 insertions(+) create mode 100644 test/expected/control_structures.bash create mode 100644 test/expected/unexpected_eof_doublebracket.bash create mode 100644 test/original/control_structures.bash create mode 100644 test/original/unexpected_eof_doublebracket.bash diff --git a/shellharden.rs b/shellharden.rs index 4d8f372..a143b56 100644 --- a/shellharden.rs +++ b/shellharden.rs @@ -619,6 +619,14 @@ fn keyword_or_command( return flush(i); } let word = &horizon[i..i+len]; + if word == b"[[" { + return WhatNow{ + tri: Transition::Push(Box::new( + SitVec{terminator: vec!{b']', b']'}, color: 0x00007fff} + )), + pre: i, len: len, alt: None + }; + } match KEYWORDS_SORTED.binary_search(&word) { Ok(_) => WhatNow{ tri: Transition::Push(Box::new(SitExtent{ diff --git a/test/expected/control_structures.bash b/test/expected/control_structures.bash new file mode 100644 index 0000000..ff7eb32 --- /dev/null +++ b/test/expected/control_structures.bash @@ -0,0 +1,18 @@ +if [[ -v $julenissen ]]; then + [[ $julenissen ]] || [[ $kake ]] || exit 1 + env [[ He is a "$n"åså ]] + a a a a | a a a a ; a a a a & a a a a +fi + +# Comment above command +true + +if true; then true true; fi + +echo It is not possible \ +# FIXME \ +echo to comment between args + +if test -e julenissen; then echo ja; elif test -e kake; then echo ok; else echo nei; fi +for i in "$a"; do echo "$i"; done +case "$PATH" in *"$HOME"*) echo homeopath;; esac diff --git a/test/expected/unexpected_eof_doublebracket.bash b/test/expected/unexpected_eof_doublebracket.bash new file mode 100644 index 0000000..95adc75 --- /dev/null +++ b/test/expected/unexpected_eof_doublebracket.bash @@ -0,0 +1,5 @@ +[[ + +test/original/unexpected_eof_doublebracket.bash: Unexpected end of file +The file's end was reached without closing all sytactic scopes. +Either, the parser got lost, or the file is truncated or malformed. diff --git a/test/original/control_structures.bash b/test/original/control_structures.bash new file mode 100644 index 0000000..154b706 --- /dev/null +++ b/test/original/control_structures.bash @@ -0,0 +1,18 @@ +if [[ -v $julenissen ]]; then + [[ $julenissen ]] || [[ $kake ]] || exit 1 + env [[ He is a $nåså ]] + a a a a | a a a a ; a a a a & a a a a +fi + +# Comment above command +true + +if true; then true true; fi + +echo It is not possible \ +# FIXME \ +echo to comment between args + +if test -e julenissen; then echo ja; elif test -e kake; then echo ok; else echo nei; fi +for i in $a; do echo $i; done +case $PATH in *"$HOME"*) echo homeopath;; esac diff --git a/test/original/unexpected_eof_doublebracket.bash b/test/original/unexpected_eof_doublebracket.bash new file mode 100644 index 0000000..25ce3fc --- /dev/null +++ b/test/original/unexpected_eof_doublebracket.bash @@ -0,0 +1 @@ +[[