summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-06 04:16:11 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-06 04:16:11 -0500
commit3ec1f55f4df5d6e5a353c19be1f325ed0657ca8b (patch)
treef1c5f209ab9868e3667553a237390e73d6982bfb
parent6bfb525c90ea2fe166c812e63fa20b71b0ec113d (diff)
downloadnbsh-3ec1f55f4df5d6e5a353c19be1f325ed0657ca8b.tar.gz
nbsh-3ec1f55f4df5d6e5a353c19be1f325ed0657ca8b.zip
stop using implicit whitespace
the end of rule whitespace handling is weird and inconsistent, see https://github.com/pest-parser/pest/issues/396 and https://github.com/pest-parser/pest/issues/519
-rw-r--r--src/shell.pest15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/shell.pest b/src/shell.pest
index e61b5bd..408a996 100644
--- a/src/shell.pest
+++ b/src/shell.pest
@@ -2,21 +2,24 @@ bareword_char = @{ !("|" | ";" | "\"" | "'" | WHITESPACE | COMMENT) ~ ANY }
single_string_char = @{ "\\'" | (!"'" ~ ANY) }
double_string_char = @{ "\\\"" | (!"\"" ~ ANY) }
+redir_prefix = @{ (ASCII_DIGIT* ~ (">" | "<" | ">>") ~ WHITESPACE*) }
bareword = @{ bareword_char+ }
single_string = @{ single_string_char+ }
double_string = @{ double_string_char+ }
word = ${
- bareword |
+ redir_prefix? ~
+ (bareword |
"'" ~ single_string ~ "'" |
- "\"" ~ double_string ~ "\""
+ "\"" ~ double_string ~ "\"")
}
-exe = { word+ }
-pipeline = { exe ~ ("|" ~ exe)* }
-commands = { pipeline ~ (";" ~ pipeline)* }
+exe = ${ word ~ (w ~ word)* }
+pipeline = ${ exe ~ (w ~ "|" ~ w ~ exe)* }
+commands = ${ pipeline ~ (w ~ ";" ~ w ~ pipeline)* }
-line = { SOI ~ commands ~ EOI }
+line = ${ SOI ~ w ~ commands ~ w ~ EOI }
+w = _{ (WHITESPACE | COMMENT)* }
WHITESPACE = _{ (" " | "\t" | "\n") }
COMMENT = _{ "#" ~ ANY* }