-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgrammar.pest
56 lines (44 loc) · 2.03 KB
/
grammar.pest
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
WHITESPACE = _{ "\t" | " " }
COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* ~ NEWLINE}
file = { SOI ~ NEWLINE* ~ setting* ~ NEWLINE* ~ ((menu|snippet) ~ NEWLINE*)+ ~ EOI }
menu = { "menu" ~ string? ~ symbol ~ NEWLINE* ~ OPENBR ~ menu_body ~ CLOSINGBR }
OPENBR = _{"{"}
CLOSINGBR = _{"}"}
setting = { shell_def | echo_setting}
shell_def = {"shell" ~ (string|word)+ }
word = @{ (!("\"" | WHITESPACE | NEWLINE) ~ ANY)+ }
echo_setting = {"echo" ~ echo_val}
echo_val = {"on" | "off"}
menu_body = { (NEWLINE* ~ entry ~ NEWLINE*)+ }
entry = { keydef ~ ":" ~ (anon_command | quick_command | symbol)}
keydef = @{ (!(":" | WHITESPACE | NEWLINE) ~ ANY)* }
symbol = @{ (ASCII_ALPHANUMERIC | "_")+ }
string = { normal_string | protected_string }
// a normal string in which you can escape a " with a \
normal_string = ${ QUOTE ~ normal_content ~ QUOTE }
normal_content = @{ ("\\\"" | !QUOTE ~ ANY)* }
QUOTE = _{ "\"" }
// a raw string, which is delimited by !""!
// where you can insert any sign to make it unique e.g.
// !x""x!. Multiple inserts are not mirrored, so this is valid:
// !ab"content"ab!, but this is not: !ab"content"ba!
protected_string = ${(sep_start ~ protected_content ~ sep_end)}
protected_content = @{ (!("\"" ~ PEEK ~ "!") ~ ANY)* }
quick_command = {command_name? ~ ECHO_TOGGLE_TOKEN? ~ string_expr}
command_name = { (string ~ "-") }
ECHO_TOGGLE_TOKEN = {"@"}
sep_start = _{ EXCL ~ PUSH((!"\"" ~ ANY)*) ~ QUOTE}
sep_end = _{ QUOTE ~ POP ~ EXCL }
EXCL = _{ "!" }
anon_command = { "cmd" ~ NEWLINE* ~ OPENBR
~ NEWLINE* ~ cmd_body ~ NEWLINE* ~ CLOSINGBR }
cmd_body = { ((cmd_settings|vars_def|shell_def) ~ NEWLINE)* ~ quick_command }
vars_def = { "vars" ~ var_def ~ (DEF_SEP* ~ var_def)* }
DEF_SEP = _{"," ~ NEWLINE*}
var_def = { symbol ~ default_var? }
default_var = { "=" ~ string }
cmd_settings = { "set" ~ symbol ~ (DEF_SEP* ~ symbol)* }
snippet = { "snippet" ~ NEWLINE* ~ symbol ~ "=" ~ string_expr}
string_expr = { string_expr_elem ~ (NEWLINE* ~ "+" ~ NEWLINE* ~ string_expr_elem)*}
string_expr_elem = { string | snippet_symbol }
snippet_symbol = @{"$" ~ symbol}