-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
peppa.peg
117 lines (96 loc) · 2.09 KB
/
peppa.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
grammar = start_of_input rule+ end_of_input;
start_of_input = &.;
end_of_input = !.;
rule = decorators name @cut "=" expression ";";
decorators = decorator*;
decorator = "@" @cut (
"squashed"
/ "scoped"
/ "spaced"
/ "lifted"
/ "tight"
/ "nonterminal"
);
@squashed
name = reference;
@lifted
expression = left_recursion;
@nonterminal
left_recursion = choice ("|" @cut reference choice)?;
@nonterminal
choice = sequence ("/" sequence)*;
@nonterminal
sequence = repeat+;
@nonterminal
repeat = primary (
onceormore
/ zeroormore
/ zerooronce
/ repeatexact
/ repeatminmax
/ repeatmin
/ repeatmax
)?;
onceormore = "+";
zeroormore = "*";
zerooronce = "?";
repeatexact = "{" number "}";
repeatminmax = "{" number "," number "}";
repeatmin = "{" number "," "}";
repeatmax = "{" "," number "}";
@lifted
primary = literal
/ insensitive
/ range
/ (reference !"=")
/ back_reference
/ positive
/ negative
/ "(" choice ")"
/ dot
/ cut;
@squashed @tight
literal = "\"" @cut chars "\"";
chars = char*;
@squashed @tight
char = [\x20-\x21] / [\x23-\x5b] / [\x5d-\U0010ffff] / (
"\\" (
"\""
/ "/"
/ "\\"
/ "b"
/ "f"
/ "n"
/ "r"
/ "t"
/ ("x" @cut two_hexdigits)
/ ("u" @cut four_hexdigits)
/ ("U" @cut eight_hexdigits)
)
);
@squashed @tight
range_category = ([a-z] / [A-Z] / [0-9] / "_" / " ")+;
range = "[" (
(char "-" char (".." number)?)
/ ("\\p{" range_category "}")
) "]";
@tight
insensitive = "i" (literal / back_reference);
@squashed @tight
reference = ([a-z] / [A-Z] / "_") ([a-z] / [A-Z] / [0-9] / "_")*;
@tight
back_reference = "\\" @cut number;
positive = "&" @cut primary;
negative = "!" @cut primary;
dot = ".";
cut = "@cut";
hexdigit = [0-9] / [a-f] / [A-F];
two_hexdigits = hexdigit{2};
four_hexdigits = hexdigit{4};
eight_hexdigits = hexdigit{8};
@squashed @tight
number = "0" / [1-9] [0-9]*;
@lifted @spaced
comment = "#" (!"\n" .)* "\n"?;
@lifted @spaced
whitespace = " " / "\t" / "\r" / "\n";