-
Notifications
You must be signed in to change notification settings - Fork 647
/
sse.jj
266 lines (231 loc) · 6.43 KB
/
sse.jj
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
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
options
{
JAVA_UNICODE_ESCAPE = false ;
UNICODE_INPUT = true ;
STATIC = false ;
// DEBUG_PARSER = true ;
// DEBUG_TOKEN_MANAGER = true ;
}
PARSER_BEGIN(SSE_ParserCore)
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jena.sparql.sse.lang.parser ;
import org.apache.jena.sparql.sse.lang.ParserSSEBase ;
import static org.apache.jena.riot.lang.extra.LangParserLib.*;
public class SSE_ParserCore extends ParserSSEBase
{
}
PARSER_END(SSE_ParserCore)
// Now has explicit WS control in the grammar.
// Policy - eat trailing WS
// ---- Entry points : check for EOF.
void parse() : { }
{
[ <BOM> ]
{ parseStart() ; }
(<WS>)*
TermOrList()
<EOF>
{ parseFinish() ; }
}
// Parse one atom - non-compound RDF term.
void atom() : { }
{
{ parseStart() ; }
TermAtom()
<EOF>
{ parseFinish() ; }
}
// ----
void TermOrList() : { }
{
( TermAtom() (<WS>)* | List() )
}
void List() : { Token t ; }
{
// The OP token must exclude these
( t = <LPAREN>
(<WS>)*
{ listStart(t.beginLine, t.beginColumn) ; }
BareList()
t = <RPAREN>
(<WS>)*
{ listFinish(t.beginLine, t.beginColumn) ; }
| t = <LBRACKET>
(<WS>)*
{ listStart(t.beginLine, t.beginColumn) ; }
BareList()
t = <RBRACKET>
(<WS>)*
{ listFinish(t.beginLine, t.beginColumn) ; } )
}
void BareList() : { }
{
(
TermOrList()
// White space swallowed
)*
}
void TermAtom() : { }
{
Symbol() | RDFTermAtom()
}
// Atomic RDF terms URI, literal, bnode, variable.
// Not quoted triple. unless <<>> support is active.
void RDFTermAtom() : { }
{
IRIref()
|
PrefixedName()
|
Var()
|
Literal()
|
BlankNode()
|
TripleTerm()
}
void Symbol() : { Token t ; }
{
t = <SYMBOL>
{ emitSymbol(t.beginLine, t.beginColumn, t.image) ; }
}
void IRIref() : { Token t ; String s ; }
{
t = <IRIref>
{
s = t.image ;
s = stripQuotes(s) ;
s = unescapeStr(s, t.beginLine, t.beginColumn) ;
emitIRI(t.beginLine, t.beginColumn, s) ; }
}
void PrefixedName() : { Token t ; }
{
t = <PNAME>
{ emitPName(t.beginLine, t.beginColumn, t.image) ; }
}
void Var() : { Token t ; }
{
// VAR_NAMED: "?" and any legal SPARQL variable.
// VAR_NAMED2: "?." and non-legal SPARQL variable (usually allocated)
// VAR_ANON: "??" : Anon variables.
// Includes "?" as a variable which allocated one from ?0, ?1, ?2
// Legal SPARQL syntax.
// Includes "??" as a variable for anon non-distinguished variables.
// Includes non-distinguished variables as ??0
// Includes internal allocated variables as ?.0
// ( t = <VAR_NAMED> | t = <VAR_NAMED2> | t = <VAR_ANON> )
( t = <VAR_NAMED> | t = <VAR_OTHER> )
{ emitVar(t.beginLine, t.beginColumn, stripChars(t.image, 1)) ; }
}
void Literal() : { }
{
( RDFLiteral()
| NumericLiteral()
// | BooleanLiteral() // Do as a symbol.
)
}
void BlankNode() : { Token t ; }
{
t = <BLANK_NODE_LABEL>
{ emitBNode(t.beginLine, t.beginColumn, stripChars(t.image, 2)) ; }
//|
// t = <LBRACKET> <RBRACKET> { return emitBNode(t.beginLine, t.beginColumn) ; }
// t = <ANON> { return emitBNode(t.beginLine, t.beginColumn) ; }
}
void TripleTerm() : { Token t1 = null ; Token t2 = null ; }
{
t1 = <LT2>
(<WS>)*
{ tripleTermStart(t1.beginLine, t1.beginColumn); }
RDFTermAtom()
(<WS>)*
RDFTermAtom()
(<WS>)*
RDFTermAtom()
(<WS>)*
t2 = <GT2>
{ tripleTermFinish(t2.beginLine, t2.beginColumn); }
}
void RDFLiteral() : { Token t = null ; int currLine ; int currColumn ;
String lex ; String lang = null ;
String dt_iri = null ; String dt_pn = null ; }
{
( t = <STRING_LITERAL1> { lex = stripQuotes(t.image) ; }
| t = <STRING_LITERAL2> { lex = stripQuotes(t.image) ; }
| t = <STRING_LITERAL_LONG1> { lex = stripQuotes3(t.image) ; }
| t = <STRING_LITERAL_LONG2> { lex = stripQuotes3(t.image) ; }
)
{ currLine = t.beginLine ; currColumn = t.beginColumn ;
lex = unescapeStr(lex, currLine, currColumn) ;
}
// Optional lang tag and datatype.
(
t = <LANGTAG> { lang = stripChars(t.image, 1) ; }
|
<DATATYPE>
( t = <IRIref> { dt_iri = stripQuotes(t.image) ; }
| t = <PNAME> { dt_pn = t.image ; }
)
)?
{ emitLiteral(currLine, currColumn, lex, lang, dt_iri, dt_pn) ; }
}
void NumericLiteral() : { Token t ; }
{
t = <INTEGER>
{ emitLiteralInteger(t.beginLine, t.beginColumn, t.image) ; }
| t = <DECIMAL>
{ emitLiteralDecimal(t.beginLine, t.beginColumn, t.image) ; }
| t = <DOUBLE>
{ emitLiteralDouble(t.beginLine, t.beginColumn, t.image) ; }
}
// Symbol!
// Node BooleanLiteral() : {}
// {
// <TRUE> { return XSD_TRUE ; }
// |
// <FALSE> { return XSD_FALSE ; }
// }
// No whitespace skipping.
#undef SKIP
#include "tokens.inc"
/*
# Local Variables:
# tab-width: 4
# indent-tabs-mode: nil
# comment-default-style: "//"
# End:
*/