-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.bnf
25 lines (23 loc) · 1.17 KB
/
grammar.bnf
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
; based on BSD manpage: https://man.openbsd.org/re_format.7
; TODO: anchors, equivalence classes, boundaries, collating symbols
<re> ::= <branch> | <re> "|" <branch>
<branch> ::= <simple-re> | <branch> <simple-re>
<simple-re> ::= <basic-re> | <basic-re> <quantifier>
<basic-re> ::= <group> | <expr>
<expr> ::= <literal> | "." | <bracket>
<literal> ::= ? any non <meta> character ? | <escaped>
<meta> ::= "\" | "|" | "." | "?" | "+" | "*" | "(" | ")" | "{" | "}"
<escaped> ::= "\" ? any char ?
<group> ::= "(" <re> ")"
<quantifier> ::= "?" | "+" | "*" | "{" <range> "}"
<range> ::= number | number "," | number "," number
<bracket> ::= "[" <list> "]" | "[" "^" <list> "]"
<list> ::= <simple-list> | "]" <simple-list> | "-" <simple-list> |
<simple-list> "-" | "-" <simple-list> "-"
<simple-list> ::= <term> | <simple-list> <term>
<term> ::= <bracket-literal> | <class> | <range-expr>
<range-expr> ::= <bracket-literal> "-" <bracket-literal>
<bracket-literal> ::= ? any char except "\" ? | <escaped>
<class> ::= "[:" <class-name> ":]"
<class-name> ::= "alnum" | "alpha" | "blank" | "cntrl" | "digit" | "graph"
"lower" | "print" | "punct" | "space" | "upper" | "xdigit"