-
Notifications
You must be signed in to change notification settings - Fork 2
/
PEG.peg
88 lines (59 loc) · 2.38 KB
/
PEG.peg
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
RuleSet ← LB* (Comment / Rule) (LB+ (Comment / Rule))* LB*
/ ϵ
Comment ← ";" [^ U+000A U+000D ]*
Rule ← NonTerminal S ("←"/"<-") S OrdChoice
PropSpec ← [a-z A-Z _ - U+0020 ]+
UPlusCodePoint ← "U+" HEXDIG{4,6}
PositiveSpec ← "[:" PropSpec ":]"
NegativeSpec ← "[:^" PropSpec ":]"
CodePoint ← UPlusCodePoint
/ CodePointLit
CodePointLit ← !"except" [ [:^Zs:] − U+005D − U+2212 ]
CodePointFrom ← CodePoint
CodePointTo ← CodePoint
CodePointRange ← CodePointFrom "-" CodePointTo
UnicodePropSpec ← PositiveSpec / NegativeSpec
CodePointExpr ← UnicodePropSpec
/ CodePointRange
/ CodePoint
CharSetUnion ← CodePointExpr ( S? CodePointExpr )*
HEXDIG ← [0-9A-F]
CharSetDifference ← CharSetUnion
( S ([U+2212]/"except") S CharSetUnion )*
CharEscape ← [U+005C] HEXDIG{4,4}
/ [U+005C] [ f n r t v ]
/ [U+005C] [U+0022]
CharSetExpr ← CharSetDifference S?
StrLit ← [U+0022] ( CharEscape / [^"\] )* [U+0022]
CharSet ← NegCharSet / PosCharSet
PosCharSet ← "[" S? ( CharSetExpr / ϵ ) "]"
NegCharSet ← "[^" S? ( CharSetExpr / ϵ ) "]"
Epsilon ← "ϵ"
AtomicExpr ← Epsilon / CharSet / NonTerminal / StrLit
ParenthExpr ← "(" OrdChoice ")"
Replicand ← ParenthExpr
/ AtomicExpr
N ← [0-9]*
M ← [0-9]*
Optional ← Replicand "?"
MNRep ← Replicand "{" M ("," N)? "}"
PosRep ← Replicand "+"
AnyRep ← Replicand "*"
SeqUnit ← AnyRep
/ PosRep
/ MNRep
/ Optional
/ ParenthExpr
/ PosLookahead
/ NegLookahead
/ AtomicExpr
Sequence ← (SeqUnit S?)+
IdentChar ← [ a-z A-Z 0-9 _ ]
IdentStartChar ← [ A-Z ]
OrdChoice ← S? Sequence S? ("/" S? Sequence S?)*
S ← SpaceAtom+
SpaceAtom ← " " / LB " "
LB ← [U+000D][U+000A] / [U+000D U+000A]
NonTerminal ← IdentStartChar IdentChar*
PosLookahead ← "&" SeqUnit
NegLookahead ← "!" SeqUnit