diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-08 00:28:37 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-08 00:28:37 -0500 |
commit | 489fd0db1bf7f1de31a043e315179e83b77921aa (patch) | |
tree | a4862b8f8572234305eae3a1128860a7a1d5117c /src/shell.pest | |
parent | 9dd1d992bd2344d8824e69d8f47c9009a6caf021 (diff) | |
download | nbsh-489fd0db1bf7f1de31a043e315179e83b77921aa.tar.gz nbsh-489fd0db1bf7f1de31a043e315179e83b77921aa.zip |
add basic variable parsing
Diffstat (limited to 'src/shell.pest')
-rw-r--r-- | src/shell.pest | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/shell.pest b/src/shell.pest index ffb0f42..b1bcae5 100644 --- a/src/shell.pest +++ b/src/shell.pest @@ -3,11 +3,17 @@ escape_char = @{ "\\" ~ ANY } bareword_char = @{ escape_char | - !("|" | ";" | "\"" | "'" | WHITESPACE | COMMENT) ~ ANY + !("|" | ";" | "\"" | "'" | "$" | WHITESPACE | COMMENT) ~ ANY } single_string_char = @{ basic_escape_char | (!"'" ~ ANY) } double_string_char = @{ escape_char | (!"\"" ~ ANY) } +var = @{ + ("$" ~ XID_START ~ XID_CONTINUE*) | + ("$" ~ ("?" | "$" | "*" | ASCII_DIGIT)) | + ("${" ~ (!"}" ~ ANY)+ ~ "}") +} + redir_prefix = @{ ASCII_DIGIT* ~ (">>" | ">" | "<") ~ WHITESPACE* } bareword = @{ bareword_char+ } single_string = @{ single_string_char+ } @@ -15,17 +21,17 @@ double_string = @{ double_string_char+ } word = ${ redir_prefix? ~ - (bareword | + (var | bareword | "'" ~ single_string ~ "'" | "\"" ~ double_string ~ "\"") } exe = ${ word ~ (w ~ word)* } -pipeline = ${ exe ~ (w ~ "|" ~ w ~ exe)* } -commands = ${ pipeline ~ (w ~ ";" ~ w ~ pipeline)* } +pipeline = ${ exe ~ (w? ~ "|" ~ w? ~ exe)* } +commands = ${ pipeline ~ (w? ~ ";" ~ w? ~ pipeline)* } -line = ${ SOI ~ w ~ commands ~ w ~ EOI } +line = ${ SOI ~ w? ~ commands ~ w? ~ EOI } -w = _{ (WHITESPACE | COMMENT)* } +w = _{ (WHITESPACE | COMMENT)+ } WHITESPACE = _{ (" " | "\t" | "\n") } COMMENT = _{ "#" ~ ANY* } |