-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.html
More file actions
312 lines (235 loc) · 6.86 KB
/
syntax.html
File metadata and controls
312 lines (235 loc) · 6.86 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<html>
<head>
<style>
body {
font-family: sans-serif;
margin-left: 2em;
}
.code, pre {
font-family: monospace;
background-color: #eee;
border: thin solid black;
padding: 0.5em 1em 0.5em 1em;
margin: 1em 1em 1em 3em;
width: 52em;
}
.code:before {
content: 'C:> ';
}
#quick_start_list li {
margin-bottom: 3em;
}
#zeromore li, #contents li {
margin-bottom: 0em;
}
p {
width: 45em;
}
li {
margin-bottom: 1em;
}
h2 {
margin-top: 3em;
padding-top: 1.5em;
border-top: thin solid black;
}
h3 {
margin-top: 3em;
}
.highlight p {
border: 3px solid black;
width: 40em;
margin: 2em 1em 2em 6em;
padding: 1em 2em 1em 2em;
font-size: 1.1em;
}
dl {
padding-bottom: 4em;
}
dt {
clear: left;
font-weight: bold;
font-family: monospace;
float: left;
width: 8em;
font-size: 1.2em;
}
dd {
width: 60em;
margin: 0 0 1.5em 0;
float: left;
}
p.clear { clear: both; }
#postfixes {
margin-left: 3em;
}
#postfixes dt {
width: 4em;
}
#postfixes dd {
width: 60em;
margin: 0 0 0.2em 0;
float: left;
}
code {
font-weight: bold;
font-size: 1.1em;
}
</style>
<title>jParser EBNF Syntax</title>
</head>
<body>
<h1>jParser EBNF Syntax</h2>
<h3><a name="syntax_grammar">Syntax of the grammar file</a></h3>
A grammar is encapsulated in the following block:
<pre>
language package.path.to.Parser {
...
}</pre>
<p>
Where <code>Parser</code> is the name of the resulting java file and <code>package.path.to</code> is the package in which the class resides. The package-part is optional for the parser, but necessary for the parser project.
</p><p>
A statement has the following layout:
</p>
<pre>
<modifiers> name = <items>.
</pre>
<p>Where:</p>
<ul><li>
modifiers are optional keywords which give instructions to the parser generator as to how to handle this statement.
</li><li>
items is a definition of the text pattern which matches some input.
</li></ul>
<div class='highlight'>
<p>
A brief explanation of a parser is a program which associates labels to parts of a text which corresponds to given patterns.
</p>
</div>
<p>Comments are preceded by <code>'#'</code> and go till the end of the line.<p>
<h3>Items</h3>
<dl>
<dt>a b</dt>
<dd>Concatenation. Item a must follow item b.</dd>
<dt>a | b</dt>
<dd> Alternative. Either a or b will match the input.<br>
Please note that the |-command will match with the nearest item. This
is different from most languages. For example:
<pre>a b c | d e | f</pre>
Will match as:
<pre>a b ( c | d ) ( e | f )</pre>
You will need to brace explicitly to indicate your intention. eg:
<pre>( a b c ) | ( d e ) | ( f )</pre>
</dd>
<dt>[abc]</dt>
<dd>Character class. The parser will match any character between these
braces to the next incoming character.<br> The given example will
match charactes 'a' 'b' and 'c', and nothing else.
<p>
Special characters are denoted by a preceding backslash, eg:
<p>
<pre>\r \n \t - respectively carriage return, line feed, tab</pre>
<p>
A character class can include ranges, eg: <code>[a-zA-Z0-9]</code>.
Special class <code>[\all]</code> matches everything.
<code>[\all]</code> can be expanded with an exclusion set, for example:
</p>
<pre>[\all~\r\n] - match all characters EXCEPT carriage returns and line feeds.</pre>
</dd>
<dt>"abc"</dt>
<dd>String. This item will be matched verbatim with the input. A match will be
stored in the parse output.
</dd>
<dt>'abc'</dt>
<dd>As previous, but the match will NOT be stored in the parse output.
</dd>
<dt>(...)</dt>
<dd>Group items. All items between the braces are grouped together. eg:
<pre>( a b c )</pre>
</dd>
<dt>{...}</dt>
<dd>Group items within and repeat zero or more items.
<p>Thus <code>{ [a] }</code> will match
(Assuming whitespace parsing is on):
</p>
<ul id="zeromore"><li>
<nothing>
</li><li>
a
</li><li>
a a
</li><li>
aa a a
</li><li>
aaaaaaa aaaaa aaaaa aaaa
</li><li>
etc.
</li></ul>
<dt>!a</dt>
<dd>Not-operator. Next item in input must NOT correspond with item a.
This is a test only, the input will be retained for the next item.
The not-operator can not be combined with the postfix-operators as
described below.
</dd>
</dl>
<p class='clear'>
In addition, the following postfixes can appear behind (almost) every statement:
<p>
<dl id='postfixes'>
<dt>?</dt>
<dd>Repeat previous item zero or one times</dd>
<dt>*</dt>
<dd>Repeat previous item zero or more times</dd>
<dt>+</dt>
<dd>Repeat previous item one or more times</dd>
</dl>
<p class='clear'></p>
<h4>Modifiers</h4>
<dl>
<dt>noWS, skipWS</dt>
<dd>Enable/disable whitespace handling.
<p>Whitespace is defined by statement with label 'WS'. If you do not
include this, the following default definition will be used:</p>
<pre>WS = [ \r\t\n]+.</pre>
<p>These modifiers can appear between statements. After a noWS, all statements
are assumed to be parsed without whitespace in between. After a skipWS,
whitespace is assumed to be between every item.</p>
<p>These modifiers can also appear within a statement. The working is the same;
from the point noWS appears, no more whitespace is parsed until skipWS
is encountered. These settings are for within the statement only; they
are reset when the statement has been handled.</p>
</dd>
</dl>
<p class='clear'></p>
<h4>Statement prefixes</h4>
<p>Statement prefixes are used to tell the parser how to handle a given parse
result in the output. They are optional and not necessary for a succesful
parse.</p>
<p>The following are used as prefixes for statements:</p>
<dl>
<dt>entry</dt>
<dd>Okay, so this prefix IS necessary. Indicates which statement will be
handled as first statement upon parsing. There must be exactly one
entry statement defined in a grammar.
</dd>
<dt>ignore</dt>
<dd>Parse, but do not add this statement to the parsing output. The result
of this statement is ignored.
</dd>
<dt>token</dt>
<dd>The result of a statement usually contains structure. The statements
called by this statement are retained as separate child-entities.<br>
The prefix <code>token</code> reduces this structure to a flat string value. The
contents are retained, but the child-labels are discarded.
</dd>
<dt>skip</dt>
<dd>Parse normally and retain structure. Remove current parse result,
but retain all children. Thus, the label of the current statement is
discarded, but the labels of the child-statements are retained in the
output.
</dd>
</dl>
<p class='clear'></p>
<h3>Notes</h3>
<div class='highlight'><p>Please avoid java keywords as names for statements. </p></div>
</body>
</html>