-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathudev_rule_grammar.pest
66 lines (59 loc) · 2.51 KB
/
udev_rule_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
57
58
59
60
61
62
63
/// Grammar for parsing udev rules
WHITESPACE = _{ " " }
// if remove *, will throw error when empty string
udev_rule = { SOI ~ (inner_rule)* ~ EOI }
inner_rule = { udev_filter ~ ("," ~ udev_filter)* }
udev_filter = ${ field ~ operation ~ quoted_value }
field = { unsupported_field | attributes | attribute | devpath | drivers | driver | kernels | kernel | property | subsystems | subsystem | tags | tag }
action_field = { label | goto | group | import | options | owner | mode | run | wait_for }
unsupported_field = { action | action_field | constant | name | program | result | seclabel | symlink | sysctl | test }
bounded_key = {"{" ~ key ~ "}"}
// remove ! on key and value rules if want to allow spaces between ""/{} and key/value (ie: { DEVPATH } vs {DEVPATH})
key = !{ (ASCII_ALPHANUMERIC | SPACE_SEPARATOR | "$" | "." | "_" | "*" | "?" | "[" | "]" | "-" | "|" | "\\" | "/" )* }
value = !{ (ASCII_ALPHANUMERIC | SPACE_SEPARATOR | "$" | "." | "_" | "*" | ":" | "?" | "[" | "]" | "-" | "|" | "\\" | "/" | "%" | "{"| "}")* }
allowed_value_characters = { ASCII_DIGIT | ASCII_ALPHA | MARK | PUNCTUATION | SYMBOL | SPACE_SEPARATOR }
quoted_value = {"\"" ~ value ~ "\""}
operation = { equality | inequality | action_operation }
action_operation = { addition | removal | final_assignment | assignment }
equality = { "==" }
inequality = { "!=" }
assignment = { "=" }
addition = { "+=" }
removal = { "-=" }
final_assignment = { ":=" }
// Supported fields
attributes = { "ATTRS" ~ bounded_key }
attribute = { "ATTR" ~ bounded_key } // {key}
devpath = { "DEVPATH" }
drivers = { "DRIVERS" }
driver = { "DRIVER" }
kernels = { "KERNELS" }
kernel = { "KERNEL" }
property = { "ENV" ~ bounded_key } // {key}
subsystems = { "SUBSYSTEMS" }
subsystem = { "SUBSYSTEM" }
tags = { "TAGS" }
tag = { "TAG" }
//
// Unsupported fields
//
// Unsupported action only fields
goto = { "GOTO" }
group = { "GROUP" }
label = { "LABEL" }
import = { "IMPORT" ~ bounded_key } // {type} where type = program | builtin | file | db | cmdline | parent
mode = { "MODE" }
options = { "OPTIONS" }
owner = { "OWNER" }
run = { "RUN" ~ bounded_key } // {type} where type = program | builtin
wait_for = { "WAIT_FOR" }
// Other unsupported match (and action) fields
action = { "ACTION" }
constant = { "CONST" ~ bounded_key } // {key} where key = "arch" | "virt"
name = { "NAME" }
program = { "PROGRAM" }
result = { "RESULT" }
seclabel = { "SECLABEL" ~ bounded_key } // {module}
symlink = { "SYMLINK" }
sysctl = { "SYSCTL" ~ bounded_key } // {kernel key}
test = { "TEST" ~ bounded_key } // {octal mode mask}