annotate src/share/classes/com/sun/xml/internal/rngom/parse/compact/CompactSyntax.jj @ 0:0961a4a21176

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