| 1 |
options { |
| 2 |
STATIC = false; |
| 3 |
UNICODE_INPUT = true; |
| 4 |
JAVA_UNICODE_ESCAPE = true; |
| 5 |
} |
| 6 |
|
| 7 |
PARSER_BEGIN(CompactSyntax) |
| 8 |
|
| 9 |
package com.thaiopensource.relaxng.parse.compact; |
| 10 |
|
| 11 |
import com.thaiopensource.relaxng.parse.Annotations; |
| 12 |
import com.thaiopensource.relaxng.parse.BuildException; |
| 13 |
import com.thaiopensource.relaxng.parse.CommentList; |
| 14 |
import com.thaiopensource.relaxng.parse.Context; |
| 15 |
import com.thaiopensource.relaxng.parse.DataPatternBuilder; |
| 16 |
import com.thaiopensource.relaxng.parse.Div; |
| 17 |
import com.thaiopensource.relaxng.parse.ElementAnnotationBuilder; |
| 18 |
import com.thaiopensource.relaxng.parse.Grammar; |
| 19 |
import com.thaiopensource.relaxng.parse.GrammarSection; |
| 20 |
import com.thaiopensource.relaxng.parse.IllegalSchemaException; |
| 21 |
import com.thaiopensource.relaxng.parse.Include; |
| 22 |
import com.thaiopensource.relaxng.parse.IncludedGrammar; |
| 23 |
import com.thaiopensource.relaxng.parse.SchemaBuilder; |
| 24 |
import com.thaiopensource.relaxng.parse.Scope; |
| 25 |
|
| 26 |
import com.thaiopensource.util.Ref; |
| 27 |
import com.thaiopensource.xml.util.WellKnownNamespaces; |
| 28 |
|
| 29 |
import com.thaiopensource.util.Localizer; |
| 30 |
|
| 31 |
import org.xml.sax.ErrorHandler; |
| 32 |
import org.xml.sax.SAXException; |
| 33 |
import org.xml.sax.SAXParseException; |
| 34 |
import org.xml.sax.helpers.LocatorImpl; |
| 35 |
|
| 36 |
import java.util.ArrayList; |
| 37 |
import java.util.Collections; |
| 38 |
import java.util.HashMap; |
| 39 |
import java.util.HashSet; |
| 40 |
import java.util.List; |
| 41 |
import java.util.Map; |
| 42 |
import java.util.Set; |
| 43 |
import java.io.Reader; |
| 44 |
|
| 45 |
public class CompactSyntax<Pattern, NameClass, Location, ElementAnnotation, |
| 46 |
CommentListImpl extends CommentList<Location>, |
| 47 |
AnnotationsImpl extends Annotations<Location, ElementAnnotation, CommentListImpl>> |
| 48 |
implements Context { |
| 49 |
private static final int IN_ELEMENT = 0; |
| 50 |
private static final int IN_ATTRIBUTE = 1; |
| 51 |
private static final int IN_ANY_NAME = 2; |
| 52 |
private static final int IN_NS_NAME = 4; |
| 53 |
|
| 54 |
private String defaultNamespace = SchemaBuilder.INHERIT_NS; |
| 55 |
private String compatibilityPrefix = null; |
| 56 |
private SchemaBuilder<Pattern, NameClass, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> sb; |
| 57 |
private String sourceUri; |
| 58 |
private ErrorHandler eh; |
| 59 |
private final Map<String, String> namespaceMap = new HashMap<String, String>(); |
| 60 |
private final Map<String, String> datatypesMap = new HashMap<String, String>(); |
| 61 |
private boolean hadError = false; |
| 62 |
private static final Localizer localizer = new Localizer(CompactSyntax.class); |
| 63 |
private final Set<String> attributeNames = new HashSet<String>(); |
| 64 |
private boolean annotationsIncludeElements = false; |
| 65 |
|
| 66 |
final class LocatedString { |
| 67 |
private final String str; |
| 68 |
private final Token tok; |
| 69 |
|
| 70 |
LocatedString(String str, Token tok) { |
| 71 |
this.str = str; |
| 72 |
this.tok = tok; |
| 73 |
} |
| 74 |
|
| 75 |
String getString() { |
| 76 |
return str; |
| 77 |
} |
| 78 |
|
| 79 |
Location getLocation() { |
| 80 |
return makeLocation(tok); |
| 81 |
} |
| 82 |
|
| 83 |
Token getToken() { |
| 84 |
return tok; |
| 85 |
} |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
public CompactSyntax(Reader r, String sourceUri, SchemaBuilder<Pattern, NameClass, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> sb, ErrorHandler eh) { |
| 90 |
this(r); |
| 91 |
this.sourceUri = sourceUri; |
| 92 |
this.sb = sb; |
| 93 |
this.eh = eh; |
| 94 |
// this causes the root pattern to have non-null annotations |
| 95 |
// which is useful because it gives a context to trang |
| 96 |
this.topLevelComments = sb.makeCommentList(); |
| 97 |
} |
| 98 |
|
| 99 |
Pattern parse(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope) throws IllegalSchemaException { |
| 100 |
try { |
| 101 |
Pattern p = Input(scope); |
| 102 |
if (!hadError) |
| 103 |
return p; |
| 104 |
} |
| 105 |
catch (ParseException e) { |
| 106 |
error("syntax_error", e.currentToken.next); |
| 107 |
} |
| 108 |
catch (EscapeSyntaxException e) { |
| 109 |
reportEscapeSyntaxException(e); |
| 110 |
} |
| 111 |
throw new IllegalSchemaException(); |
| 112 |
} |
| 113 |
|
| 114 |
Pattern parseInclude(IncludedGrammar<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> g) throws IllegalSchemaException { |
| 115 |
try { |
| 116 |
Pattern p = IncludedGrammar(g); |
| 117 |
if (!hadError) |
| 118 |
return p; |
| 119 |
} |
| 120 |
catch (ParseException e) { |
| 121 |
error("syntax_error", e.currentToken.next); |
| 122 |
} |
| 123 |
catch (EscapeSyntaxException e) { |
| 124 |
reportEscapeSyntaxException(e); |
| 125 |
} |
| 126 |
throw new IllegalSchemaException(); |
| 127 |
} |
| 128 |
|
| 129 |
private void checkNsName(int context, LocatedString ns) { |
| 130 |
if ((context & IN_NS_NAME) != 0) |
| 131 |
error("ns_name_except_contains_ns_name", ns.getToken()); |
| 132 |
} |
| 133 |
|
| 134 |
private void checkAnyName(int context, Token t) { |
| 135 |
if ((context & IN_NS_NAME) != 0) |
| 136 |
error("ns_name_except_contains_any_name", t); |
| 137 |
if ((context & IN_ANY_NAME) != 0) |
| 138 |
error("any_name_except_contains_any_name", t); |
| 139 |
} |
| 140 |
|
| 141 |
private void error(String key, Token tok) { |
| 142 |
doError(localizer.message(key), tok); |
| 143 |
} |
| 144 |
|
| 145 |
private void error(String key, String arg, Token tok) { |
| 146 |
doError(localizer.message(key, arg), tok); |
| 147 |
} |
| 148 |
|
| 149 |
private void error(String key, String arg1, String arg2, Token tok) { |
| 150 |
doError(localizer.message(key, arg1, arg2), tok); |
| 151 |
} |
| 152 |
|
| 153 |
private void doError(String message, Token tok) { |
| 154 |
hadError = true; |
| 155 |
if (eh != null) { |
| 156 |
LocatorImpl loc = new LocatorImpl(); |
| 157 |
loc.setLineNumber(tok.beginLine); |
| 158 |
loc.setColumnNumber(tok.beginColumn); |
| 159 |
loc.setSystemId(sourceUri); |
| 160 |
try { |
| 161 |
eh.error(new SAXParseException(message, loc)); |
| 162 |
} |
| 163 |
catch (SAXException se) { |
| 164 |
throw new BuildException(se); |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
private void reportEscapeSyntaxException(EscapeSyntaxException e) { |
| 170 |
if (eh != null) { |
| 171 |
LocatorImpl loc = new LocatorImpl(); |
| 172 |
loc.setLineNumber(e.getLineNumber()); |
| 173 |
loc.setColumnNumber(e.getColumnNumber()); |
| 174 |
loc.setSystemId(sourceUri); |
| 175 |
try { |
| 176 |
eh.error(new SAXParseException(localizer.message(e.getKey()), loc)); |
| 177 |
} |
| 178 |
catch (SAXException se) { |
| 179 |
throw new BuildException(se); |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
private static String unquote(String s) { |
| 185 |
if (s.length() >= 6 && s.charAt(0) == s.charAt(1)) { |
| 186 |
s = s.replace('\u0000', '\n'); |
| 187 |
return s.substring(3, s.length() - 3); |
| 188 |
} |
| 189 |
else |
| 190 |
return s.substring(1, s.length() - 1); |
| 191 |
} |
| 192 |
|
| 193 |
Location makeLocation(Token t) { |
| 194 |
return sb.makeLocation(sourceUri, t.beginLine, t.beginColumn); |
| 195 |
} |
| 196 |
|
| 197 |
String getCompatibilityPrefix() { |
| 198 |
if (compatibilityPrefix == null) { |
| 199 |
compatibilityPrefix = "a"; |
| 200 |
while (namespaceMap.get(compatibilityPrefix) != null) |
| 201 |
compatibilityPrefix = compatibilityPrefix + "a"; |
| 202 |
} |
| 203 |
return compatibilityPrefix; |
| 204 |
} |
| 205 |
|
| 206 |
public String resolveNamespacePrefix(String prefix) { |
| 207 |
String result = namespaceMap.get(prefix); |
| 208 |
if (result == null || result.length() == 0) |
| 209 |
return null; |
| 210 |
return result; |
| 211 |
} |
| 212 |
|
| 213 |
public Set<String> prefixes() { |
| 214 |
return namespaceMap.keySet(); |
| 215 |
} |
| 216 |
|
| 217 |
public String getBaseUri() { |
| 218 |
return sourceUri; |
| 219 |
} |
| 220 |
|
| 221 |
public boolean isUnparsedEntity(String entityName) { |
| 222 |
return false; |
| 223 |
} |
| 224 |
|
| 225 |
public boolean isNotation(String notationName) { |
| 226 |
return false; |
| 227 |
} |
| 228 |
|
| 229 |
public Context copy() { |
| 230 |
return this; |
| 231 |
} |
| 232 |
|
| 233 |
private Context getContext() { |
| 234 |
return this; |
| 235 |
} |
| 236 |
|
| 237 |
private CommentListImpl getComments() { |
| 238 |
return getComments(getTopLevelComments()); |
| 239 |
} |
| 240 |
|
| 241 |
private CommentListImpl topLevelComments; |
| 242 |
|
| 243 |
private CommentListImpl getTopLevelComments() { |
| 244 |
CommentListImpl tem = topLevelComments; |
| 245 |
topLevelComments = null; |
| 246 |
return tem; |
| 247 |
} |
| 248 |
|
| 249 |
private void noteTopLevelComments() { |
| 250 |
topLevelComments = getComments(topLevelComments); |
| 251 |
} |
| 252 |
|
| 253 |
private void topLevelComments(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section) { |
| 254 |
section.topLevelComment(getComments(null)); |
| 255 |
} |
| 256 |
|
| 257 |
private Token lastCommentSourceToken = null; |
| 258 |
|
| 259 |
private CommentListImpl getComments(CommentListImpl comments) { |
| 260 |
Token nextToken = getToken(1); |
| 261 |
if (lastCommentSourceToken != nextToken) { |
| 262 |
if (lastCommentSourceToken == null) |
| 263 |
lastCommentSourceToken = token; |
| 264 |
do { |
| 265 |
lastCommentSourceToken = lastCommentSourceToken.next; |
| 266 |
Token t = lastCommentSourceToken.specialToken; |
| 267 |
if (t != null) { |
| 268 |
while (t.specialToken != null) |
| 269 |
t = t.specialToken; |
| 270 |
if (comments == null) |
| 271 |
comments = sb.makeCommentList(); |
| 272 |
for (; t != null; t = t.next) { |
| 273 |
String s = mungeComment(t.image); |
| 274 |
Location loc = makeLocation(t); |
| 275 |
if (t.next != null |
| 276 |
&& t.next.kind == CompactSyntaxConstants.SINGLE_LINE_COMMENT_CONTINUE) { |
| 277 |
StringBuffer buf = new StringBuffer(s); |
| 278 |
do { |
| 279 |
t = t.next; |
| 280 |
buf.append('\n'); |
| 281 |
buf.append(mungeComment(t.image)); |
| 282 |
} while (t.next != null |
| 283 |
&& t.next.kind == CompactSyntaxConstants.SINGLE_LINE_COMMENT_CONTINUE); |
| 284 |
s = buf.toString(); |
| 285 |
} |
| 286 |
comments.addComment(s, loc); |
| 287 |
} |
| 288 |
} |
| 289 |
} while (lastCommentSourceToken != nextToken); |
| 290 |
} |
| 291 |
return comments; |
| 292 |
} |
| 293 |
|
| 294 |
private Pattern afterPatternComments(Pattern p) { |
| 295 |
CommentListImpl comments = getComments(null); |
| 296 |
if (comments == null) |
| 297 |
return p; |
| 298 |
return sb.commentAfterPattern(p, comments); |
| 299 |
} |
| 300 |
|
| 301 |
private NameClass afterNameClassComments(NameClass nc) { |
| 302 |
CommentListImpl comments = getComments(null); |
| 303 |
if (comments == null) |
| 304 |
return nc; |
| 305 |
return sb.commentAfterNameClass(nc, comments); |
| 306 |
} |
| 307 |
|
| 308 |
private static String mungeComment(String image) { |
| 309 |
int i = image.indexOf('#') + 1; |
| 310 |
while (i < image.length() && image.charAt(i) == '#') |
| 311 |
i++; |
| 312 |
if (i < image.length() && image.charAt(i) == ' ') |
| 313 |
i++; |
| 314 |
return image.substring(i); |
| 315 |
} |
| 316 |
|
| 317 |
private AnnotationsImpl getCommentsAsAnnotations() { |
| 318 |
CommentListImpl comments = getComments(); |
| 319 |
if (comments == null) |
| 320 |
return null; |
| 321 |
return sb.makeAnnotations(comments, getContext()); |
| 322 |
} |
| 323 |
|
| 324 |
private AnnotationsImpl addCommentsToChildAnnotations(AnnotationsImpl a) { |
| 325 |
CommentListImpl comments = getComments(); |
| 326 |
if (comments == null) |
| 327 |
return a; |
| 328 |
if (a == null) |
| 329 |
a = sb.makeAnnotations(null, getContext()); |
| 330 |
a.addComment(comments); |
| 331 |
return a; |
| 332 |
} |
| 333 |
|
| 334 |
private AnnotationsImpl addCommentsToLeadingAnnotations(AnnotationsImpl a) { |
| 335 |
CommentListImpl comments = getComments(); |
| 336 |
if (comments == null) |
| 337 |
return a; |
| 338 |
if (a == null) |
| 339 |
return sb.makeAnnotations(comments, getContext()); |
| 340 |
a.addLeadingComment(comments); |
| 341 |
return a; |
| 342 |
} |
| 343 |
|
| 344 |
private AnnotationsImpl getTopLevelCommentsAsAnnotations() { |
| 345 |
CommentListImpl comments = getTopLevelComments(); |
| 346 |
if (comments == null) |
| 347 |
return null; |
| 348 |
return sb.makeAnnotations(comments, getContext()); |
| 349 |
} |
| 350 |
|
| 351 |
private void clearAttributeList() { |
| 352 |
attributeNames.clear(); |
| 353 |
} |
| 354 |
|
| 355 |
private void addAttribute(Annotations<Location, ElementAnnotation, CommentListImpl> a, String ns, String localName, String prefix, String value, Token tok) { |
| 356 |
String key = ns + "#" + localName; |
| 357 |
if (attributeNames.contains(key)) |
| 358 |
error("duplicate_attribute", ns, localName, tok); |
| 359 |
else { |
| 360 |
attributeNames.add(key); |
| 361 |
a.addAttribute(ns, localName, prefix, value, makeLocation(tok)); |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
private void checkExcept(Token[] except) { |
| 366 |
if (except[0] != null) |
| 367 |
error("except_missing_parentheses", except[0]); |
| 368 |
} |
| 369 |
|
| 370 |
private String lookupPrefix(String prefix, Token t) { |
| 371 |
String ns = namespaceMap.get(prefix); |
| 372 |
if (ns == null) { |
| 373 |
error("undeclared_prefix", prefix, t); |
| 374 |
return "#error"; |
| 375 |
} |
| 376 |
return ns; |
| 377 |
} |
| 378 |
private String lookupDatatype(String prefix, Token t) { |
| 379 |
String ns = datatypesMap.get(prefix); |
| 380 |
if (ns == null) { |
| 381 |
error("undeclared_prefix", prefix, t); |
| 382 |
return ""; // XXX |
| 383 |
} |
| 384 |
return ns; |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
PARSER_END(CompactSyntax) |
| 389 |
|
| 390 |
Pattern Input(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope) : |
| 391 |
{ |
| 392 |
Pattern p; |
| 393 |
} |
| 394 |
{ |
| 395 |
Preamble() |
| 396 |
(LOOKAHEAD(TopLevelLookahead()) p = TopLevelGrammar(scope) |
| 397 |
| p = Expr(true, scope, null, null) { p = afterPatternComments(p); } <EOF>) |
| 398 |
{ return p; } |
| 399 |
} |
| 400 |
|
| 401 |
void TopLevelLookahead() : |
| 402 |
{} |
| 403 |
{ |
| 404 |
<PREFIXED_NAME> "[" |
| 405 |
| Identifier() ("[" | "=" | "&=" | "|=") |
| 406 |
| LookaheadGrammarKeyword() |
| 407 |
| LookaheadBody() LookaheadAfterAnnotations() |
| 408 |
| LookaheadDocumentation() (LookaheadBody())? LookaheadAfterAnnotations() |
| 409 |
} |
| 410 |
|
| 411 |
void LookaheadAfterAnnotations() : |
| 412 |
{} |
| 413 |
{ |
| 414 |
Identifier() ("=" | "&=" | "|=") |
| 415 |
| LookaheadGrammarKeyword() |
| 416 |
} |
| 417 |
|
| 418 |
void LookaheadGrammarKeyword() : |
| 419 |
{} |
| 420 |
{ |
| 421 |
"start" | "div" | "include" |
| 422 |
} |
| 423 |
|
| 424 |
void LookaheadDocumentation() : |
| 425 |
{} |
| 426 |
{ |
| 427 |
((<DOCUMENTATION> | <DOCUMENTATION_AFTER_SINGLE_LINE_COMMENT>) (<DOCUMENTATION_CONTINUE>)*)+ |
| 428 |
} |
| 429 |
|
| 430 |
void LookaheadBody() : |
| 431 |
{} |
| 432 |
{ |
| 433 |
"[" |
| 434 |
(<PREFIXED_NAME> | UnprefixedName() | "=" | <LITERAL> | "~" | LookaheadBody() )* |
| 435 |
"]" |
| 436 |
} |
| 437 |
|
| 438 |
Pattern IncludedGrammar(IncludedGrammar<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> g) : |
| 439 |
{ |
| 440 |
AnnotationsImpl a; |
| 441 |
Pattern p; |
| 442 |
} |
| 443 |
{ |
| 444 |
Preamble() |
| 445 |
(LOOKAHEAD(TopLevelLookahead()) a = GrammarBody(g, g, getTopLevelCommentsAsAnnotations()) |
| 446 |
| a = AnnotationsImpl() "grammar" "{" a = GrammarBody(g, g, a) { topLevelComments(g); } "}") |
| 447 |
{ p = afterPatternComments(g.endIncludedGrammar(sb.makeLocation(sourceUri, 1, 1), a)); } |
| 448 |
<EOF> |
| 449 |
{ return p; } |
| 450 |
} |
| 451 |
|
| 452 |
Pattern TopLevelGrammar(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope) : |
| 453 |
{ |
| 454 |
AnnotationsImpl a = getTopLevelCommentsAsAnnotations(); |
| 455 |
Grammar<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> g; |
| 456 |
Pattern p; |
| 457 |
} |
| 458 |
{ |
| 459 |
{ g = sb.makeGrammar(scope); } |
| 460 |
a = GrammarBody(g, g, a) |
| 461 |
{ p = afterPatternComments(g.endGrammar(sb.makeLocation(sourceUri, 1, 1), a)); } |
| 462 |
<EOF> |
| 463 |
{ return p; } |
| 464 |
} |
| 465 |
|
| 466 |
void Preamble() : |
| 467 |
{} |
| 468 |
{ |
| 469 |
(NamespaceDecl() | DatatypesDecl())* |
| 470 |
{ |
| 471 |
namespaceMap.put("xml", WellKnownNamespaces.XML); |
| 472 |
if (datatypesMap.get("xsd") == null) |
| 473 |
datatypesMap.put("xsd", WellKnownNamespaces.XML_SCHEMA_DATATYPES); |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
void NamespaceDecl() : |
| 478 |
{ |
| 479 |
LocatedString prefix = null; |
| 480 |
boolean isDefault = false; |
| 481 |
String namespaceName; |
| 482 |
} |
| 483 |
{ |
| 484 |
{ noteTopLevelComments(); } |
| 485 |
(("namespace" prefix = UnprefixedName()) |
| 486 |
| ("default" { isDefault = true; } |
| 487 |
"namespace" (prefix = UnprefixedName())?)) |
| 488 |
"=" |
| 489 |
namespaceName = NamespaceName() |
| 490 |
{ |
| 491 |
if (isDefault) |
| 492 |
defaultNamespace = namespaceName; |
| 493 |
if (prefix != null) { |
| 494 |
if (prefix.getString().equals("xmlns")) |
| 495 |
error("xmlns_prefix", prefix.getToken()); |
| 496 |
else if (prefix.getString().equals("xml")) { |
| 497 |
if (!namespaceName.equals(WellKnownNamespaces.XML)) |
| 498 |
error("xml_prefix_bad_uri", prefix.getToken()); |
| 499 |
} |
| 500 |
else if (namespaceName.equals(WellKnownNamespaces.XML)) |
| 501 |
error("xml_uri_bad_prefix", prefix.getToken()); |
| 502 |
else { |
| 503 |
if (namespaceName.equals(WellKnownNamespaces.RELAX_NG_COMPATIBILITY_ANNOTATIONS)) |
| 504 |
compatibilityPrefix = prefix.getString(); |
| 505 |
namespaceMap.put(prefix.getString(), namespaceName); |
| 506 |
} |
| 507 |
} |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
String NamespaceName() : |
| 512 |
{ |
| 513 |
String r; |
| 514 |
} |
| 515 |
{ |
| 516 |
(r = Literal() | "inherit" { r = SchemaBuilder.INHERIT_NS; }) |
| 517 |
{ return r; } |
| 518 |
} |
| 519 |
|
| 520 |
void DatatypesDecl() : |
| 521 |
{ |
| 522 |
LocatedString prefix; |
| 523 |
String uri; |
| 524 |
} |
| 525 |
{ |
| 526 |
{ noteTopLevelComments(); } |
| 527 |
"datatypes" prefix = UnprefixedName() "=" uri = Literal() |
| 528 |
{ |
| 529 |
datatypesMap.put(prefix.getString(), uri); |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
Pattern AnnotatedPrimaryExpr(boolean topLevel, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, Token[] except) : |
| 534 |
{ |
| 535 |
AnnotationsImpl a; |
| 536 |
Pattern p; |
| 537 |
ElementAnnotation e; |
| 538 |
Token t; |
| 539 |
} |
| 540 |
{ |
| 541 |
a = AnnotationsImpl() |
| 542 |
p = PrimaryExpr(topLevel, scope, a, except) |
| 543 |
( t = <FANNOTATE> e = AnnotationElement(false) { |
| 544 |
if (topLevel) |
| 545 |
error("top_level_follow_annotation", t); |
| 546 |
else |
| 547 |
p = sb.annotateAfterPattern(p, e); |
| 548 |
})* |
| 549 |
{ return p; } |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
Pattern PrimaryExpr(boolean topLevel, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a, Token[] except) : |
| 554 |
{ |
| 555 |
Pattern p; |
| 556 |
} |
| 557 |
{ |
| 558 |
(p = ElementExpr(scope, a) |
| 559 |
| p = AttributeExpr(scope, a) |
| 560 |
| p = GrammarExpr(scope, a) |
| 561 |
| p = ExternalRefExpr(scope, a) |
| 562 |
| p = ListExpr(scope, a) |
| 563 |
| p = MixedExpr(scope, a) |
| 564 |
| p = ParenExpr(topLevel, scope, a) |
| 565 |
| p = IdentifierExpr(scope, a) |
| 566 |
| p = ParentExpr(scope, a) |
| 567 |
| p = DataExpr(topLevel, scope, a, except) |
| 568 |
| p = ValueExpr(topLevel, a) |
| 569 |
| p = TextExpr(a) |
| 570 |
| p = EmptyExpr(a) |
| 571 |
| p = NotAllowedExpr(a)) |
| 572 |
{ return p; } |
| 573 |
} |
| 574 |
|
| 575 |
Pattern EmptyExpr(AnnotationsImpl a) : |
| 576 |
{ |
| 577 |
Token t; |
| 578 |
} |
| 579 |
{ |
| 580 |
t = "empty" |
| 581 |
{ return sb.makeEmpty(makeLocation(t), a); } |
| 582 |
} |
| 583 |
|
| 584 |
Pattern TextExpr(AnnotationsImpl a) : |
| 585 |
{ |
| 586 |
Token t; |
| 587 |
} |
| 588 |
{ |
| 589 |
t = "text" |
| 590 |
{ return sb.makeText(makeLocation(t), a); } |
| 591 |
} |
| 592 |
|
| 593 |
Pattern NotAllowedExpr(AnnotationsImpl a) : |
| 594 |
{ |
| 595 |
Token t; |
| 596 |
} |
| 597 |
{ |
| 598 |
t = "notAllowed" |
| 599 |
{ return sb.makeNotAllowed(makeLocation(t), a); } |
| 600 |
} |
| 601 |
|
| 602 |
Pattern Expr(boolean topLevel, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, Token t, AnnotationsImpl a) : |
| 603 |
{ |
| 604 |
Pattern p; |
| 605 |
List<Pattern> patterns = new ArrayList<Pattern>(); |
| 606 |
boolean[] hadOccur = new boolean[1]; |
| 607 |
Token[] except = new Token[1]; |
| 608 |
} |
| 609 |
{ |
| 610 |
p = UnaryExpr(topLevel, scope, hadOccur, except) |
| 611 |
{ patterns.add(p); } |
| 612 |
( |
| 613 |
{ checkExcept(except); } |
| 614 |
(t = "|" p = UnaryExpr(topLevel, scope, null, except) |
| 615 |
{ patterns.add(p); checkExcept(except); } )+ |
| 616 |
{ p = sb.makeChoice(patterns, makeLocation(t), a); } |
| 617 |
| (t = "&" p = UnaryExpr(topLevel, scope, null, except) |
| 618 |
{ patterns.add(p); checkExcept(except); } )+ |
| 619 |
{ p = sb.makeInterleave(patterns, makeLocation(t), a); } |
| 620 |
| (t = "," p = UnaryExpr(topLevel, scope, null, except) |
| 621 |
{ patterns.add(p); checkExcept(except); } )+ |
| 622 |
{ p = sb.makeGroup(patterns, makeLocation(t), a); } |
| 623 |
)? |
| 624 |
{ |
| 625 |
if (patterns.size() == 1 && a != null) { |
| 626 |
if (hadOccur[0]) |
| 627 |
p = sb.annotatePattern(p, a); |
| 628 |
else |
| 629 |
p = sb.makeGroup(patterns, makeLocation(t), a); |
| 630 |
} |
| 631 |
return p; |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
Pattern UnaryExpr(boolean topLevel, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, boolean[] hadOccur, Token[] except) : |
| 636 |
{ |
| 637 |
Pattern p; |
| 638 |
Token t; |
| 639 |
ElementAnnotation e; |
| 640 |
} |
| 641 |
{ |
| 642 |
p = AnnotatedPrimaryExpr(topLevel, scope, except) |
| 643 |
( |
| 644 |
{ |
| 645 |
if (hadOccur != null) hadOccur[0] = true; |
| 646 |
p = afterPatternComments(p); |
| 647 |
} |
| 648 |
(t = "+" { checkExcept(except); p = sb.makeOneOrMore(p, makeLocation(t), null); } |
| 649 |
| t = "?" { checkExcept(except); p = sb.makeOptional(p, makeLocation(t), null); } |
| 650 |
| t = "*" { checkExcept(except); p = sb.makeZeroOrMore(p, makeLocation(t), null); }) |
| 651 |
( t = <FANNOTATE> e = AnnotationElement(false) { |
| 652 |
if (topLevel) |
| 653 |
error("top_level_follow_annotation", t); |
| 654 |
else |
| 655 |
p = sb.annotateAfterPattern(p, e); |
| 656 |
} )* |
| 657 |
)? |
| 658 |
{ return p; } |
| 659 |
} |
| 660 |
|
| 661 |
Pattern ElementExpr(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 662 |
{ |
| 663 |
Token t; |
| 664 |
NameClass nc; |
| 665 |
Pattern p; |
| 666 |
} |
| 667 |
{ |
| 668 |
t = "element" |
| 669 |
nc = NameClass(IN_ELEMENT, null) |
| 670 |
"{" |
| 671 |
p = Expr(false, scope, null, null) |
| 672 |
{ p = afterPatternComments(p); } |
| 673 |
"}" |
| 674 |
{ return sb.makeElement(nc, p, makeLocation(t), a); } |
| 675 |
} |
| 676 |
|
| 677 |
Pattern AttributeExpr(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 678 |
{ |
| 679 |
Token t; |
| 680 |
NameClass nc; |
| 681 |
Pattern p; |
| 682 |
} |
| 683 |
{ |
| 684 |
t = "attribute" |
| 685 |
nc = NameClass(IN_ATTRIBUTE, null) |
| 686 |
"{" |
| 687 |
p = Expr(false, scope, null, null) |
| 688 |
{ p = afterPatternComments(p); } |
| 689 |
"}" |
| 690 |
{ return sb.makeAttribute(nc, p, makeLocation(t), a); } |
| 691 |
} |
| 692 |
|
| 693 |
NameClass NameClass(int context, Ref<AnnotationsImpl> ra) : |
| 694 |
{ |
| 695 |
AnnotationsImpl a; |
| 696 |
NameClass nc; |
| 697 |
} |
| 698 |
{ |
| 699 |
a = AnnotationsImpl() |
| 700 |
(nc = PrimaryNameClass(context, a) nc = AnnotateAfter(nc) nc = NameClassAlternatives(context, nc, ra) |
| 701 |
| nc = AnyNameExceptClass(context, a, ra) |
| 702 |
| nc = NsNameExceptClass(context, a, ra)) |
| 703 |
{ return nc; } |
| 704 |
} |
| 705 |
|
| 706 |
NameClass AnnotateAfter(NameClass nc) : |
| 707 |
{ |
| 708 |
ElementAnnotation e; |
| 709 |
} |
| 710 |
{ |
| 711 |
( <FANNOTATE> e = AnnotationElement(false) { nc = sb.annotateAfterNameClass(nc, e); })* |
| 712 |
{ return nc; } |
| 713 |
} |
| 714 |
|
| 715 |
NameClass NameClassAlternatives(int context, NameClass nc, Ref<AnnotationsImpl> ra) : |
| 716 |
{ |
| 717 |
Token t; |
| 718 |
List<NameClass> nameClasses; |
| 719 |
} |
| 720 |
{ |
| 721 |
( |
| 722 |
{ |
| 723 |
nameClasses = new ArrayList<NameClass>(); |
| 724 |
nameClasses.add(nc); |
| 725 |
} |
| 726 |
(t = "|" nc = BasicNameClass(context) nc = AnnotateAfter(nc) |
| 727 |
{ |
| 728 |
nameClasses.add(nc); |
| 729 |
})+ |
| 730 |
{ |
| 731 |
AnnotationsImpl a; |
| 732 |
if (ra == null) |
| 733 |
a = null; |
| 734 |
else { |
| 735 |
a = ra.get(); |
| 736 |
ra.clear(); |
| 737 |
} |
| 738 |
nc = sb.makeNameClassChoice(nameClasses, makeLocation(t), a); |
| 739 |
} |
| 740 |
)? |
| 741 |
{ return nc; } |
| 742 |
} |
| 743 |
|
| 744 |
NameClass BasicNameClass(int context) : |
| 745 |
{ |
| 746 |
AnnotationsImpl a; |
| 747 |
NameClass nc; |
| 748 |
} |
| 749 |
{ |
| 750 |
a = AnnotationsImpl() |
| 751 |
(nc = PrimaryNameClass(context, a) |
| 752 |
| nc = OpenNameClass(context, a)) |
| 753 |
{ return nc; } |
| 754 |
} |
| 755 |
|
| 756 |
NameClass PrimaryNameClass(int context, AnnotationsImpl a) : |
| 757 |
{ |
| 758 |
NameClass nc; |
| 759 |
} |
| 760 |
{ |
| 761 |
(nc = UnprefixedNameClass(context, a) |
| 762 |
| nc = PrefixedNameClass(a) |
| 763 |
| nc = ParenNameClass(context, a)) |
| 764 |
{ return nc; } |
| 765 |
} |
| 766 |
|
| 767 |
NameClass OpenNameClass(int context, AnnotationsImpl a) : |
| 768 |
{ |
| 769 |
Token t; |
| 770 |
LocatedString ns; |
| 771 |
} |
| 772 |
{ |
| 773 |
ns = NsName() { checkNsName(context, ns); return sb.makeNsName(ns.getString(), ns.getLocation(), a); } |
| 774 |
| t = "*" { checkAnyName(context, t); return sb.makeAnyName(makeLocation(t), a); } |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
NameClass UnprefixedNameClass(int context, AnnotationsImpl a) : |
| 779 |
{ |
| 780 |
LocatedString name; |
| 781 |
} |
| 782 |
{ |
| 783 |
name = UnprefixedName() |
| 784 |
{ |
| 785 |
String ns; |
| 786 |
if ((context & (IN_ATTRIBUTE|IN_ELEMENT)) == IN_ATTRIBUTE) |
| 787 |
ns = ""; |
| 788 |
else |
| 789 |
ns = defaultNamespace; |
| 790 |
return sb.makeName(ns, name.getString(), null, name.getLocation(), a); |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
NameClass PrefixedNameClass(AnnotationsImpl a) : |
| 795 |
{ |
| 796 |
Token t; |
| 797 |
} |
| 798 |
{ |
| 799 |
t = <PREFIXED_NAME> |
| 800 |
{ |
| 801 |
String qn = t.image; |
| 802 |
int colon = qn.indexOf(':'); |
| 803 |
String prefix = qn.substring(0, colon); |
| 804 |
return sb.makeName(lookupPrefix(prefix, t), qn.substring(colon + 1), prefix, makeLocation(t), a); |
| 805 |
} |
| 806 |
} |
| 807 |
|
| 808 |
NameClass NsNameExceptClass(int context, AnnotationsImpl a, Ref<AnnotationsImpl> ra) : |
| 809 |
{ |
| 810 |
LocatedString ns; |
| 811 |
NameClass nc; |
| 812 |
} |
| 813 |
{ |
| 814 |
ns = NsName() |
| 815 |
{ checkNsName(context, ns); } |
| 816 |
(nc = ExceptNameClass(context | IN_NS_NAME) |
| 817 |
{ nc = sb.makeNsName(ns.getString(), nc, ns.getLocation(), a); } |
| 818 |
nc = AnnotateAfter(nc) |
| 819 |
| { nc = sb.makeNsName(ns.getString(), ns.getLocation(), a); } |
| 820 |
nc = AnnotateAfter(nc) |
| 821 |
nc = NameClassAlternatives(context, nc, ra)) |
| 822 |
{ return nc; } |
| 823 |
} |
| 824 |
|
| 825 |
LocatedString NsName() : |
| 826 |
{ |
| 827 |
Token t; |
| 828 |
} |
| 829 |
{ |
| 830 |
t = <PREFIX_STAR> |
| 831 |
{ |
| 832 |
String qn = t.image; |
| 833 |
String prefix = qn.substring(0, qn.length() - 2); |
| 834 |
return new LocatedString(lookupPrefix(prefix, t), t); |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
NameClass AnyNameExceptClass(int context, AnnotationsImpl a, Ref<AnnotationsImpl> ra) : |
| 839 |
{ |
| 840 |
Token t; |
| 841 |
NameClass nc; |
| 842 |
} |
| 843 |
{ |
| 844 |
t = "*" |
| 845 |
{ checkAnyName(context, t); } |
| 846 |
(nc = ExceptNameClass(context | IN_ANY_NAME) |
| 847 |
{ nc = sb.makeAnyName(nc, makeLocation(t), a); } |
| 848 |
nc = AnnotateAfter(nc) |
| 849 |
| { nc = sb.makeAnyName(makeLocation(t), a); } |
| 850 |
nc = AnnotateAfter(nc) |
| 851 |
nc = NameClassAlternatives(context, nc, ra)) |
| 852 |
{ return nc; } |
| 853 |
} |
| 854 |
|
| 855 |
NameClass ParenNameClass(int context, AnnotationsImpl a) : |
| 856 |
{ |
| 857 |
Token t; |
| 858 |
NameClass nc; |
| 859 |
Ref<AnnotationsImpl> ra = new Ref<AnnotationsImpl>(a); |
| 860 |
} |
| 861 |
{ |
| 862 |
t = "(" nc = NameClass(context, ra) { nc = afterNameClassComments(nc); } ")" |
| 863 |
{ |
| 864 |
if (ra.get() != null) |
| 865 |
nc = sb.makeNameClassChoice(Collections.singletonList(nc), makeLocation(t), ra.get()); |
| 866 |
return nc; |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
NameClass ExceptNameClass(int context) : |
| 871 |
{ |
| 872 |
NameClass nc; |
| 873 |
} |
| 874 |
{ |
| 875 |
"-" nc = BasicNameClass(context) |
| 876 |
{ return nc; } |
| 877 |
} |
| 878 |
|
| 879 |
Pattern ListExpr(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 880 |
{ |
| 881 |
Token t; |
| 882 |
Pattern p; |
| 883 |
} |
| 884 |
{ |
| 885 |
t = "list" |
| 886 |
"{" |
| 887 |
p = Expr(false, scope, null, null) |
| 888 |
{ p = afterPatternComments(p); } |
| 889 |
"}" |
| 890 |
{ return sb.makeList(p, makeLocation(t), a); } |
| 891 |
} |
| 892 |
|
| 893 |
Pattern MixedExpr(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 894 |
{ |
| 895 |
Token t; |
| 896 |
Pattern p; |
| 897 |
} |
| 898 |
{ |
| 899 |
t = "mixed" |
| 900 |
"{" |
| 901 |
p = Expr(false, scope, null, null) |
| 902 |
{ p = afterPatternComments(p); } |
| 903 |
"}" |
| 904 |
{ return sb.makeMixed(p, makeLocation(t), a); } |
| 905 |
} |
| 906 |
|
| 907 |
Pattern GrammarExpr(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 908 |
{ |
| 909 |
Token t; |
| 910 |
Grammar<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> g; |
| 911 |
} |
| 912 |
{ |
| 913 |
t = "grammar" { g = sb.makeGrammar(scope); } |
| 914 |
"{" a = GrammarBody(g, g, a) { topLevelComments(g); } "}" |
| 915 |
{ return g.endGrammar(makeLocation(t), a); } |
| 916 |
} |
| 917 |
|
| 918 |
Pattern ParenExpr(boolean topLevel, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 919 |
{ |
| 920 |
Token t; |
| 921 |
Pattern p; |
| 922 |
} |
| 923 |
{ |
| 924 |
t = "(" p = Expr(topLevel, scope, t, a) { p = afterPatternComments(p); } ")" |
| 925 |
{ return p; } |
| 926 |
} |
| 927 |
|
| 928 |
AnnotationsImpl GrammarBody(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 929 |
{ |
| 930 |
ElementAnnotation e; |
| 931 |
} |
| 932 |
{ |
| 933 |
(LOOKAHEAD(2) e = AnnotationElementNotKeyword() |
| 934 |
{ if (a == null) a = sb.makeAnnotations(null, getContext()); a.addElement(e); })* |
| 935 |
(GrammarComponent(section, scope))* |
| 936 |
{ return a; } |
| 937 |
} |
| 938 |
|
| 939 |
void GrammarComponent(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope) : |
| 940 |
{ |
| 941 |
ElementAnnotation e; |
| 942 |
AnnotationsImpl a; |
| 943 |
} |
| 944 |
{ |
| 945 |
(a = AnnotationsImpl() |
| 946 |
(Definition(section, scope, a) |
| 947 |
| Include(section, scope, a) |
| 948 |
| Div(section, scope, a))) |
| 949 |
(LOOKAHEAD(2) e = AnnotationElementNotKeyword() { section.topLevelAnnotation(e); })* |
| 950 |
} |
| 951 |
|
| 952 |
void Definition(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 953 |
{} |
| 954 |
{ |
| 955 |
(Define(section, scope, a) | Start(section, scope, a)) |
| 956 |
} |
| 957 |
|
| 958 |
void Start(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 959 |
{ |
| 960 |
Token t; |
| 961 |
GrammarSection.Combine combine; |
| 962 |
Pattern p; |
| 963 |
} |
| 964 |
{ |
| 965 |
t = "start" combine = AssignOp() p = Expr(false, scope, null, null) |
| 966 |
{ section.define(GrammarSection.START, combine, p, makeLocation(t), a); } |
| 967 |
} |
| 968 |
|
| 969 |
void Define(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 970 |
{ |
| 971 |
LocatedString name; |
| 972 |
GrammarSection.Combine combine; |
| 973 |
Pattern p; |
| 974 |
} |
| 975 |
{ |
| 976 |
name = Identifier() combine = AssignOp() p = Expr(false, scope, null, null) |
| 977 |
{ section.define(name.getString(), combine, p, name.getLocation(), a); } |
| 978 |
} |
| 979 |
|
| 980 |
GrammarSection.Combine AssignOp() : |
| 981 |
{} |
| 982 |
{ |
| 983 |
"=" { return null; } |
| 984 |
| "|=" { return GrammarSection.COMBINE_CHOICE; } |
| 985 |
| "&=" { return GrammarSection.COMBINE_INTERLEAVE; } |
| 986 |
} |
| 987 |
|
| 988 |
void Include(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 989 |
{ |
| 990 |
Token t; |
| 991 |
String href; |
| 992 |
String ns; |
| 993 |
Include<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> include = section.makeInclude(); |
| 994 |
} |
| 995 |
{ |
| 996 |
t = "include" href = Literal() |
| 997 |
ns = Inherit() |
| 998 |
("{" a = IncludeBody(include, scope, a) { topLevelComments(include); } "}")? |
| 999 |
{ |
| 1000 |
try { |
| 1001 |
include.endInclude(href, sourceUri, ns, makeLocation(t), a); |
| 1002 |
} |
| 1003 |
catch (IllegalSchemaException e) { } |
| 1004 |
} |
| 1005 |
} |
| 1006 |
|
| 1007 |
AnnotationsImpl IncludeBody(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 1008 |
{ |
| 1009 |
ElementAnnotation e; |
| 1010 |
} |
| 1011 |
{ |
| 1012 |
(LOOKAHEAD(2) e = AnnotationElementNotKeyword() |
| 1013 |
{ if (a == null) a = sb.makeAnnotations(null, getContext()); a.addElement(e); })* |
| 1014 |
(IncludeComponent(section, scope))* |
| 1015 |
{ return a; } |
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
void IncludeComponent(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope) : |
| 1020 |
{ |
| 1021 |
ElementAnnotation e; |
| 1022 |
AnnotationsImpl a; |
| 1023 |
} |
| 1024 |
{ |
| 1025 |
(a = AnnotationsImpl() (Definition(section, scope, a) |
| 1026 |
| IncludeDiv(section, scope, a))) |
| 1027 |
(LOOKAHEAD(2) e = AnnotationElementNotKeyword() { section.topLevelAnnotation(e); })* |
| 1028 |
} |
| 1029 |
|
| 1030 |
void Div(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 1031 |
{ |
| 1032 |
Token t; |
| 1033 |
Div<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> div = section.makeDiv(); |
| 1034 |
} |
| 1035 |
{ |
| 1036 |
t = "div" "{" a = GrammarBody(div, scope, a) { topLevelComments(div); } "}" |
| 1037 |
{ div.endDiv(makeLocation(t), a); } |
| 1038 |
} |
| 1039 |
|
| 1040 |
void IncludeDiv(GrammarSection<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> section, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 1041 |
{ |
| 1042 |
Token t; |
| 1043 |
Div<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> div = section.makeDiv(); |
| 1044 |
} |
| 1045 |
{ |
| 1046 |
t = "div" "{" a = IncludeBody(div, scope, a) { topLevelComments(div); } "}" |
| 1047 |
{ div.endDiv(makeLocation(t), a); } |
| 1048 |
} |
| 1049 |
|
| 1050 |
Pattern ExternalRefExpr(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 1051 |
{ |
| 1052 |
Token t; |
| 1053 |
String href; |
| 1054 |
String ns; |
| 1055 |
} |
| 1056 |
{ |
| 1057 |
t = "external" href = Literal() |
| 1058 |
ns = Inherit() |
| 1059 |
{ |
| 1060 |
try { |
| 1061 |
return sb.makeExternalRef(href, sourceUri, ns, scope, makeLocation(t), a); |
| 1062 |
} |
| 1063 |
catch (IllegalSchemaException e) { |
| 1064 |
return sb.makeErrorPattern(); |
| 1065 |
} |
| 1066 |
} |
| 1067 |
} |
| 1068 |
|
| 1069 |
String Inherit() : |
| 1070 |
{ |
| 1071 |
String ns = null; |
| 1072 |
} |
| 1073 |
{ |
| 1074 |
("inherit" "=" ns = Prefix())? |
| 1075 |
{ |
| 1076 |
if (ns == null) |
| 1077 |
ns = defaultNamespace; |
| 1078 |
return ns; |
| 1079 |
} |
| 1080 |
} |
| 1081 |
|
| 1082 |
Pattern ParentExpr(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 1083 |
{ |
| 1084 |
LocatedString name; |
| 1085 |
} |
| 1086 |
{ |
| 1087 |
"parent" { a = addCommentsToChildAnnotations(a); } name = Identifier() |
| 1088 |
{ |
| 1089 |
return scope.makeParentRef(name.getString(), name.getLocation(), a); |
| 1090 |
} |
| 1091 |
} |
| 1092 |
|
| 1093 |
Pattern IdentifierExpr(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a) : |
| 1094 |
{ |
| 1095 |
LocatedString name; |
| 1096 |
} |
| 1097 |
{ |
| 1098 |
name = Identifier() |
| 1099 |
{ |
| 1100 |
return scope.makeRef(name.getString(), name.getLocation(), a); |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
Pattern ValueExpr(boolean topLevel, AnnotationsImpl a) : |
| 1105 |
{ |
| 1106 |
LocatedString s; |
| 1107 |
} |
| 1108 |
{ |
| 1109 |
s = LocatedLiteral() |
| 1110 |
{ |
| 1111 |
if (topLevel && annotationsIncludeElements) { |
| 1112 |
error("top_level_follow_annotation", s.getToken()); |
| 1113 |
a = null; |
| 1114 |
} |
| 1115 |
return sb.makeValue("", "token", s.getString(), getContext(), defaultNamespace, s.getLocation(), a); |
| 1116 |
} |
| 1117 |
} |
| 1118 |
|
| 1119 |
Pattern DataExpr(boolean topLevel, Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, AnnotationsImpl a, Token[] except) : |
| 1120 |
{ |
| 1121 |
Token datatypeToken; |
| 1122 |
Location loc; |
| 1123 |
String datatype; |
| 1124 |
String datatypeUri = null; |
| 1125 |
String s = null; |
| 1126 |
Pattern e = null; |
| 1127 |
DataPatternBuilder<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> dpb; |
| 1128 |
} |
| 1129 |
{ |
| 1130 |
datatypeToken = DatatypeName() |
| 1131 |
{ |
| 1132 |
datatype = datatypeToken.image; |
| 1133 |
loc = makeLocation(datatypeToken); |
| 1134 |
int colon = datatype.indexOf(':'); |
| 1135 |
if (colon < 0) |
| 1136 |
datatypeUri = ""; |
| 1137 |
else { |
| 1138 |
String prefix = datatype.substring(0, colon); |
| 1139 |
datatypeUri = lookupDatatype(prefix, datatypeToken); |
| 1140 |
datatype = datatype.substring(colon + 1); |
| 1141 |
} |
| 1142 |
} |
| 1143 |
((s = Literal() |
| 1144 |
{ |
| 1145 |
if (topLevel && annotationsIncludeElements) { |
| 1146 |
error("top_level_follow_annotation", datatypeToken); |
| 1147 |
a = null; |
| 1148 |
} |
| 1149 |
return sb.makeValue(datatypeUri, datatype, s, getContext(), defaultNamespace, loc, a); |
| 1150 |
} |
| 1151 |
) |
| 1152 |
| ( { dpb = sb.makeDataPatternBuilder(datatypeUri, datatype, loc); } |
| 1153 |
( (Params(dpb) (e = Except(scope, except))?) |
| 1154 |
| (e = Except(scope, except))?) |
| 1155 |
{ return e == null ? dpb.makePattern(loc, a) : dpb.makePattern(e, loc, a); })) |
| 1156 |
} |
| 1157 |
|
| 1158 |
Token DatatypeName() : |
| 1159 |
{ |
| 1160 |
Token t; |
| 1161 |
} |
| 1162 |
{ |
| 1163 |
(t = "string" | t = "token" | t = <PREFIXED_NAME>) |
| 1164 |
{ return t; } |
| 1165 |
} |
| 1166 |
|
| 1167 |
LocatedString Identifier() : |
| 1168 |
{ |
| 1169 |
LocatedString s; |
| 1170 |
Token t; |
| 1171 |
} |
| 1172 |
{ |
| 1173 |
(t = <IDENTIFIER> { s = new LocatedString(t.image, t); } |
| 1174 |
| t = <ESCAPED_IDENTIFIER> { s = new LocatedString(t.image.substring(1), t); }) |
| 1175 |
{ return s; } |
| 1176 |
} |
| 1177 |
|
| 1178 |
String Prefix() : |
| 1179 |
{ |
| 1180 |
Token t; |
| 1181 |
String prefix; |
| 1182 |
} |
| 1183 |
{ |
| 1184 |
(t = <IDENTIFIER> { prefix = t.image; } |
| 1185 |
| t = <ESCAPED_IDENTIFIER> { prefix = t.image.substring(1); } |
| 1186 |
| t = Keyword() { prefix = t.image; }) |
| 1187 |
{ return lookupPrefix(prefix, t); } |
| 1188 |
} |
| 1189 |
|
| 1190 |
LocatedString UnprefixedName() : |
| 1191 |
{ |
| 1192 |
LocatedString s; |
| 1193 |
Token t; |
| 1194 |
} |
| 1195 |
{ |
| 1196 |
(s = Identifier() |
| 1197 |
| t = Keyword() { s = new LocatedString(t.image, t); }) |
| 1198 |
{ return s; } |
| 1199 |
} |
| 1200 |
|
| 1201 |
void Params(DataPatternBuilder<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> dpb) : |
| 1202 |
{} |
| 1203 |
{ |
| 1204 |
"{" (Param(dpb))* "}" |
| 1205 |
} |
| 1206 |
|
| 1207 |
void Param(DataPatternBuilder<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> dpb) : |
| 1208 |
{ |
| 1209 |
LocatedString name; |
| 1210 |
AnnotationsImpl a; |
| 1211 |
String value; |
| 1212 |
} |
| 1213 |
{ |
| 1214 |
a = AnnotationsImpl() name = UnprefixedName() "=" { a = addCommentsToLeadingAnnotations(a); } value = Literal() |
| 1215 |
{ dpb.addParam(name.getString(), value, getContext(), defaultNamespace, name.getLocation(), a); } |
| 1216 |
} |
| 1217 |
|
| 1218 |
Pattern Except(Scope<Pattern, Location, ElementAnnotation, CommentListImpl, AnnotationsImpl> scope, Token[] except) : |
| 1219 |
{ |
| 1220 |
AnnotationsImpl a; |
| 1221 |
Pattern p; |
| 1222 |
Token t; |
| 1223 |
Token[] innerExcept = new Token[1]; |
| 1224 |
} |
| 1225 |
{ |
| 1226 |
t = "-" a = AnnotationsImpl() p = PrimaryExpr(false, scope, a, innerExcept) |
| 1227 |
{ |
| 1228 |
checkExcept(innerExcept); |
| 1229 |
except[0] = t; |
| 1230 |
return p; |
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
ElementAnnotation Documentation() : |
| 1235 |
{ |
| 1236 |
CommentListImpl comments = getComments(); |
| 1237 |
ElementAnnotationBuilder<Location, ElementAnnotation, CommentListImpl> eab; |
| 1238 |
Token t; |
| 1239 |
} |
| 1240 |
{ |
| 1241 |
(t = <DOCUMENTATION> | t = <DOCUMENTATION_AFTER_SINGLE_LINE_COMMENT>) |
| 1242 |
{ |
| 1243 |
eab = sb.makeElementAnnotationBuilder(WellKnownNamespaces.RELAX_NG_COMPATIBILITY_ANNOTATIONS, |
| 1244 |
"documentation", |
| 1245 |
getCompatibilityPrefix(), |
| 1246 |
makeLocation(t), |
| 1247 |
comments, |
| 1248 |
getContext()); |
| 1249 |
eab.addText(mungeComment(t.image), makeLocation(t), null); |
| 1250 |
} |
| 1251 |
(t = <DOCUMENTATION_CONTINUE> { eab.addText("\n" + mungeComment(t.image), makeLocation(t), null); })* |
| 1252 |
{ return eab.makeElementAnnotation(); } |
| 1253 |
} |
| 1254 |
|
| 1255 |
AnnotationsImpl AnnotationsImpl() : |
| 1256 |
{ |
| 1257 |
CommentListImpl comments = getComments(); |
| 1258 |
AnnotationsImpl a = null; |
| 1259 |
ElementAnnotation e; |
| 1260 |
} |
| 1261 |
{ |
| 1262 |
( { a = sb.makeAnnotations(comments, getContext()); } |
| 1263 |
(e = Documentation() { a.addElement(e); })+ |
| 1264 |
{ |
| 1265 |
comments = getComments(); |
| 1266 |
if (comments != null) |
| 1267 |
a.addLeadingComment(comments); |
| 1268 |
} |
| 1269 |
)? |
| 1270 |
("[" { if (a == null) a = sb.makeAnnotations(comments, getContext()); clearAttributeList(); annotationsIncludeElements = false; } |
| 1271 |
(LOOKAHEAD(2) PrefixedAnnotationAttribute(a, false) )* |
| 1272 |
( e = AnnotationElement(false) { a.addElement(e); annotationsIncludeElements = true; } )* |
| 1273 |
{ a.addComment(getComments()); } |
| 1274 |
"]")? |
| 1275 |
{ |
| 1276 |
if (a == null && comments != null) |
| 1277 |
a = sb.makeAnnotations(comments, getContext()); |
| 1278 |
return a; |
| 1279 |
} |
| 1280 |
} |
| 1281 |
|
| 1282 |
void AnnotationAttribute(Annotations<Location, ElementAnnotation, CommentListImpl> a) : |
| 1283 |
{} |
| 1284 |
{ |
| 1285 |
PrefixedAnnotationAttribute(a, true) | UnprefixedAnnotationAttribute(a) |
| 1286 |
} |
| 1287 |
|
| 1288 |
void PrefixedAnnotationAttribute(Annotations<Location, ElementAnnotation, CommentListImpl> a, boolean nested) : |
| 1289 |
{ |
| 1290 |
Token t; |
| 1291 |
String value; |
| 1292 |
} |
| 1293 |
{ |
| 1294 |
t = <PREFIXED_NAME> "=" value = Literal() |
| 1295 |
{ |
| 1296 |
String qn = t.image; |
| 1297 |
int colon = qn.indexOf(':'); |
| 1298 |
String prefix = qn.substring(0, colon); |
| 1299 |
String ns = lookupPrefix(prefix, t); |
| 1300 |
if (ns == SchemaBuilder.INHERIT_NS) |
| 1301 |
error("inherited_annotation_namespace", t); |
| 1302 |
else if (ns.length() == 0 && !nested) |
| 1303 |
error("unqualified_annotation_attribute", t); |
| 1304 |
else if (ns.equals(WellKnownNamespaces.RELAX_NG) && !nested) |
| 1305 |
error("relax_ng_namespace", t); |
| 1306 |
/*else if (ns.length() == 0 |
| 1307 |
&& qn.length() - colon - 1 == 5 |
| 1308 |
&& qn.regionMatches(colon + 1, "xmlns", 0, 5)) |
| 1309 |
error("xmlns_annotation_attribute", t);*/ |
| 1310 |
else if (ns.equals(WellKnownNamespaces.XMLNS)) |
| 1311 |
error("xmlns_annotation_attribute_uri", t); |
| 1312 |
else { |
| 1313 |
if (ns.length() == 0) |
| 1314 |
prefix = null; |
| 1315 |
addAttribute(a, ns, qn.substring(colon + 1), prefix, value, t); |
| 1316 |
} |
| 1317 |
} |
| 1318 |
} |
| 1319 |
|
| 1320 |
void UnprefixedAnnotationAttribute(Annotations<Location, ElementAnnotation, CommentListImpl> a) : |
| 1321 |
{ |
| 1322 |
LocatedString name; |
| 1323 |
String value; |
| 1324 |
} |
| 1325 |
{ |
| 1326 |
name = UnprefixedName() "=" value = Literal() |
| 1327 |
{ |
| 1328 |
if (name.getString().equals("xmlns")) |
| 1329 |
error("xmlns_annotation_attribute", name.getToken()); |
| 1330 |
else |
| 1331 |
addAttribute(a, "", name.getString(), null, value, name.getToken()); |
| 1332 |
} |
| 1333 |
} |
| 1334 |
|
| 1335 |
ElementAnnotation AnnotationElement(boolean nested) : |
| 1336 |
{ |
| 1337 |
ElementAnnotation a; |
| 1338 |
} |
| 1339 |
{ |
| 1340 |
(a = PrefixedAnnotationElement(nested) |
| 1341 |
| a = UnprefixedAnnotationElement()) |
| 1342 |
{ return a; } |
| 1343 |
} |
| 1344 |
|
| 1345 |
ElementAnnotation AnnotationElementNotKeyword() : |
| 1346 |
{ |
| 1347 |
ElementAnnotation a; |
| 1348 |
} |
| 1349 |
{ |
| 1350 |
(a = PrefixedAnnotationElement(false) |
| 1351 |
| a = IdentifierAnnotationElement()) |
| 1352 |
{ return a; } |
| 1353 |
} |
| 1354 |
|
| 1355 |
ElementAnnotation PrefixedAnnotationElement(boolean nested) : |
| 1356 |
{ |
| 1357 |
CommentListImpl comments = getComments(); |
| 1358 |
Token t; |
| 1359 |
ElementAnnotationBuilder<Location, ElementAnnotation, CommentListImpl> eab; |
| 1360 |
} |
| 1361 |
{ |
| 1362 |
t = <PREFIXED_NAME> |
| 1363 |
{ |
| 1364 |
String qn = t.image; |
| 1365 |
int colon = qn.indexOf(':'); |
| 1366 |
String prefix = qn.substring(0, colon); |
| 1367 |
String ns = lookupPrefix(prefix, t); |
| 1368 |
if (ns == SchemaBuilder.INHERIT_NS) { |
| 1369 |
error("inherited_annotation_namespace", t); |
| 1370 |
ns = ""; |
| 1371 |
} |
| 1372 |
else if (!nested && ns.equals(WellKnownNamespaces.RELAX_NG)) { |
| 1373 |
error("relax_ng_namespace", t); |
| 1374 |
ns = ""; |
| 1375 |
} |
| 1376 |
else { |
| 1377 |
if (ns.length() == 0) |
| 1378 |
prefix = null; |
| 1379 |
} |
| 1380 |
eab = sb.makeElementAnnotationBuilder(ns, qn.substring(colon + 1), prefix, |
| 1381 |
makeLocation(t), comments, getContext()); |
| 1382 |
} |
| 1383 |
AnnotationElementContent(eab) |
| 1384 |
{ return eab.makeElementAnnotation(); } |
| 1385 |
} |
| 1386 |
|
| 1387 |
ElementAnnotation UnprefixedAnnotationElement() : |
| 1388 |
{ |
| 1389 |
CommentListImpl comments = getComments(); |
| 1390 |
LocatedString name; |
| 1391 |
ElementAnnotationBuilder<Location, ElementAnnotation, CommentListImpl> eab; |
| 1392 |
} |
| 1393 |
{ |
| 1394 |
name = UnprefixedName() |
| 1395 |
{ |
| 1396 |
eab = sb.makeElementAnnotationBuilder("", name.getString(), null, |
| 1397 |
name.getLocation(), comments, getContext()); |
| 1398 |
} |
| 1399 |
AnnotationElementContent(eab) |
| 1400 |
{ return eab.makeElementAnnotation(); } |
| 1401 |
} |
| 1402 |
|
| 1403 |
ElementAnnotation IdentifierAnnotationElement() : |
| 1404 |
{ |
| 1405 |
CommentListImpl comments = getComments(); |
| 1406 |
LocatedString name; |
| 1407 |
ElementAnnotationBuilder<Location, ElementAnnotation, CommentListImpl> eab; |
| 1408 |
} |
| 1409 |
{ |
| 1410 |
name = Identifier() |
| 1411 |
{ |
| 1412 |
eab = sb.makeElementAnnotationBuilder("", name.getString(), null, |
| 1413 |
name.getLocation(), comments, getContext()); |
| 1414 |
} |
| 1415 |
AnnotationElementContent(eab) |
| 1416 |
{ return eab.makeElementAnnotation(); } |
| 1417 |
} |
| 1418 |
|
| 1419 |
void AnnotationElementContent(ElementAnnotationBuilder<Location, ElementAnnotation, CommentListImpl> eab) : |
| 1420 |
{ |
| 1421 |
ElementAnnotation e; |
| 1422 |
} |
| 1423 |
{ |
| 1424 |
"[" { clearAttributeList(); } |
| 1425 |
(LOOKAHEAD(2) AnnotationAttribute(eab))* |
| 1426 |
((AnnotationElementLiteral(eab) |
| 1427 |
("~" AnnotationElementLiteral(eab))*) |
| 1428 |
| e = AnnotationElement(true) { eab.addElement(e); })* |
| 1429 |
{ eab.addComment(getComments()); } |
| 1430 |
"]" |
| 1431 |
} |
| 1432 |
|
| 1433 |
void AnnotationElementLiteral(ElementAnnotationBuilder<Location, ElementAnnotation, CommentListImpl> eab) : |
| 1434 |
{ |
| 1435 |
Token t; |
| 1436 |
CommentListImpl comments = getComments(); |
| 1437 |
} |
| 1438 |
{ |
| 1439 |
t = <LITERAL> { eab.addText(unquote(t.image), makeLocation(t), comments); } |
| 1440 |
} |
| 1441 |
|
| 1442 |
String Literal() : |
| 1443 |
{ |
| 1444 |
Token t; |
| 1445 |
String s; |
| 1446 |
StringBuffer buf; |
| 1447 |
} |
| 1448 |
{ |
| 1449 |
t = <LITERAL> |
| 1450 |
{ |
| 1451 |
s = unquote(t.image); |
| 1452 |
} |
| 1453 |
( |
| 1454 |
{ buf = new StringBuffer(s); } |
| 1455 |
("~" t = <LITERAL> { buf.append(unquote(t.image)); })+ |
| 1456 |
{ s = buf.toString(); } |
| 1457 |
)? |
| 1458 |
{ return s; } |
| 1459 |
} |
| 1460 |
|
| 1461 |
LocatedString LocatedLiteral() : |
| 1462 |
{ |
| 1463 |
Token t; |
| 1464 |
Token t2; |
| 1465 |
String s; |
| 1466 |
StringBuffer buf; |
| 1467 |
} |
| 1468 |
{ |
| 1469 |
t = <LITERAL> |
| 1470 |
{ |
| 1471 |
s = unquote(t.image); |
| 1472 |
} |
| 1473 |
( |
| 1474 |
{ buf = new StringBuffer(s); } |
| 1475 |
("~" t2 = <LITERAL> { buf.append(unquote(t2.image)); })+ |
| 1476 |
{ s = buf.toString(); } |
| 1477 |
)? |
| 1478 |
{ return new LocatedString(s, t); } |
| 1479 |
} |
| 1480 |
|
| 1481 |
Token Keyword() : |
| 1482 |
{ |
| 1483 |
Token t; |
| 1484 |
} |
| 1485 |
{ |
| 1486 |
(t = "element" |
| 1487 |
| t = "attribute" |
| 1488 |
| t = "namespace" |
| 1489 |
| t = "list" |
| 1490 |
| t = "mixed" |
| 1491 |
| t = "grammar" |
| 1492 |
| t = "empty" |
| 1493 |
| t = "text" |
| 1494 |
| t = "parent" |
| 1495 |
| t = "external" |
| 1496 |
| t = "notAllowed" |
| 1497 |
| t = "start" |
| 1498 |
| t = "include" |
| 1499 |
| t = "default" |
| 1500 |
| t = "inherit" |
| 1501 |
| t = "string" |
| 1502 |
| t = "token" |
| 1503 |
| t = "datatypes" |
| 1504 |
| t = "div") |
| 1505 |
{ return t; } |
| 1506 |
} |
| 1507 |
|
| 1508 |
<*> |
| 1509 |
SKIP: { |
| 1510 |
< #NEWLINE : [ "\u0000", "\n" ] > |
| 1511 |
| < #NOT_NEWLINE : ~[ "\u0000", "\n" ] > |
| 1512 |
| < WS: ([ "\u0000", " ", "\n", "\t" ])+ > : DEFAULT |
| 1513 |
} |
| 1514 |
|
| 1515 |
TOKEN : |
| 1516 |
{ |
| 1517 |
< DOCUMENTATION: "##" (<NOT_NEWLINE>)* > : AFTER_DOCUMENTATION |
| 1518 |
} |
| 1519 |
|
| 1520 |
<AFTER_DOCUMENTATION> |
| 1521 |
TOKEN : |
| 1522 |
{ |
| 1523 |
< DOCUMENTATION_CONTINUE: <NEWLINE> ([" ", "\t"])* <DOCUMENTATION> > |
| 1524 |
} |
| 1525 |
|
| 1526 |
SPECIAL_TOKEN: |
| 1527 |
{ |
| 1528 |
< SINGLE_LINE_COMMENT: "#" (<NOT_NEWLINE>)* > : AFTER_SINGLE_LINE_COMMENT |
| 1529 |
} |
| 1530 |
|
| 1531 |
<AFTER_SINGLE_LINE_COMMENT> |
| 1532 |
TOKEN : |
| 1533 |
{ |
| 1534 |
< DOCUMENTATION_AFTER_SINGLE_LINE_COMMENT: <NEWLINE> ([" ", "\t"])* <DOCUMENTATION> > : AFTER_DOCUMENTATION |
| 1535 |
} |
| 1536 |
|
| 1537 |
<AFTER_SINGLE_LINE_COMMENT> |
| 1538 |
SPECIAL_TOKEN : |
| 1539 |
{ |
| 1540 |
< SINGLE_LINE_COMMENT_CONTINUE: <NEWLINE> ([" ", "\t"])* <SINGLE_LINE_COMMENT> > |
| 1541 |
} |
| 1542 |
|
| 1543 |
TOKEN : |
| 1544 |
{ |
| 1545 |
< #BASE_CHAR : [ |
| 1546 |
"\u0041" - "\u005a", |
| 1547 |
"\u0061" - "\u007a", |
| 1548 |
"\u00c0" - "\u00d6", |
| 1549 |
"\u00d8" - "\u00f6", |
| 1550 |
"\u00f8" - "\u00ff", |
| 1551 |
"\u0100" - "\u0131", |
| 1552 |
"\u0134" - "\u013e", |
| 1553 |
"\u0141" - "\u0148", |
| 1554 |
"\u014a" - "\u017e", |
| 1555 |
"\u0180" - "\u01c3", |
| 1556 |
"\u01cd" - "\u01f0", |
| 1557 |
"\u01f4" - "\u01f5", |
| 1558 |
"\u01fa" - "\u0217", |
| 1559 |
"\u0250" - "\u02a8", |
| 1560 |
"\u02bb" - "\u02c1", |
| 1561 |
"\u0386", |
| 1562 |
"\u0388" - "\u038a", |
| 1563 |
"\u038c", |
| 1564 |
"\u038e" - "\u03a1", |
| 1565 |
"\u03a3" - "\u03ce", |
| 1566 |
"\u03d0" - "\u03d6", |
| 1567 |
"\u03da", |
| 1568 |
"\u03dc", |
| 1569 |
"\u03de", |
| 1570 |
"\u03e0", |
| 1571 |
"\u03e2" - "\u03f3", |
| 1572 |
"\u0401" - "\u040c", |
| 1573 |
"\u040e" - "\u044f", |
| 1574 |
"\u0451" - "\u045c", |
| 1575 |
"\u045e" - "\u0481", |
| 1576 |
"\u0490" - "\u04c4", |
| 1577 |
"\u04c7" - "\u04c8", |
| 1578 |
"\u04cb" - "\u04cc", |
| 1579 |
"\u04d0" - "\u04eb", |
| 1580 |
"\u04ee" - "\u04f5", |
| 1581 |
"\u04f8" - "\u04f9", |
| 1582 |
"\u0531" - "\u0556", |
| 1583 |
"\u0559", |
| 1584 |
"\u0561" - "\u0586", |
| 1585 |
"\u05d0" - "\u05ea", |
| 1586 |
"\u05f0" - "\u05f2", |
| 1587 |
"\u0621" - "\u063a", |
| 1588 |
"\u0641" - "\u064a", |
| 1589 |
"\u0671" - "\u06b7", |
| 1590 |
"\u06ba" - "\u06be", |
| 1591 |
"\u06c0" - "\u06ce", |
| 1592 |
"\u06d0" - "\u06d3", |
| 1593 |
"\u06d5", |
| 1594 |
"\u06e5" - "\u06e6", |
| 1595 |
"\u0905" - "\u0939", |
| 1596 |
"\u093d", |
| 1597 |
"\u0958" - "\u0961", |
| 1598 |
"\u0985" - "\u098c", |
| 1599 |
"\u098f" - "\u0990", |
| 1600 |
"\u0993" - "\u09a8", |
| 1601 |
"\u09aa" - "\u09b0", |
| 1602 |
"\u09b2", |
| 1603 |
"\u09b6" - "\u09b9", |
| 1604 |
"\u09dc" - "\u09dd", |
| 1605 |
"\u09df" - "\u09e1", |
| 1606 |
"\u09f0" - "\u09f1", |
| 1607 |
"\u0a05" - "\u0a0a", |
| 1608 |
"\u0a0f" - "\u0a10", |
| 1609 |
"\u0a13" - "\u0a28", |
| 1610 |
"\u0a2a" - "\u0a30", |
| 1611 |
"\u0a32" - "\u0a33", |
| 1612 |
"\u0a35" - "\u0a36", |
| 1613 |
"\u0a38" - "\u0a39", |
| 1614 |
"\u0a59" - "\u0a5c", |
| 1615 |
"\u0a5e", |
| 1616 |
"\u0a72" - "\u0a74", |
| 1617 |
"\u0a85" - "\u0a8b", |
| 1618 |
"\u0a8d", |
| 1619 |
"\u0a8f" - "\u0a91", |
| 1620 |
"\u0a93" - "\u0aa8", |
| 1621 |
"\u0aaa" - "\u0ab0", |
| 1622 |
"\u0ab2" - "\u0ab3", |
| 1623 |
"\u0ab5" - "\u0ab9", |
| 1624 |
"\u0abd", |
| 1625 |
"\u0ae0", |
| 1626 |
"\u0b05" - "\u0b0c", |
| 1627 |
"\u0b0f" - "\u0b10", |
| 1628 |
"\u0b13" - "\u0b28", |
| 1629 |
"\u0b2a" - "\u0b30", |
| 1630 |
"\u0b32" - "\u0b33", |
| 1631 |
"\u0b36" - "\u0b39", |
| 1632 |
"\u0b3d", |
| 1633 |
"\u0b5c" - "\u0b5d", |
| 1634 |
"\u0b5f" - "\u0b61", |
| 1635 |
"\u0b85" - "\u0b8a", |
| 1636 |
"\u0b8e" - "\u0b90", |
| 1637 |
"\u0b92" - "\u0b95", |
| 1638 |
"\u0b99" - "\u0b9a", |
| 1639 |
"\u0b9c", |
| 1640 |
"\u0b9e" - "\u0b9f", |
| 1641 |
"\u0ba3" - "\u0ba4", |
| 1642 |
"\u0ba8" - "\u0baa", |
| 1643 |
"\u0bae" - "\u0bb5", |
| 1644 |
"\u0bb7" - "\u0bb9", |
| 1645 |
"\u0c05" - "\u0c0c", |
| 1646 |
"\u0c0e" - "\u0c10", |
| 1647 |
"\u0c12" - "\u0c28", |
| 1648 |
"\u0c2a" - "\u0c33", |
| 1649 |
"\u0c35" - "\u0c39", |
| 1650 |
"\u0c60" - "\u0c61", |
| 1651 |
"\u0c85" - "\u0c8c", |
| 1652 |
"\u0c8e" - "\u0c90", |
| 1653 |
"\u0c92" - "\u0ca8", |
| 1654 |
"\u0caa" - "\u0cb3", |
| 1655 |
"\u0cb5" - "\u0cb9", |
| 1656 |
"\u0cde", |
| 1657 |
"\u0ce0" - "\u0ce1", |
| 1658 |
"\u0d05" - "\u0d0c", |
| 1659 |
"\u0d0e" - "\u0d10", |
| 1660 |
"\u0d12" - "\u0d28", |
| 1661 |
"\u0d2a" - "\u0d39", |
| 1662 |
"\u0d60" - "\u0d61", |
| 1663 |
"\u0e01" - "\u0e2e", |
| 1664 |
"\u0e30", |
| 1665 |
"\u0e32" - "\u0e33", |
| 1666 |
"\u0e40" - "\u0e45", |
| 1667 |
"\u0e81" - "\u0e82", |
| 1668 |
"\u0e84", |
| 1669 |
"\u0e87" - "\u0e88", |
| 1670 |
"\u0e8a", |
| 1671 |
"\u0e8d", |
| 1672 |
"\u0e94" - "\u0e97", |
| 1673 |
"\u0e99" - "\u0e9f", |
| 1674 |
"\u0ea1" - "\u0ea3", |
| 1675 |
"\u0ea5", |
| 1676 |
"\u0ea7", |
| 1677 |
"\u0eaa" - "\u0eab", |
| 1678 |
"\u0ead" - "\u0eae", |
| 1679 |
"\u0eb0", |
| 1680 |
"\u0eb2" - "\u0eb3", |
| 1681 |
"\u0ebd", |
| 1682 |
"\u0ec0" - "\u0ec4", |
| 1683 |
"\u0f40" - "\u0f47", |
| 1684 |
"\u0f49" - "\u0f69", |
| 1685 |
"\u10a0" - "\u10c5", |
| 1686 |
"\u10d0" - "\u10f6", |
| 1687 |
"\u1100", |
| 1688 |
"\u1102" - "\u1103", |
| 1689 |
"\u1105" - "\u1107", |
| 1690 |
"\u1109", |
| 1691 |
"\u110b" - "\u110c", |
| 1692 |
"\u110e" - "\u1112", |
| 1693 |
"\u113c", |
| 1694 |
"\u113e", |
| 1695 |
"\u1140", |
| 1696 |
"\u114c", |
| 1697 |
"\u114e", |
| 1698 |
"\u1150", |
| 1699 |
"\u1154" - "\u1155", |
| 1700 |
"\u1159", |
| 1701 |
"\u115f" - "\u1161", |
| 1702 |
"\u1163", |
| 1703 |
"\u1165", |
| 1704 |
"\u1167", |
| 1705 |
"\u1169", |
| 1706 |
"\u116d" - "\u116e", |
| 1707 |
"\u1172" - "\u1173", |
| 1708 |
"\u1175", |
| 1709 |
"\u119e", |
| 1710 |
"\u11a8", |
| 1711 |
"\u11ab", |
| 1712 |
"\u11ae" - "\u11af", |
| 1713 |
"\u11b7" - "\u11b8", |
| 1714 |
"\u11ba", |
| 1715 |
"\u11bc" - "\u11c2", |
| 1716 |
"\u11eb", |
| 1717 |
"\u11f0", |
| 1718 |
"\u11f9", |
| 1719 |
"\u1e00" - "\u1e9b", |
| 1720 |
"\u1ea0" - "\u1ef9", |
| 1721 |
"\u1f00" - "\u1f15", |
| 1722 |
"\u1f18" - "\u1f1d", |
| 1723 |
"\u1f20" - "\u1f45", |
| 1724 |
"\u1f48" - "\u1f4d", |
| 1725 |
"\u1f50" - "\u1f57", |
| 1726 |
"\u1f59", |
| 1727 |
"\u1f5b", |
| 1728 |
"\u1f5d", |
| 1729 |
"\u1f5f" - "\u1f7d", |
| 1730 |
"\u1f80" - "\u1fb4", |
| 1731 |
"\u1fb6" - "\u1fbc", |
| 1732 |
"\u1fbe", |
| 1733 |
"\u1fc2" - "\u1fc4", |
| 1734 |
"\u1fc6" - "\u1fcc", |
| 1735 |
"\u1fd0" - "\u1fd3", |
| 1736 |
"\u1fd6" - "\u1fdb", |
| 1737 |
"\u1fe0" - "\u1fec", |
| 1738 |
"\u1ff2" - "\u1ff4", |
| 1739 |
"\u1ff6" - "\u1ffc", |
| 1740 |
"\u2126", |
| 1741 |
"\u212a" - "\u212b", |
| 1742 |
"\u212e", |
| 1743 |
"\u2180" - "\u2182", |
| 1744 |
"\u3041" - "\u3094", |
| 1745 |
"\u30a1" - "\u30fa", |
| 1746 |
"\u3105" - "\u312c", |
| 1747 |
"\uac00" - "\ud7a3" |
| 1748 |
] > |
| 1749 |
| < #IDEOGRAPHIC : [ |
| 1750 |
"\u4e00" - "\u9fa5", |
| 1751 |
"\u3007", |
| 1752 |
"\u3021" - "\u3029" |
| 1753 |
] > |
| 1754 |
| < #LETTER : (<BASE_CHAR> | <IDEOGRAPHIC>) > |
| 1755 |
| < #COMBINING_CHAR : [ |
| 1756 |
"\u0300" - "\u0345", |
| 1757 |
"\u0360" - "\u0361", |
| 1758 |
"\u0483" - "\u0486", |
| 1759 |
"\u0591" - "\u05a1", |
| 1760 |
"\u05a3" - "\u05b9", |
| 1761 |
"\u05bb" - "\u05bd", |
| 1762 |
"\u05bf", |
| 1763 |
"\u05c1" - "\u05c2", |
| 1764 |
"\u05c4", |
| 1765 |
"\u064b" - "\u0652", |
| 1766 |
"\u0670", |
| 1767 |
"\u06d6" - "\u06dc", |
| 1768 |
"\u06dd" - "\u06df", |
| 1769 |
"\u06e0" - "\u06e4", |
| 1770 |
"\u06e7" - "\u06e8", |
| 1771 |
"\u06ea" - "\u06ed", |
| 1772 |
"\u0901" - "\u0903", |
| 1773 |
"\u093c", |
| 1774 |
"\u093e" - "\u094c", |
| 1775 |
"\u094d", |
| 1776 |
"\u0951" - "\u0954", |
| 1777 |
"\u0962" - "\u0963", |
| 1778 |
"\u0981" - "\u0983", |
| 1779 |
"\u09bc", |
| 1780 |
"\u09be", |
| 1781 |
"\u09bf", |
| 1782 |
"\u09c0" - "\u09c4", |
| 1783 |
"\u09c7" - "\u09c8", |
| 1784 |
"\u09cb" - "\u09cd", |
| 1785 |
"\u09d7", |
| 1786 |
"\u09e2" - "\u09e3", |
| 1787 |
"\u0a02", |
| 1788 |
"\u0a3c", |
| 1789 |
"\u0a3e", |
| 1790 |
"\u0a3f", |
| 1791 |
"\u0a40" - "\u0a42", |
| 1792 |
"\u0a47" - "\u0a48", |
| 1793 |
"\u0a4b" - "\u0a4d", |
| 1794 |
"\u0a70" - "\u0a71", |
| 1795 |
"\u0a81" - "\u0a83", |
| 1796 |
"\u0abc", |
| 1797 |
"\u0abe" - "\u0ac5", |
| 1798 |
"\u0ac7" - "\u0ac9", |
| 1799 |
"\u0acb" - "\u0acd", |
| 1800 |
"\u0b01" - "\u0b03", |
| 1801 |
"\u0b3c", |
| 1802 |
"\u0b3e" - "\u0b43", |
| 1803 |
"\u0b47" - "\u0b48", |
| 1804 |
"\u0b4b" - "\u0b4d", |
| 1805 |
"\u0b56" - "\u0b57", |
| 1806 |
"\u0b82" - "\u0b83", |
| 1807 |
"\u0bbe" - "\u0bc2", |
| 1808 |
"\u0bc6" - "\u0bc8", |
| 1809 |
"\u0bca" - "\u0bcd", |
| 1810 |
"\u0bd7", |
| 1811 |
"\u0c01" - "\u0c03", |
| 1812 |
"\u0c3e" - "\u0c44", |
| 1813 |
"\u0c46" - "\u0c48", |
| 1814 |
"\u0c4a" - "\u0c4d", |
| 1815 |
"\u0c55" - "\u0c56", |
| 1816 |
"\u0c82" - "\u0c83", |
| 1817 |
"\u0cbe" - "\u0cc4", |
| 1818 |
"\u0cc6" - "\u0cc8", |
| 1819 |
"\u0cca" - "\u0ccd", |
| 1820 |
"\u0cd5" - "\u0cd6", |
| 1821 |
"\u0d02" - "\u0d03", |
| 1822 |
"\u0d3e" - "\u0d43", |
| 1823 |
"\u0d46" - "\u0d48", |
| 1824 |
"\u0d4a" - "\u0d4d", |
| 1825 |
"\u0d57", |
| 1826 |
"\u0e31", |
| 1827 |
"\u0e34" - "\u0e3a", |
| 1828 |
"\u0e47" - "\u0e4e", |
| 1829 |
"\u0eb1", |
| 1830 |
"\u0eb4" - "\u0eb9", |
| 1831 |
"\u0ebb" - "\u0ebc", |
| 1832 |
"\u0ec8" - "\u0ecd", |
| 1833 |
"\u0f18" - "\u0f19", |
| 1834 |
"\u0f35", |
| 1835 |
"\u0f37", |
| 1836 |
"\u0f39", |
| 1837 |
"\u0f3e", |
| 1838 |
"\u0f3f", |
| 1839 |
"\u0f71" - "\u0f84", |
| 1840 |
"\u0f86" - "\u0f8b", |
| 1841 |
"\u0f90" - "\u0f95", |
| 1842 |
"\u0f97", |
| 1843 |
"\u0f99" - "\u0fad", |
| 1844 |
"\u0fb1" - "\u0fb7", |
| 1845 |
"\u0fb9", |
| 1846 |
"\u20d0" - "\u20dc", |
| 1847 |
"\u20e1", |
| 1848 |
"\u302a" - "\u302f", |
| 1849 |
"\u3099", |
| 1850 |
"\u309a" |
| 1851 |
] > |
| 1852 |
| < #DIGIT : [ |
| 1853 |
"\u0030" - "\u0039", |
| 1854 |
"\u0660" - "\u0669", |
| 1855 |
"\u06f0" - "\u06f9", |
| 1856 |
"\u0966" - "\u096f", |
| 1857 |
"\u09e6" - "\u09ef", |
| 1858 |
"\u0a66" - "\u0a6f", |
| 1859 |
"\u0ae6" - "\u0aef", |
| 1860 |
"\u0b66" - "\u0b6f", |
| 1861 |
"\u0be7" - "\u0bef", |
| 1862 |
"\u0c66" - "\u0c6f", |
| 1863 |
"\u0ce6" - "\u0cef", |
| 1864 |
"\u0d66" - "\u0d6f", |
| 1865 |
"\u0e50" - "\u0e59", |
| 1866 |
"\u0ed0" - "\u0ed9", |
| 1867 |
"\u0f20" - "\u0f29" |
| 1868 |
] > |
| 1869 |
| < #EXTENDER : [ |
| 1870 |
"\u00b7", |
| 1871 |
"\u02d0", |
| 1872 |
"\u02d1", |
| 1873 |
"\u0387", |
| 1874 |
"\u0640", |
| 1875 |
"\u0e46", |
| 1876 |
"\u0ec6", |
| 1877 |
"\u3005", |
| 1878 |
"\u3031" - "\u3035", |
| 1879 |
"\u309d" - "\u309e", |
| 1880 |
"\u30fc" - "\u30fe" |
| 1881 |
] > |
| 1882 |
| < #NMSTART : (<LETTER> | "_") > |
| 1883 |
| < #NMCHAR : (<LETTER> | <COMBINING_CHAR> | <EXTENDER> | <DIGIT> | "." | "-" | "_") > |
| 1884 |
| < #NCNAME: <NMSTART> (<NMCHAR>)* > |
| 1885 |
} |
| 1886 |
|
| 1887 |
TOKEN : |
| 1888 |
{ |
| 1889 |
< IDENTIFIER: <NCNAME> > |
| 1890 |
| < ESCAPED_IDENTIFIER: "\\" <NCNAME> > |
| 1891 |
| < PREFIX_STAR: <NCNAME> ":*" > |
| 1892 |
| < PREFIXED_NAME: <NCNAME> ":" <NCNAME> > |
| 1893 |
| < LITERAL : ("\"" (~["\u0000", "\""])* "\"") |
| 1894 |
| ("'" (~["\u0000", "'"])* "'") |
| 1895 |
| ("\"\"\"" (~["\""] |
| 1896 |
| ("\"" ~["\""]) |
| 1897 |
| ("\"\"" ~["\""]))* "\"\"\"") |
| 1898 |
| ("'''" (~["'"] |
| 1899 |
| ("'" ~["'"]) |
| 1900 |
| ("''" ~["'"]))* "'''") > |
| 1901 |
| < FANNOTATE : ">>" > |
| 1902 |
} |
| 1903 |
|
| 1904 |
/* This avoids lexical errors from JavaCC. */ |
| 1905 |
<*> |
| 1906 |
TOKEN : |
| 1907 |
{ |
| 1908 |
< ILLEGAL_CHAR : [ "\u0000" - "\u0008", "\u000b" - "\uffff" ] > |
| 1909 |
} |