summaryrefslogtreecommitdiffstats
path: root/src/shell.pest
blob: ffb0f420bec68fbb874c97876583a3acfeae956a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
basic_escape_char = @{ "\\\\" | "\\'" }
escape_char       = @{ "\\" ~ ANY }

bareword_char = @{
    escape_char |
    !("|" | ";" | "\"" | "'" | WHITESPACE | COMMENT) ~ ANY
}
single_string_char = @{ basic_escape_char | (!"'" ~ ANY) }
double_string_char = @{ escape_char | (!"\"" ~ ANY) }

redir_prefix  = @{ ASCII_DIGIT* ~ (">>" | ">" | "<") ~ WHITESPACE* }
bareword      = @{ bareword_char+ }
single_string = @{ single_string_char+ }
double_string = @{ double_string_char+ }

word     = ${
    redir_prefix? ~
    (bareword |
    "'" ~ single_string ~ "'" |
    "\"" ~ double_string ~ "\"")
}

exe      = ${ word ~ (w ~ word)* }
pipeline = ${ exe ~ (w ~ "|" ~ w ~ exe)* }
commands = ${ pipeline ~ (w ~ ";" ~ w ~ pipeline)* }

line = ${ SOI ~ w ~ commands ~ w ~ EOI }

w          = _{ (WHITESPACE | COMMENT)* }
WHITESPACE = _{ (" " | "\t" | "\n") }
COMMENT    = _{ "#" ~ ANY* }