Debian Codegraph @

lib/Marpa/R2/meta/metag.bnf

raw
1 # Copyright 2022 Jeffrey Kegler
2 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
3 # redistribute it and/or modify it under the terms of the GNU Lesser
4 # General Public License as published by the Free Software Foundation,
5 # either version 3 of the License, or (at your option) any later version.
6 #
7 # Marpa::R2 is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11 #
12 # You should have received a copy of the GNU Lesser
13 # General Public License along with Marpa::R2. If not, see
14 # http://www.gnu.org/licenses/.
15
16 :default ::= action => [start,length,values] bless => ::lhs
17 lexeme default =
18 action => [start,length,value]
19 bless => ::name
20 forgiving => 1
21
22 :start ::= statements
23 statements ::= statement+
24 statement ::= <start rule> | <empty rule>
25 | <null statement> | <statement group>
26 | <priority rule> | <quantified rule>
27 | <discard rule> | <default rule>
28 | <lexeme default statement>
29 | <discard default statement>
30 | <lexeme rule>
31 | <completion event declaration>
32 | <nulled event declaration>
33 | <prediction event declaration>
34 | <current lexer statement>
35 | <inaccessible statement>
36
37 <null statement> ::= ';'
38 <statement group> ::= ('{') statements '}'
39 <start rule> ::= (':start' <op declare bnf>) symbol
40 <start rule> ::= ('start' 'symbol' 'is') symbol
41 <default rule> ::= ':default' <op declare bnf> <adverb list>
42 <lexeme default statement> ::= ('lexeme' 'default' '=') <adverb list>
43 <discard default statement> ::= ('discard' 'default' '=') <adverb list>
44 <priority rule> ::= lhs <op declare> priorities
45 <empty rule> ::= lhs <op declare> <adverb list>
46 <quantified rule> ::= lhs <op declare> <single symbol> quantifier <adverb list>
47 <discard rule> ::= (':discard' <op declare match>) <single symbol> <adverb list>
48 <lexeme rule> ::= (':lexeme' <op declare match>) symbol <adverb list>
49 <completion event declaration> ::= ('event') <event initialization> ('=' 'completed') <symbol name>
50 <nulled event declaration> ::= ('event') <event initialization> ('=' 'nulled') <symbol name>
51 <prediction event declaration> ::= ('event') <event initialization> ('=' 'predicted') <symbol name>
52 <current lexer statement> ::= ('current' 'lexer' 'is') <lexer name>
53
54 <inaccessible statement> ::= ('inaccessible' 'is') <inaccessible treatment> ('by' 'default')
55 <inaccessible treatment> ::= 'warn' | 'ok' | 'fatal'
56
57 <op declare> ::= <op declare bnf> | <op declare match>
58 priorities ::= alternatives+
59 separator => <op loosen> proper => 1
60 alternatives ::= alternative+
61 separator => <op equal priority> proper => 1
62 alternative ::= rhs <adverb list>
63
64 <adverb list> ::= <adverb list items>
65 <adverb list items> ::= <adverb item>*
66 <adverb item> ::=
67 action
68 | <left association> | <right association> | <group association>
69 | <separator specification> | <proper specification>
70 | <rank specification> | <null ranking specification>
71 | <priority specification> | <pause specification> | <event specification>
72 | <latm specification> | blessing | naming | <null adverb>
73
74 <null adverb> ::= ','
75 action ::= ('action' '=>') <action name>
76 <left association> ::= ('assoc' '=>' 'left')
77 <right association> ::= ('assoc' '=>' 'right')
78 <group association> ::= ('assoc' '=>' 'group')
79 <separator specification> ::= ('separator' '=>') <single symbol>
80 <proper specification> ::= ('proper' '=>') boolean
81 <rank specification> ::= ('rank' '=>') <signed integer>
82 <null ranking specification> ::= ('null-ranking' '=>') <null ranking constant>
83 <null ranking specification> ::= ('null' 'rank' '=>') <null ranking constant>
84 <null ranking constant> ::= 'low' | 'high'
85 <priority specification> ::= ('priority' '=>') <signed integer>
86 <pause specification> ::= ('pause' '=>') <before or after>
87
88 <event specification> ::= ('event' '=>') <event initialization>
89 <event initialization> ::= <event name> <event initializer>
90 <event initializer> ::= ('=') <on or off>
91 <on or off> ::= 'on' | 'off'
92 <event initializer> ::= # empty
93
94 <latm specification> ::= ('forgiving' '=>') boolean
95 <latm specification> ::= ('latm' '=>') boolean
96 <blessing> ::= ('bless' '=>') <blessing name>
97 <naming> ::= ('name' '=>') <alternative name>
98
99 <alternative name> ::= <standard name> | <single quoted name>
100 <lexer name> ::= <standard name> | <single quoted name>
101
102 <event name> ::= <standard name>
103 | <single quoted name>
104 | <reserved event name>
105 <reserved event name> ~ ':symbol'
106
107 <blessing name> ::= <standard name>
108 <blessing name> ::= <reserved blessing name>
109
110 lhs ::= <symbol name>
111 rhs ::= <rhs primary>+
112 <rhs primary> ::= <single symbol>
113 <rhs primary> ::= <single quoted string>
114 <rhs primary> ::= <parenthesized rhs primary list>
115 <parenthesized rhs primary list> ::= ('(') <rhs primary list> (')')
116 <rhs primary list> ::= <rhs primary>+
117 <single symbol> ::=
118 symbol
119 | <character class>
120 symbol ::= <symbol name>
121 <symbol name> ::= <bare name>
122 <symbol name> ::= <bracketed name>
123 <action name> ::= <Perl name>
124 <action name> ::= <reserved action name>
125 <action name> ::= <array descriptor>
126
127 :discard ~ whitespace
128 whitespace ~ [\s]+
129
130 # allow comments
131 :discard ~ <hash comment>
132 <hash comment> ~ <terminated hash comment> | <unterminated
133 final hash comment>
134 <terminated hash comment> ~ '#' <hash comment body> <vertical space char>
135 <unterminated final hash comment> ~ '#' <hash comment body>
136 <hash comment body> ~ <hash comment char>*
137 <vertical space char> ~ [\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}]
138 <hash comment char> ~ [^\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}]
139
140 <op declare bnf> ~ '::='
141 <op declare match> ~ '~'
142 <op loosen> ~ '||'
143 <op equal priority> ~ '|'
144 quantifier ::= '*' | '+'
145 <before or after> ~ 'before' | 'after'
146
147 <signed integer> ~ <integer> | <sign> <integer>
148 <sign> ~ [+-]
149 <integer> ~ [\d]+
150
151 boolean ~ [01]
152
153 <reserved action name> ~ '::' <one or more word characters>
154 <reserved blessing name> ~ '::' <one or more word characters>
155 <one or more word characters> ~ [\w]+
156 <zero or more word characters> ~ [\w]*
157
158 # Perl identifiers allow an initial digit, which makes them slightly more liberal than Perl bare names
159 # but equivalent to Perl names with sigils.
160 <Perl identifier> ~ [\w]+
161 <double colon> ~ '::'
162 <Perl name> ~ <Perl identifier>+ separator => <double colon> proper => 1
163
164 <bare name> ~ [\w]+
165 <standard name> ~ [a-zA-Z] <zero or more word characters>
166 <bracketed name> ~ '<' <bracketed name string> '>'
167 <bracketed name string> ~ [\s\w]+
168
169 <array descriptor> ~ <array descriptor left bracket> <result item descriptor list> <array descriptor right bracket>
170 <array descriptor left bracket> ~ '['
171 <array descriptor left bracket> ~ '[' whitespace
172 <array descriptor right bracket> ~ ']'
173 <array descriptor right bracket> ~ whitespace ']'
174 <result item descriptor list> ~ <result item descriptor>* separator => <result item descriptor separator>
175 <result item descriptor separator> ~ [,]
176 <result item descriptor separator> ~ [,] whitespace
177 <result item descriptor> ~ 'start' | 'length'
178 | 'g1start' | 'g1length' | 'g1len'
179 | 'name' | 'lhs' | 'symbol' | 'rule'
180 | 'value' | 'values'
181
182 # In single quoted strings and character classes
183 # no escaping or internal newlines, and disallow empty string
184
185 <single quoted string> ~ ['] <string without single quote or vertical space> ['] <character class modifiers>
186 <single quoted name> ~ ['] <string without single quote or vertical space> [']
187 <string without single quote or vertical space> ~ [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]+
188
189 <character class> ~ '[' <cc elements> ']' <character class modifiers>
190 <cc elements> ~ <cc element>+
191 <cc element> ~ <safe cc character>
192 # hex 5d is right square bracket
193 <safe cc character> ~ [^\x{5d}\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]
194 <cc element> ~ <escaped cc character>
195 <escaped cc character> ~ '\' <horizontal character>
196 <cc element> ~ <posix char class>
197 <cc element> ~ <negated posix char class>
198 <character class modifiers> ~ <character class modifier>*
199 <character class modifier> ~ ':ic'
200 <character class modifier> ~ ':i'
201
202 # [=xyz=] and [.xyz.] are parsed by Perl, but then currently cause an exception.
203 # Catching Perl exceptions is inconvenient for Marpa,
204 # so we reject them syntactically instead.
205 <posix char class> ~ '[:' <posix char class name> ':]'
206 <negated posix char class> ~ '[:^' <posix char class name> ':]'
207 <posix char class name> ~ [[:alnum:]]+
208
209 # a horizontal character is any character that is not vertical space
210 <horizontal character> ~ [^\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}]