Skip to content

Commit

Permalink
stop using implicit whitespace
Browse files Browse the repository at this point in the history
the end of rule whitespace handling is weird and inconsistent, see
pest-parser/pest#396 and
pest-parser/pest#519
  • Loading branch information
doy committed Jan 6, 2022
1 parent 6bfb525 commit 3ec1f55
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/shell.pest
Original file line number Diff line number Diff line change
Expand Up @@ -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* }

0 comments on commit 3ec1f55

Please sign in to comment.