| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.parser; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.Version; |
| 12 |
import net.sf.saxon.expr.*; |
| 13 |
import net.sf.saxon.expr.flwor.Clause; |
| 14 |
import net.sf.saxon.expr.instruct.Block; |
| 15 |
import net.sf.saxon.expr.instruct.Choose; |
| 16 |
import net.sf.saxon.expr.instruct.ForEach; |
| 17 |
import net.sf.saxon.functions.*; |
| 18 |
import net.sf.saxon.functions.registry.VendorFunctionSetHE; |
| 19 |
import net.sf.saxon.lib.Feature; |
| 20 |
import net.sf.saxon.lib.NamespaceConstant; |
| 21 |
import net.sf.saxon.ma.arrays.ArrayFunctionSet; |
| 22 |
import net.sf.saxon.ma.arrays.ArrayItemType; |
| 23 |
import net.sf.saxon.ma.arrays.SimpleArrayItem; |
| 24 |
import net.sf.saxon.ma.arrays.SquareArrayConstructor; |
| 25 |
import net.sf.saxon.ma.map.*; |
| 26 |
import net.sf.saxon.om.*; |
| 27 |
import net.sf.saxon.pattern.*; |
| 28 |
import net.sf.saxon.query.AnnotationList; |
| 29 |
import net.sf.saxon.trace.LocationKind; |
| 30 |
import net.sf.saxon.trans.Err; |
| 31 |
import net.sf.saxon.trans.LicenseException; |
| 32 |
import net.sf.saxon.trans.SymbolicName; |
| 33 |
import net.sf.saxon.trans.XPathException; |
| 34 |
import net.sf.saxon.type.*; |
| 35 |
import net.sf.saxon.value.*; |
| 36 |
import net.sf.saxon.z.IntArraySet; |
| 37 |
import net.sf.saxon.z.IntSet; |
| 38 |
|
| 39 |
import java.util.ArrayList; |
| 40 |
import java.util.Arrays; |
| 41 |
import java.util.List; |
| 42 |
import java.util.Stack; |
| 43 |
import java.util.function.IntPredicate; |
| 44 |
|
| 45 |
import static net.sf.saxon.type.BuiltInAtomicType.*; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public class XPathParser { |
| 58 |
|
| 59 |
protected Tokenizer t; |
| 60 |
protected StaticContext env; |
| 61 |
protected Stack<LocalBinding> rangeVariables = new Stack<>(); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
protected QNameParser qNameParser; |
| 67 |
protected ParserExtension parserExtension = new ParserExtension(); |
| 68 |
|
| 69 |
protected IntPredicate charChecker; |
| 70 |
|
| 71 |
protected boolean allowXPath30Syntax = false; |
| 72 |
protected boolean allowXPath30XSLTExtensions = false; |
| 73 |
protected boolean allowXPath31Syntax = false; |
| 74 |
protected boolean allowSaxonExtensions = false; |
| 75 |
|
| 76 |
protected boolean scanOnly = false; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
private boolean allowAbsentExpression = false; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
protected CodeInjector codeInjector = null; |
| 90 |
private Accelerator accelerator = null; |
| 91 |
|
| 92 |
protected int language = XPATH; |
| 93 |
public static final int XPATH = 0; |
| 94 |
public static final int XSLT_PATTERN = 1; |
| 95 |
public static final int SEQUENCE_TYPE = 2; |
| 96 |
public static final int XQUERY = 3; |
| 97 |
public static final int EXTENDED_ITEM_TYPE = 4; |
| 98 |
|
| 99 |
protected int languageVersion = 20; |
| 100 |
protected int catchDepth = 0; |
| 101 |
|
| 102 |
public interface Accelerator { |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
Expression parse(Tokenizer t, StaticContext env, String expression, int start, int terminator); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public XPathParser() { |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public void setCodeInjector( CodeInjector injector) { |
| 135 |
this.codeInjector = injector; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public CodeInjector getCodeInjector() { |
| 148 |
return codeInjector; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public void setAccelerator(Accelerator accelerator) { |
| 157 |
this.accelerator = accelerator; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
public Tokenizer getTokenizer() { |
| 167 |
return t; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
public StaticContext getStaticContext() { |
| 177 |
return env; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
public void setParserExtension(ParserExtension extension) { |
| 207 |
this.parserExtension = extension; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
public void setCatchDepth(int depth) { |
| 217 |
catchDepth = depth; |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public void nextToken() throws XPathException { |
| 227 |
try { |
| 228 |
t.next(); |
| 229 |
} catch (XPathException e) { |
| 230 |
grumble(e.getMessage()); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
public void expect(int token) throws XPathException { |
| 244 |
if (t.currentToken != token) { |
| 245 |
grumble("expected \"" + Token.tokens[token] + |
| 246 |
"\", found " + currentTokenDisplay()); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
public void grumble(String message) throws XPathException { |
| 259 |
grumble(message, language == XSLT_PATTERN ? "XTSE0340" : "XPST0003"); |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public void grumble(String message, String errorCode) throws XPathException { |
| 272 |
grumble(message, new StructuredQName("", NamespaceConstant.ERR, errorCode), -1); |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public void grumble(String message, String errorCode, int offset) throws XPathException { |
| 286 |
grumble(message, new StructuredQName("", NamespaceConstant.ERR, errorCode), offset); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
protected void grumble(String message, StructuredQName errorCode, int offset) throws XPathException { |
| 300 |
if (errorCode == null) { |
| 301 |
errorCode = new StructuredQName("err", NamespaceConstant.ERR, "XPST0003"); |
| 302 |
} |
| 303 |
String nearbyText = t.recentText(-1); |
| 304 |
int line; |
| 305 |
int column; |
| 306 |
if (offset == -1) { |
| 307 |
line = t.getLineNumber(); |
| 308 |
column = t.getColumnNumber(); |
| 309 |
} else { |
| 310 |
line = t.getLineNumber(offset); |
| 311 |
column = t.getColumnNumber(offset); |
| 312 |
} |
| 313 |
Location loc = makeNestedLocation(env.getContainingLocation(), line, column, nearbyText); |
| 314 |
|
| 315 |
XPathException err = new XPathException(message); |
| 316 |
err.setLocation(loc); |
| 317 |
err.setIsSyntaxError("XPST0003".equals(errorCode.getLocalPart())); |
| 318 |
err.setIsStaticError(true); |
| 319 |
err.setHostLanguage(getLanguage()); |
| 320 |
|
| 321 |
err.setErrorCodeQName(errorCode); |
| 322 |
throw err; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
protected void warning(String message) { |
| 333 |
if (!env.getConfiguration().getBooleanProperty(Feature.SUPPRESS_XPATH_WARNINGS)) { |
| 334 |
String s = t.recentText(-1); |
| 335 |
String prefix = |
| 336 |
(message.startsWith("...") ? "near" : "in") + |
| 337 |
' ' + Err.wrap(s) + ":\n "; |
| 338 |
env.issueWarning(prefix + message, makeLocation()); |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
public void setLanguage(int language, int version) { |
| 353 |
if (version == 0) { |
| 354 |
version = 30; |
| 355 |
} |
| 356 |
if (version == 305) { |
| 357 |
version = 30; |
| 358 |
allowXPath30XSLTExtensions = true; |
| 359 |
} |
| 360 |
switch (language) { |
| 361 |
case XPATH: |
| 362 |
if (!(version == 20 || version == 30 || version == 31)) { |
| 363 |
throw new IllegalArgumentException("Unsupported language version " + version); |
| 364 |
} |
| 365 |
break; |
| 366 |
case XSLT_PATTERN: |
| 367 |
case SEQUENCE_TYPE: |
| 368 |
if (!(version == 20 || version == 30 || version == 31)) { |
| 369 |
throw new IllegalArgumentException("Unsupported language version " + version); |
| 370 |
} |
| 371 |
break; |
| 372 |
case XQUERY: |
| 373 |
if (!(version == 10 || version == 30 || version == 31)) { |
| 374 |
throw new IllegalArgumentException("Unsupported language version " + version); |
| 375 |
} |
| 376 |
break; |
| 377 |
default: |
| 378 |
throw new IllegalArgumentException("Unknown language " + language); |
| 379 |
} |
| 380 |
this.language = language; |
| 381 |
this.languageVersion = version; |
| 382 |
this.allowXPath30Syntax = languageVersion >= 30; |
| 383 |
this.allowXPath31Syntax = languageVersion >= 31; |
| 384 |
|
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
protected String getLanguage() { |
| 394 |
switch (language) { |
| 395 |
case XPATH: |
| 396 |
return "XPath"; |
| 397 |
case XSLT_PATTERN: |
| 398 |
return "XSLT Pattern"; |
| 399 |
case SEQUENCE_TYPE: |
| 400 |
return "SequenceType"; |
| 401 |
case XQUERY: |
| 402 |
return "XQuery"; |
| 403 |
case EXTENDED_ITEM_TYPE: |
| 404 |
return "Extended ItemType"; |
| 405 |
default: |
| 406 |
return "XPath"; |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
public boolean isAllowXPath31Syntax() { |
| 417 |
return allowXPath31Syntax; |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
public void setQNameParser(QNameParser qp) { |
| 427 |
this.qNameParser = qp; |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
public QNameParser getQNameParser() { |
| 437 |
return qNameParser; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
protected String currentTokenDisplay() { |
| 447 |
if (t.currentToken == Token.NAME) { |
| 448 |
return "name \"" + t.currentTokenValue + '\"'; |
| 449 |
} else if (t.currentToken == Token.UNKNOWN) { |
| 450 |
return "(unknown token)"; |
| 451 |
} else { |
| 452 |
return '\"' + Token.tokens[t.currentToken] + '\"'; |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
public Expression parse(String expression, int start, int terminator, StaticContext env) |
| 470 |
throws XPathException { |
| 471 |
|
| 472 |
this.env = env; |
| 473 |
int languageVersion = env.getXPathVersion(); |
| 474 |
if (languageVersion == 20 && language == XQUERY) { |
| 475 |
languageVersion = 10; |
| 476 |
} |
| 477 |
setLanguage(language, languageVersion); |
| 478 |
|
| 479 |
Expression exp = null; |
| 480 |
int offset = start; |
| 481 |
if (accelerator != null) { |
| 482 |
if (expression.length() - start < 30 || terminator == Token.RCURLY) { |
| 483 |
|
| 484 |
|
| 485 |
t = new Tokenizer(); |
| 486 |
t.languageLevel = env.getXPathVersion(); |
| 487 |
exp = accelerator.parse(t, env, expression, start, terminator); |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
if (exp == null) { |
| 492 |
|
| 493 |
qNameParser = new QNameParser(env.getNamespaceResolver()); |
| 494 |
qNameParser.setAcceptEQName(allowXPath30Syntax); |
| 495 |
qNameParser.setDefaultNamespace(""); |
| 496 |
qNameParser.setErrorOnBadSyntax(language == XSLT_PATTERN ? "XTSE0340" : "XPST0003"); |
| 497 |
qNameParser.setErrorOnUnresolvedPrefix("XPST0081"); |
| 498 |
|
| 499 |
charChecker = env.getConfiguration().getValidCharacterChecker(); |
| 500 |
t = new Tokenizer(); |
| 501 |
t.languageLevel = env.getXPathVersion(); |
| 502 |
allowSaxonExtensions = |
| 503 |
t.allowSaxonExtensions = |
| 504 |
env.getConfiguration().getBooleanProperty(Feature.ALLOW_SYNTAX_EXTENSIONS); |
| 505 |
offset = t.currentTokenStartOffset; |
| 506 |
customizeTokenizer(t); |
| 507 |
try { |
| 508 |
t.tokenize(expression, start, -1); |
| 509 |
} catch (XPathException err) { |
| 510 |
grumble(err.getMessage()); |
| 511 |
} |
| 512 |
if (t.currentToken == terminator) { |
| 513 |
if (allowAbsentExpression) { |
| 514 |
Expression result = Literal.makeEmptySequence(); |
| 515 |
result.setRetainedStaticContext(env.makeRetainedStaticContext()); |
| 516 |
setLocation(result); |
| 517 |
return result; |
| 518 |
} else { |
| 519 |
grumble("The expression is empty"); |
| 520 |
} |
| 521 |
} |
| 522 |
exp = parseExpression(); |
| 523 |
if (t.currentToken != terminator) { |
| 524 |
if (t.currentToken == Token.EOF && terminator == Token.RCURLY) { |
| 525 |
grumble("Missing curly brace after expression in value template", "XTSE0350"); |
| 526 |
} else { |
| 527 |
grumble("Unexpected token " + currentTokenDisplay() + " beyond end of expression"); |
| 528 |
} |
| 529 |
} |
| 530 |
setLocation(exp, offset); |
| 531 |
} |
| 532 |
exp.setRetainedStaticContextThoroughly(env.makeRetainedStaticContext()); |
| 533 |
|
| 534 |
return exp; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
protected void customizeTokenizer(Tokenizer t) { |
| 544 |
|
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
public SequenceType parseSequenceType(String input, StaticContext env) throws XPathException { |
| 559 |
this.env = env; |
| 560 |
if (qNameParser == null) { |
| 561 |
qNameParser = new QNameParser(env.getNamespaceResolver()); |
| 562 |
if (languageVersion >= 30) { |
| 563 |
qNameParser.setAcceptEQName(true); |
| 564 |
} |
| 565 |
} |
| 566 |
language = SEQUENCE_TYPE; |
| 567 |
t = new Tokenizer(); |
| 568 |
t.languageLevel = env.getXPathVersion(); |
| 569 |
allowSaxonExtensions = |
| 570 |
t.allowSaxonExtensions = |
| 571 |
env.getConfiguration().getBooleanProperty(Feature.ALLOW_SYNTAX_EXTENSIONS); |
| 572 |
try { |
| 573 |
t.tokenize(input, 0, -1); |
| 574 |
} catch (XPathException err) { |
| 575 |
grumble(err.getMessage()); |
| 576 |
} |
| 577 |
SequenceType req = parseSequenceType(); |
| 578 |
if (t.currentToken != Token.EOF) { |
| 579 |
grumble("Unexpected token " + currentTokenDisplay() + " beyond end of SequenceType"); |
| 580 |
} |
| 581 |
return req; |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
public ItemType parseExtendedItemType(String input, StaticContext env) throws XPathException { |
| 598 |
this.env = env; |
| 599 |
language = EXTENDED_ITEM_TYPE; |
| 600 |
t = new Tokenizer(); |
| 601 |
t.languageLevel = env.getXPathVersion(); |
| 602 |
allowSaxonExtensions = t.allowSaxonExtensions = true; |
| 603 |
try { |
| 604 |
t.tokenize(input, 0, -1); |
| 605 |
} catch (XPathException err) { |
| 606 |
grumble(err.getMessage()); |
| 607 |
} |
| 608 |
ItemType req = parseItemType(); |
| 609 |
if (t.currentToken != Token.EOF) { |
| 610 |
grumble("Unexpected token " + currentTokenDisplay() + " beyond end of ItemType"); |
| 611 |
} |
| 612 |
return req; |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
public SequenceType parseExtendedSequenceType(String input, StaticContext env) throws XPathException { |
| 627 |
this.env = env; |
| 628 |
language = EXTENDED_ITEM_TYPE; |
| 629 |
t = new Tokenizer(); |
| 630 |
t.languageLevel = env.getXPathVersion(); |
| 631 |
allowSaxonExtensions = t.allowSaxonExtensions = true; |
| 632 |
try { |
| 633 |
t.tokenize(input, 0, -1); |
| 634 |
} catch (XPathException err) { |
| 635 |
grumble(err.getMessage()); |
| 636 |
} |
| 637 |
SequenceType req = parseSequenceType(); |
| 638 |
if (t.currentToken != Token.EOF) { |
| 639 |
grumble("Unexpected token " + currentTokenDisplay() + " beyond end of SequenceType"); |
| 640 |
} |
| 641 |
return req; |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
public Expression parseExpression() throws XPathException { |
| 659 |
int offset = t.currentTokenStartOffset; |
| 660 |
Expression exp = parseExprSingle(); |
| 661 |
ArrayList<Expression> list = null; |
| 662 |
while (t.currentToken == Token.COMMA) { |
| 663 |
|
| 664 |
|
| 665 |
if (list == null) { |
| 666 |
list = new ArrayList<>(10); |
| 667 |
list.add(exp); |
| 668 |
} |
| 669 |
nextToken(); |
| 670 |
Expression next = parseExprSingle(); |
| 671 |
setLocation(next); |
| 672 |
list.add(next); |
| 673 |
} |
| 674 |
if (list != null) { |
| 675 |
exp = Block.makeBlock(list); |
| 676 |
setLocation(exp, offset); |
| 677 |
} |
| 678 |
return exp; |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
public Expression parseExprSingle() throws XPathException { |
| 690 |
Expression e = parserExtension.parseExtendedExprSingle(this); |
| 691 |
if (e != null) { |
| 692 |
return e; |
| 693 |
} |
| 694 |
|
| 695 |
int peek = t.peekAhead(); |
| 696 |
if (peek == Token.EOF || peek == Token.COMMA || peek == Token.RPAR || peek == Token.RSQB) { |
| 697 |
switch (t.currentToken) { |
| 698 |
case Token.STRING_LITERAL: |
| 699 |
return parseStringLiteral(true); |
| 700 |
case Token.NUMBER: |
| 701 |
return parseNumericLiteral(true); |
| 702 |
case Token.NAME: |
| 703 |
case Token.PREFIX: |
| 704 |
case Token.SUFFIX: |
| 705 |
case Token.STAR: |
| 706 |
return parseBasicStep(true); |
| 707 |
case Token.DOT: |
| 708 |
nextToken(); |
| 709 |
Expression cie = new ContextItemExpression(); |
| 710 |
setLocation(cie); |
| 711 |
return cie; |
| 712 |
case Token.DOTDOT: |
| 713 |
nextToken(); |
| 714 |
Expression pne = new AxisExpression(AxisInfo.PARENT, null); |
| 715 |
setLocation(pne); |
| 716 |
return pne; |
| 717 |
case Token.EOF: |
| 718 |
|
| 719 |
default: |
| 720 |
} |
| 721 |
} |
| 722 |
switch (t.currentToken) { |
| 723 |
case Token.EOF: |
| 724 |
grumble("Expected an expression, but reached the end of the input"); |
| 725 |
case Token.FOR: |
| 726 |
case Token.LET: |
| 727 |
case Token.FOR_SLIDING: |
| 728 |
case Token.FOR_TUMBLING: |
| 729 |
return parseFLWORExpression(); |
| 730 |
case Token.SOME: |
| 731 |
case Token.EVERY: |
| 732 |
return parseQuantifiedExpression(); |
| 733 |
case Token.IF: |
| 734 |
return parseIfExpression(); |
| 735 |
case Token.SWITCH: |
| 736 |
return parseSwitchExpression(); |
| 737 |
case Token.TYPESWITCH: |
| 738 |
return parseTypeswitchExpression(); |
| 739 |
case Token.VALIDATE: |
| 740 |
case Token.VALIDATE_STRICT: |
| 741 |
case Token.VALIDATE_LAX: |
| 742 |
case Token.VALIDATE_TYPE: |
| 743 |
return parseValidateExpression(); |
| 744 |
case Token.PRAGMA: |
| 745 |
return parseExtensionExpression(); |
| 746 |
case Token.KEYWORD_CURLY: |
| 747 |
if (t.currentTokenValue.equals("try")) { |
| 748 |
return parseTryCatchExpression(); |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
default: |
| 753 |
return parseBinaryExpression(parseUnaryExpression(), 4); |
| 754 |
} |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
public Expression parseBinaryExpression(Expression lhs, int minPrecedence) throws XPathException { |
| 774 |
while (getCurrentOperatorPrecedence() >= minPrecedence) { |
| 775 |
int offset = t.currentTokenStartOffset; |
| 776 |
int operator = t.currentToken; |
| 777 |
int prec = getCurrentOperatorPrecedence(); |
| 778 |
switch (operator) { |
| 779 |
case Token.INSTANCE_OF: |
| 780 |
case Token.TREAT_AS: |
| 781 |
nextToken(); |
| 782 |
SequenceType seq = parseSequenceType(); |
| 783 |
lhs = makeSequenceTypeExpression(lhs, operator, seq); |
| 784 |
setLocation(lhs, offset); |
| 785 |
if (getCurrentOperatorPrecedence() >= prec) { |
| 786 |
grumble("Left operand of '" + Token.tokens[t.currentToken] + "' needs parentheses"); |
| 787 |
} |
| 788 |
break; |
| 789 |
case Token.CAST_AS: |
| 790 |
case Token.CASTABLE_AS: |
| 791 |
nextToken(); |
| 792 |
SimpleType at; |
| 793 |
if (allowSaxonExtensions && t.currentToken == Token.NODEKIND && t.currentTokenValue.equals("union")) { |
| 794 |
|
| 795 |
at = (SimpleType)parseItemType(); |
| 796 |
} else { |
| 797 |
expect(Token.NAME); |
| 798 |
at = getSimpleType(t.currentTokenValue); |
| 799 |
if (at == ANY_ATOMIC) { |
| 800 |
grumble("No value is castable to xs:anyAtomicType", "XPST0080"); |
| 801 |
} |
| 802 |
if (at == NOTATION) { |
| 803 |
grumble("No value is castable to xs:NOTATION", "XPST0080"); |
| 804 |
} |
| 805 |
nextToken(); |
| 806 |
} |
| 807 |
|
| 808 |
boolean allowEmpty = t.currentToken == Token.QMARK; |
| 809 |
if (allowEmpty) { |
| 810 |
nextToken(); |
| 811 |
} |
| 812 |
lhs = makeSingleTypeExpression(lhs, operator, at, allowEmpty); |
| 813 |
setLocation(lhs, offset); |
| 814 |
if (getCurrentOperatorPrecedence() >= prec) { |
| 815 |
grumble("Left operand of '" + Token.tokens[t.currentToken] + "' needs parentheses"); |
| 816 |
} |
| 817 |
break; |
| 818 |
case Token.ARROW: |
| 819 |
lhs = parseArrowPostfix(lhs); |
| 820 |
break; |
| 821 |
default: |
| 822 |
nextToken(); |
| 823 |
Expression rhs = parseUnaryExpression(); |
| 824 |
while (getCurrentOperatorPrecedence() > prec) { |
| 825 |
rhs = parseBinaryExpression(rhs, getCurrentOperatorPrecedence()); |
| 826 |
} |
| 827 |
if (getCurrentOperatorPrecedence() == prec && !allowMultipleOperators()) { |
| 828 |
String tok = Token.tokens[t.currentToken]; |
| 829 |
String message = "Left operand of '" + Token.tokens[t.currentToken] + "' needs parentheses"; |
| 830 |
if (tok.equals("<") || tok.equals(">")) { |
| 831 |
|
| 832 |
message += ". Or perhaps an XQuery element constructor appears where it is not allowed"; |
| 833 |
} |
| 834 |
grumble(message); |
| 835 |
} |
| 836 |
lhs = makeBinaryExpression(lhs, operator, rhs); |
| 837 |
setLocation(lhs, offset); |
| 838 |
} |
| 839 |
} |
| 840 |
return lhs; |
| 841 |
} |
| 842 |
|
| 843 |
private boolean allowMultipleOperators() { |
| 844 |
switch (t.currentToken) { |
| 845 |
case Token.FEQ: |
| 846 |
case Token.FNE: |
| 847 |
case Token.FLE: |
| 848 |
case Token.FLT: |
| 849 |
case Token.FGE: |
| 850 |
case Token.FGT: |
| 851 |
case Token.EQUALS: |
| 852 |
case Token.NE: |
| 853 |
case Token.LE: |
| 854 |
case Token.LT: |
| 855 |
case Token.GE: |
| 856 |
case Token.GT: |
| 857 |
case Token.IS: |
| 858 |
case Token.PRECEDES: |
| 859 |
case Token.FOLLOWS: |
| 860 |
case Token.TO: |
| 861 |
return false; |
| 862 |
default: |
| 863 |
return true; |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
private int getCurrentOperatorPrecedence() { |
| 868 |
return operatorPrecedence(t.currentToken); |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
public static int operatorPrecedence(int operator) { |
| 878 |
switch (operator) { |
| 879 |
case Token.OR: |
| 880 |
case Token.OR_ELSE: |
| 881 |
return 4; |
| 882 |
case Token.AND: |
| 883 |
case Token.AND_ALSO: |
| 884 |
return 5; |
| 885 |
case Token.FEQ: |
| 886 |
case Token.FNE: |
| 887 |
case Token.FLE: |
| 888 |
case Token.FLT: |
| 889 |
case Token.FGE: |
| 890 |
case Token.FGT: |
| 891 |
case Token.EQUALS: |
| 892 |
case Token.NE: |
| 893 |
case Token.LE: |
| 894 |
case Token.LT: |
| 895 |
case Token.GE: |
| 896 |
case Token.GT: |
| 897 |
case Token.IS: |
| 898 |
case Token.PRECEDES: |
| 899 |
case Token.FOLLOWS: |
| 900 |
return 6; |
| 901 |
case Token.CONCAT: |
| 902 |
return 7; |
| 903 |
case Token.TO: |
| 904 |
return 8; |
| 905 |
case Token.PLUS: |
| 906 |
case Token.MINUS: |
| 907 |
return 9; |
| 908 |
case Token.MULT: |
| 909 |
case Token.DIV: |
| 910 |
case Token.IDIV: |
| 911 |
case Token.MOD: |
| 912 |
return 10; |
| 913 |
case Token.UNION: |
| 914 |
return 11; |
| 915 |
case Token.INTERSECT: |
| 916 |
case Token.EXCEPT: |
| 917 |
return 12; |
| 918 |
case Token.INSTANCE_OF: |
| 919 |
return 13; |
| 920 |
case Token.TREAT_AS: |
| 921 |
return 14; |
| 922 |
case Token.CASTABLE_AS: |
| 923 |
return 15; |
| 924 |
case Token.CAST_AS: |
| 925 |
return 16; |
| 926 |
case Token.ARROW: |
| 927 |
return 17; |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
default: |
| 938 |
return -1; |
| 939 |
} |
| 940 |
} |
| 941 |
|
| 942 |
|
| 943 |
private Expression makeBinaryExpression(Expression lhs, int operator, Expression rhs) throws XPathException { |
| 944 |
switch (operator) { |
| 945 |
case Token.OR: |
| 946 |
return new OrExpression(lhs, rhs); |
| 947 |
case Token.AND: |
| 948 |
return new AndExpression(lhs, rhs); |
| 949 |
case Token.FEQ: |
| 950 |
case Token.FNE: |
| 951 |
case Token.FLE: |
| 952 |
case Token.FLT: |
| 953 |
case Token.FGE: |
| 954 |
case Token.FGT: |
| 955 |
return new ValueComparison(lhs, operator, rhs); |
| 956 |
case Token.EQUALS: |
| 957 |
case Token.NE: |
| 958 |
case Token.LE: |
| 959 |
case Token.LT: |
| 960 |
case Token.GE: |
| 961 |
case Token.GT: |
| 962 |
return env.getConfiguration().getTypeChecker(env.isInBackwardsCompatibleMode()).makeGeneralComparison(lhs, operator, rhs); |
| 963 |
case Token.IS: |
| 964 |
case Token.PRECEDES: |
| 965 |
case Token.FOLLOWS: |
| 966 |
return new IdentityComparison(lhs, operator, rhs); |
| 967 |
case Token.TO: |
| 968 |
return new RangeExpression(lhs, rhs); |
| 969 |
case Token.CONCAT: { |
| 970 |
if (!allowXPath30Syntax) { |
| 971 |
grumble("Concatenation operator ('||') requires XPath 3.0 to be enabled"); |
| 972 |
} |
| 973 |
RetainedStaticContext rsc = new RetainedStaticContext(env); |
| 974 |
if (lhs.isCallOn(Concat.class)) { |
| 975 |
Expression[] args = ((SystemFunctionCall) lhs).getArguments(); |
| 976 |
Expression[] newArgs = new Expression[args.length + 1]; |
| 977 |
System.arraycopy(args, 0, newArgs, 0, args.length); |
| 978 |
newArgs[args.length] = rhs; |
| 979 |
return SystemFunction.makeCall("concat", rsc, newArgs); |
| 980 |
} else { |
| 981 |
return SystemFunction.makeCall("concat", rsc, lhs, rhs); |
| 982 |
} |
| 983 |
} |
| 984 |
case Token.PLUS: |
| 985 |
case Token.MINUS: |
| 986 |
case Token.MULT: |
| 987 |
case Token.DIV: |
| 988 |
case Token.IDIV: |
| 989 |
case Token.MOD: |
| 990 |
return env.getConfiguration().getTypeChecker(env.isInBackwardsCompatibleMode()).makeArithmeticExpression(lhs, operator, rhs); |
| 991 |
case Token.UNION: |
| 992 |
case Token.INTERSECT: |
| 993 |
case Token.EXCEPT: |
| 994 |
return new VennExpression(lhs, operator, rhs); |
| 995 |
case Token.OR_ELSE: { |
| 996 |
RetainedStaticContext rsc = new RetainedStaticContext(env); |
| 997 |
rhs = SystemFunction.makeCall("boolean", rsc, rhs); |
| 998 |
return Choose.makeConditional(lhs, Literal.makeLiteral(BooleanValue.TRUE), rhs); |
| 999 |
} |
| 1000 |
case Token.AND_ALSO: { |
| 1001 |
RetainedStaticContext rsc = new RetainedStaticContext(env); |
| 1002 |
rhs = SystemFunction.makeCall("boolean", rsc, rhs); |
| 1003 |
return Choose.makeConditional(lhs, rhs, Literal.makeLiteral(BooleanValue.FALSE)); |
| 1004 |
} |
| 1005 |
default: |
| 1006 |
throw new IllegalArgumentException(Token.tokens[operator]); |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
private Expression makeSequenceTypeExpression(Expression lhs, int operator, SequenceType type) { |
| 1011 |
switch (operator) { |
| 1012 |
case Token.INSTANCE_OF: |
| 1013 |
return new InstanceOfExpression(lhs, type); |
| 1014 |
case Token.TREAT_AS: |
| 1015 |
return TreatExpression.make(lhs, type); |
| 1016 |
default: |
| 1017 |
throw new IllegalArgumentException(); |
| 1018 |
} |
| 1019 |
|
| 1020 |
} |
| 1021 |
|
| 1022 |
private Expression makeSingleTypeExpression(Expression lhs, int operator, SimpleType type, boolean allowEmpty) |
| 1023 |
throws XPathException { |
| 1024 |
if (type instanceof AtomicType && !(type == ErrorType.getInstance())) { |
| 1025 |
switch (operator) { |
| 1026 |
case Token.CASTABLE_AS: |
| 1027 |
CastableExpression castable = new CastableExpression(lhs, (AtomicType) type, allowEmpty); |
| 1028 |
if (lhs instanceof StringLiteral) { |
| 1029 |
castable.setOperandIsStringLiteral(true); |
| 1030 |
} |
| 1031 |
return castable; |
| 1032 |
|
| 1033 |
case Token.CAST_AS: |
| 1034 |
CastExpression cast = new CastExpression(lhs, (AtomicType) type, allowEmpty); |
| 1035 |
if (lhs instanceof StringLiteral) { |
| 1036 |
cast.setOperandIsStringLiteral(true); |
| 1037 |
} |
| 1038 |
return cast; |
| 1039 |
|
| 1040 |
default: |
| 1041 |
throw new IllegalArgumentException(); |
| 1042 |
} |
| 1043 |
} else if (allowXPath30Syntax) { |
| 1044 |
switch (operator) { |
| 1045 |
case Token.CASTABLE_AS: |
| 1046 |
if (type.isUnionType()) { |
| 1047 |
NamespaceResolver resolver = env.getNamespaceResolver(); |
| 1048 |
UnionCastableFunction ucf = new UnionCastableFunction((UnionType) type, resolver, allowEmpty); |
| 1049 |
return new StaticFunctionCall(ucf, new Expression[]{lhs}); |
| 1050 |
} else if (type.isListType()) { |
| 1051 |
NamespaceResolver resolver = env.getNamespaceResolver(); |
| 1052 |
ListCastableFunction lcf = new ListCastableFunction((ListType) type, resolver, allowEmpty); |
| 1053 |
return new StaticFunctionCall(lcf, new Expression[]{lhs}); |
| 1054 |
} |
| 1055 |
break; |
| 1056 |
case Token.CAST_AS: |
| 1057 |
if (type.isUnionType()) { |
| 1058 |
NamespaceResolver resolver = env.getNamespaceResolver(); |
| 1059 |
UnionConstructorFunction ucf = new UnionConstructorFunction((UnionType) type, resolver, allowEmpty); |
| 1060 |
return new StaticFunctionCall(ucf, new Expression[]{lhs}); |
| 1061 |
} else if (type.isListType()) { |
| 1062 |
NamespaceResolver resolver = env.getNamespaceResolver(); |
| 1063 |
ListConstructorFunction lcf = new ListConstructorFunction((ListType) type, resolver, allowEmpty); |
| 1064 |
return new StaticFunctionCall(lcf, new Expression[]{lhs}); |
| 1065 |
} |
| 1066 |
break; |
| 1067 |
default: |
| 1068 |
throw new IllegalArgumentException(); |
| 1069 |
} |
| 1070 |
if (type == AnySimpleType.getInstance()) { |
| 1071 |
throw new XPathException("Cannot cast to xs:anySimpleType", "XPST0080"); |
| 1072 |
} else { |
| 1073 |
throw new XPathException("Cannot cast to " + type.getDescription(), "XPST0051"); |
| 1074 |
} |
| 1075 |
} else { |
| 1076 |
throw new XPathException("Casting to list or union types requires XPath 3.0 to be enabled", "XPST0051"); |
| 1077 |
} |
| 1078 |
|
| 1079 |
} |
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
protected Expression parseTypeswitchExpression() throws XPathException { |
| 1092 |
grumble("typeswitch is not allowed in XPath"); |
| 1093 |
return new ErrorExpression(); |
| 1094 |
} |
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
protected Expression parseSwitchExpression() throws XPathException { |
| 1109 |
grumble("switch is not allowed in XPath"); |
| 1110 |
return new ErrorExpression(); |
| 1111 |
} |
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
protected Expression parseValidateExpression() throws XPathException { |
| 1125 |
grumble("validate{} expressions are not allowed in XPath"); |
| 1126 |
return new ErrorExpression(); |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
protected Expression parseExtensionExpression() throws XPathException { |
| 1141 |
grumble("extension expressions (#...#) are not allowed in XPath"); |
| 1142 |
return new ErrorExpression(); |
| 1143 |
} |
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
protected Expression parseTryCatchExpression() throws XPathException { |
| 1158 |
grumble("try/catch expressions are not allowed in XPath"); |
| 1159 |
return new ErrorExpression(); |
| 1160 |
} |
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
protected Expression parseFLWORExpression() throws XPathException { |
| 1173 |
if (t.currentToken == Token.LET && !allowXPath30Syntax) { |
| 1174 |
grumble("'let' is not permitted in XPath 2.0"); |
| 1175 |
} |
| 1176 |
if (t.currentToken == Token.FOR_SLIDING || t.currentToken == Token.FOR_TUMBLING) { |
| 1177 |
grumble("sliding/tumbling windows can only be used in XQuery"); |
| 1178 |
} |
| 1179 |
int clauses = 0; |
| 1180 |
int offset; |
| 1181 |
int operator = t.currentToken; |
| 1182 |
Assignation first = null; |
| 1183 |
Assignation previous = null; |
| 1184 |
do { |
| 1185 |
offset = t.currentTokenStartOffset; |
| 1186 |
nextToken(); |
| 1187 |
expect(Token.DOLLAR); |
| 1188 |
nextToken(); |
| 1189 |
expect(Token.NAME); |
| 1190 |
String var = t.currentTokenValue; |
| 1191 |
|
| 1192 |
|
| 1193 |
Assignation v; |
| 1194 |
if (operator == Token.FOR) { |
| 1195 |
v = new ForExpression(); |
| 1196 |
v.setRequiredType(SequenceType.SINGLE_ITEM); |
| 1197 |
} else { |
| 1198 |
v = new LetExpression(); |
| 1199 |
v.setRequiredType(SequenceType.ANY_SEQUENCE); |
| 1200 |
} |
| 1201 |
|
| 1202 |
clauses++; |
| 1203 |
setLocation(v, offset); |
| 1204 |
v.setVariableQName(makeStructuredQName(var, "")); |
| 1205 |
nextToken(); |
| 1206 |
|
| 1207 |
|
| 1208 |
expect(operator == Token.LET ? Token.ASSIGN : Token.IN); |
| 1209 |
nextToken(); |
| 1210 |
v.setSequence(parseExprSingle()); |
| 1211 |
declareRangeVariable(v); |
| 1212 |
if (previous == null) { |
| 1213 |
first = v; |
| 1214 |
} else { |
| 1215 |
previous.setAction(v); |
| 1216 |
} |
| 1217 |
previous = v; |
| 1218 |
|
| 1219 |
} while (t.currentToken == Token.COMMA); |
| 1220 |
|
| 1221 |
|
| 1222 |
expect(Token.RETURN); |
| 1223 |
nextToken(); |
| 1224 |
previous.setAction(parseExprSingle()); |
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
for (int i = 0; i < clauses; i++) { |
| 1229 |
undeclareRangeVariable(); |
| 1230 |
} |
| 1231 |
return makeTracer(offset, first, LocationKind.FOR_EXPRESSION, first.getVariableQName()); |
| 1232 |
} |
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
private Expression parseQuantifiedExpression() throws XPathException { |
| 1243 |
int clauses = 0; |
| 1244 |
int operator = t.currentToken; |
| 1245 |
QuantifiedExpression first = null; |
| 1246 |
QuantifiedExpression previous = null; |
| 1247 |
int initialOffset = t.currentTokenStartOffset; |
| 1248 |
do { |
| 1249 |
int offset = t.currentTokenStartOffset; |
| 1250 |
nextToken(); |
| 1251 |
expect(Token.DOLLAR); |
| 1252 |
nextToken(); |
| 1253 |
expect(Token.NAME); |
| 1254 |
String var = t.currentTokenValue; |
| 1255 |
clauses++; |
| 1256 |
|
| 1257 |
|
| 1258 |
QuantifiedExpression v = new QuantifiedExpression(); |
| 1259 |
v.setRequiredType(SequenceType.SINGLE_ITEM); |
| 1260 |
v.setOperator(operator); |
| 1261 |
setLocation(v, offset); |
| 1262 |
|
| 1263 |
v.setVariableQName(makeStructuredQName(var, "")); |
| 1264 |
nextToken(); |
| 1265 |
|
| 1266 |
if (t.currentToken == Token.AS && language == XQUERY) { |
| 1267 |
|
| 1268 |
nextToken(); |
| 1269 |
SequenceType type = parseSequenceType(); |
| 1270 |
if (type.getCardinality() != StaticProperty.EXACTLY_ONE) { |
| 1271 |
warning("Occurrence indicator on singleton range variable has no effect"); |
| 1272 |
type = SequenceType.makeSequenceType(type.getPrimaryType(), StaticProperty.EXACTLY_ONE); |
| 1273 |
} |
| 1274 |
v.setRequiredType(type); |
| 1275 |
} |
| 1276 |
|
| 1277 |
|
| 1278 |
expect(Token.IN); |
| 1279 |
nextToken(); |
| 1280 |
v.setSequence(parseExprSingle()); |
| 1281 |
declareRangeVariable(v); |
| 1282 |
if (previous != null) { |
| 1283 |
previous.setAction(v); |
| 1284 |
} else { |
| 1285 |
first = v; |
| 1286 |
} |
| 1287 |
previous = v; |
| 1288 |
|
| 1289 |
} while (t.currentToken == Token.COMMA); |
| 1290 |
|
| 1291 |
|
| 1292 |
expect(Token.SATISFIES); |
| 1293 |
nextToken(); |
| 1294 |
previous.setAction(parseExprSingle()); |
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
for (int i = 0; i < clauses; i++) { |
| 1300 |
undeclareRangeVariable(); |
| 1301 |
} |
| 1302 |
return makeTracer(initialOffset, first, LocationKind.FOR_EXPRESSION, first.getVariableQName()); |
| 1303 |
|
| 1304 |
} |
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
private Expression parseIfExpression() throws XPathException { |
| 1316 |
|
| 1317 |
int ifoffset = t.currentTokenStartOffset; |
| 1318 |
nextToken(); |
| 1319 |
Expression condition = parseExpression(); |
| 1320 |
expect(Token.RPAR); |
| 1321 |
nextToken(); |
| 1322 |
int thenoffset = t.currentTokenStartOffset; |
| 1323 |
expect(Token.THEN); |
| 1324 |
nextToken(); |
| 1325 |
Expression thenExp = makeTracer(thenoffset, parseExprSingle(), LocationKind.THEN_EXPRESSION, null); |
| 1326 |
int elseoffset = t.currentTokenStartOffset; |
| 1327 |
expect(Token.ELSE); |
| 1328 |
nextToken(); |
| 1329 |
Expression elseExp = makeTracer(elseoffset, parseExprSingle(), LocationKind.ELSE_EXPRESSION, null); |
| 1330 |
Expression ifExp = Choose.makeConditional(condition, thenExp, elseExp); |
| 1331 |
setLocation(ifExp, ifoffset); |
| 1332 |
return makeTracer(ifoffset, ifExp, LocationKind.IF_EXPRESSION, null); |
| 1333 |
} |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
private ItemType getPlainType(String qname) throws XPathException { |
| 1346 |
if (scanOnly) { |
| 1347 |
return STRING; |
| 1348 |
} |
| 1349 |
qNameParser.setDefaultNamespace(env.getDefaultElementNamespace()); |
| 1350 |
StructuredQName sq = null; |
| 1351 |
try { |
| 1352 |
sq = qNameParser.parse(qname); |
| 1353 |
} catch (XPathException e) { |
| 1354 |
grumble(e.getMessage(), e.getErrorCodeLocalPart()); |
| 1355 |
} |
| 1356 |
return getPlainType(sq); |
| 1357 |
} |
| 1358 |
|
| 1359 |
public ItemType getPlainType(StructuredQName sq) throws XPathException { |
| 1360 |
Configuration config = env.getConfiguration(); |
| 1361 |
String uri = sq.getURI(); |
| 1362 |
if (uri.isEmpty()) { |
| 1363 |
uri = env.getDefaultElementNamespace(); |
| 1364 |
} |
| 1365 |
String local = sq.getLocalPart(); |
| 1366 |
String qname = sq.getDisplayName(); |
| 1367 |
|
| 1368 |
boolean builtInNamespace = uri.equals(NamespaceConstant.SCHEMA); |
| 1369 |
|
| 1370 |
if (builtInNamespace) { |
| 1371 |
ItemType t = Type.getBuiltInItemType(uri, local); |
| 1372 |
if (t == null) { |
| 1373 |
grumble("Unknown atomic type " + qname, "XPST0051"); |
| 1374 |
assert false; |
| 1375 |
} |
| 1376 |
if (t instanceof BuiltInAtomicType) { |
| 1377 |
checkAllowedType(env, (BuiltInAtomicType) t); |
| 1378 |
return t; |
| 1379 |
} else if (t.isPlainType()) { |
| 1380 |
return t; |
| 1381 |
} else { |
| 1382 |
grumble("The type " + qname + " is not atomic", "XPST0051"); |
| 1383 |
assert false; |
| 1384 |
} |
| 1385 |
} else if (uri.equals(NamespaceConstant.JAVA_TYPE)) { |
| 1386 |
Class theClass; |
| 1387 |
try { |
| 1388 |
String className = JavaExternalObjectType.localNameToClassName(local); |
| 1389 |
theClass = config.getClass(className, false, null); |
| 1390 |
} catch (XPathException err) { |
| 1391 |
grumble("Unknown Java class " + local, "XPST0051"); |
| 1392 |
return AnyItemType.getInstance(); |
| 1393 |
} |
| 1394 |
return config.getJavaExternalObjectType(theClass); |
| 1395 |
} else if (uri.equals(NamespaceConstant.DOT_NET_TYPE)) { |
| 1396 |
return Version.platform.getExternalObjectType(config, uri, local); |
| 1397 |
} else { |
| 1398 |
SchemaType st = config.getSchemaType(sq); |
| 1399 |
if (st == null) { |
| 1400 |
grumble("Unknown simple type " + qname, "XPST0051"); |
| 1401 |
} else if (st.isAtomicType()) { |
| 1402 |
if (!env.isImportedSchema(uri)) { |
| 1403 |
grumble("Atomic type " + qname + " exists, but its schema definition has not been imported", "XPST0051"); |
| 1404 |
} |
| 1405 |
return (AtomicType) st; |
| 1406 |
} else if (st instanceof ItemType && ((ItemType) st).isPlainType() && allowXPath30Syntax) { |
| 1407 |
if (!env.isImportedSchema(uri)) { |
| 1408 |
grumble("Type " + qname + " exists, but its schema definition has not been imported", "XPST0051"); |
| 1409 |
} |
| 1410 |
return (ItemType) st; |
| 1411 |
} else if (st.isComplexType()) { |
| 1412 |
grumble("Type (" + qname + ") is a complex type", "XPST0051"); |
| 1413 |
return ANY_ATOMIC; |
| 1414 |
} else if (((SimpleType) st).isListType()) { |
| 1415 |
grumble("Type (" + qname + ") is a list type", "XPST0051"); |
| 1416 |
return ANY_ATOMIC; |
| 1417 |
} else if (allowXPath30Syntax) { |
| 1418 |
grumble("Type (" + qname + ") is a union type that cannot be used as an item type", "XPST0051"); |
| 1419 |
return ANY_ATOMIC; |
| 1420 |
} else { |
| 1421 |
grumble("The union type (" + qname + ") cannot be used as an item type unless XPath 3.0 is enabled", "XPST0051"); |
| 1422 |
return ANY_ATOMIC; |
| 1423 |
} |
| 1424 |
} |
| 1425 |
grumble("Unknown atomic type " + qname, "XPST0051"); |
| 1426 |
return ANY_ATOMIC; |
| 1427 |
} |
| 1428 |
|
| 1429 |
private void checkAllowedType(StaticContext env, BuiltInAtomicType type) throws XPathException { |
| 1430 |
String s = whyDisallowedType(env.getPackageData(), type); |
| 1431 |
if (s != null) { |
| 1432 |
grumble(s, "XPST0080"); |
| 1433 |
} |
| 1434 |
} |
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
public static String whyDisallowedType(PackageData pack, BuiltInAtomicType type) { |
| 1446 |
if (!type.isAllowedInXSD10() && pack.getConfiguration().getXsdVersion() == Configuration.XSD10) { |
| 1447 |
return "The built-in atomic type " + type.getDisplayName() + " is not recognized unless XSD 1.1 is enabled"; |
| 1448 |
} |
| 1449 |
return null; |
| 1450 |
} |
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
private SimpleType getSimpleType( String qname) throws XPathException { |
| 1464 |
if (scanOnly) { |
| 1465 |
return STRING; |
| 1466 |
} |
| 1467 |
qNameParser.setDefaultNamespace(env.getDefaultElementNamespace()); |
| 1468 |
StructuredQName sq = null; |
| 1469 |
try { |
| 1470 |
sq = qNameParser.parse(qname); |
| 1471 |
} catch (XPathException e) { |
| 1472 |
grumble(e.getMessage(), e.getErrorCodeLocalPart()); |
| 1473 |
assert false; |
| 1474 |
} |
| 1475 |
String uri = sq.getURI(); |
| 1476 |
String local = sq.getLocalPart(); |
| 1477 |
|
| 1478 |
boolean builtInNamespace = uri.equals(NamespaceConstant.SCHEMA); |
| 1479 |
if (builtInNamespace) { |
| 1480 |
SimpleType t = Type.getBuiltInSimpleType(uri, local); |
| 1481 |
if (t == null) { |
| 1482 |
if (allowXPath30Syntax) { |
| 1483 |
grumble("Unknown simple type " + qname, "XQST0052"); |
| 1484 |
} else { |
| 1485 |
grumble("Unknown simple type " + qname, "XPST0051"); |
| 1486 |
} |
| 1487 |
} |
| 1488 |
if (t instanceof BuiltInAtomicType) { |
| 1489 |
checkAllowedType(env, (BuiltInAtomicType) t); |
| 1490 |
} |
| 1491 |
return t; |
| 1492 |
} else if (uri.equals(NamespaceConstant.DOT_NET_TYPE)) { |
| 1493 |
return (AtomicType) Version.platform.getExternalObjectType(env.getConfiguration(), uri, local); |
| 1494 |
|
| 1495 |
} else { |
| 1496 |
|
| 1497 |
SchemaType st = env.getConfiguration().getSchemaType(new StructuredQName("", uri, local)); |
| 1498 |
if (st == null) { |
| 1499 |
if (allowXPath30Syntax) { |
| 1500 |
grumble("Unknown simple type " + qname, "XQST0052"); |
| 1501 |
} else { |
| 1502 |
grumble("Unknown simple type " + qname, "XPST0051"); |
| 1503 |
} |
| 1504 |
return ANY_ATOMIC; |
| 1505 |
} |
| 1506 |
if (allowXPath30Syntax) { |
| 1507 |
|
| 1508 |
if (!env.isImportedSchema(uri)) { |
| 1509 |
grumble("Simple type " + qname + " exists, but its target namespace has not been imported in the static context"); |
| 1510 |
} |
| 1511 |
return (SimpleType) st; |
| 1512 |
|
| 1513 |
} else { |
| 1514 |
|
| 1515 |
if (st.isAtomicType()) { |
| 1516 |
if (!env.isImportedSchema(uri)) { |
| 1517 |
grumble("Atomic type " + qname + " exists, but its target namespace has not been imported in the static context"); |
| 1518 |
} |
| 1519 |
return (AtomicType) st; |
| 1520 |
} else if (st.isComplexType()) { |
| 1521 |
grumble("Cannot cast to a complex type (" + qname + ")", "XPST0051"); |
| 1522 |
return ANY_ATOMIC; |
| 1523 |
} else if (((SimpleType) st).isListType()) { |
| 1524 |
grumble("Casting to a list type (" + qname + ") requires XPath 3.0", "XPST0051"); |
| 1525 |
return ANY_ATOMIC; |
| 1526 |
} else { |
| 1527 |
grumble("casting to a union type (" + qname + ") requires XPath 3.0", "XPST0051"); |
| 1528 |
return ANY_ATOMIC; |
| 1529 |
} |
| 1530 |
} |
| 1531 |
} |
| 1532 |
} |
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
public SequenceType parseSequenceType() throws XPathException { |
| 1543 |
boolean disallowIndicator = t.currentTokenValue.equals("empty-sequence"); |
| 1544 |
ItemType primaryType = parseItemType(); |
| 1545 |
if (disallowIndicator) { |
| 1546 |
|
| 1547 |
return SequenceType.makeSequenceType(primaryType, StaticProperty.EMPTY); |
| 1548 |
} |
| 1549 |
int occurrenceFlag; |
| 1550 |
switch (t.currentToken) { |
| 1551 |
case Token.STAR: |
| 1552 |
case Token.MULT: |
| 1553 |
|
| 1554 |
occurrenceFlag = StaticProperty.ALLOWS_ZERO_OR_MORE; |
| 1555 |
|
| 1556 |
t.currentToken = Token.RPAR; |
| 1557 |
nextToken(); |
| 1558 |
break; |
| 1559 |
case Token.PLUS: |
| 1560 |
occurrenceFlag = StaticProperty.ALLOWS_ONE_OR_MORE; |
| 1561 |
|
| 1562 |
t.currentToken = Token.RPAR; |
| 1563 |
nextToken(); |
| 1564 |
break; |
| 1565 |
case Token.QMARK: |
| 1566 |
occurrenceFlag = StaticProperty.ALLOWS_ZERO_OR_ONE; |
| 1567 |
|
| 1568 |
t.currentToken = Token.RPAR; |
| 1569 |
nextToken(); |
| 1570 |
break; |
| 1571 |
default: |
| 1572 |
occurrenceFlag = StaticProperty.EXACTLY_ONE; |
| 1573 |
} |
| 1574 |
return SequenceType.makeSequenceType(primaryType, occurrenceFlag); |
| 1575 |
} |
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
public ItemType parseItemType() throws XPathException { |
| 1586 |
ItemType extended = parserExtension.parseExtendedItemType(this); |
| 1587 |
return extended == null ? parseSimpleItemType() : extended; |
| 1588 |
} |
| 1589 |
|
| 1590 |
private ItemType parseSimpleItemType() throws XPathException { |
| 1591 |
ItemType primaryType; |
| 1592 |
if (t.currentToken == Token.LPAR) { |
| 1593 |
primaryType = parseParenthesizedItemType(); |
| 1594 |
|
| 1595 |
} else if (t.currentToken == Token.NAME) { |
| 1596 |
primaryType = getPlainType(t.currentTokenValue); |
| 1597 |
nextToken(); |
| 1598 |
} else if (t.currentToken == Token.NODEKIND) { |
| 1599 |
|
| 1600 |
switch (t.currentTokenValue) { |
| 1601 |
case "item": |
| 1602 |
nextToken(); |
| 1603 |
expect(Token.RPAR); |
| 1604 |
nextToken(); |
| 1605 |
primaryType = AnyItemType.getInstance(); |
| 1606 |
break; |
| 1607 |
case "function": |
| 1608 |
checkLanguageVersion30(); |
| 1609 |
AnnotationList annotations = AnnotationList.EMPTY; |
| 1610 |
primaryType = parseFunctionItemType(annotations); |
| 1611 |
break; |
| 1612 |
case "map": |
| 1613 |
primaryType = parseMapItemType(); |
| 1614 |
break; |
| 1615 |
case "array": |
| 1616 |
primaryType = parseArrayItemType(); |
| 1617 |
break; |
| 1618 |
case "empty-sequence": |
| 1619 |
nextToken(); |
| 1620 |
expect(Token.RPAR); |
| 1621 |
nextToken(); |
| 1622 |
primaryType = ErrorType.getInstance(); |
| 1623 |
break; |
| 1624 |
default: |
| 1625 |
primaryType = parseKindTest(); |
| 1626 |
break; |
| 1627 |
} |
| 1628 |
} else if (t.currentToken == Token.PERCENT) { |
| 1629 |
AnnotationList annotations = parseAnnotationsList(); |
| 1630 |
if (t.currentTokenValue.equals("function")) { |
| 1631 |
primaryType = parseFunctionItemType(annotations); |
| 1632 |
} else { |
| 1633 |
grumble("Expected 'function' to follow annotation assertions, found " + Token.tokens[t.currentToken]); |
| 1634 |
return null; |
| 1635 |
} |
| 1636 |
} else if (language == EXTENDED_ITEM_TYPE && t.currentToken == Token.PREFIX) { |
| 1637 |
String tokv = t.currentTokenValue; |
| 1638 |
nextToken(); |
| 1639 |
return makeNamespaceTest(Type.ELEMENT, tokv); |
| 1640 |
} else if (language == EXTENDED_ITEM_TYPE && t.currentToken == Token.SUFFIX) { |
| 1641 |
nextToken(); |
| 1642 |
expect(Token.NAME); |
| 1643 |
String tokv = t.currentTokenValue; |
| 1644 |
nextToken(); |
| 1645 |
return makeLocalNameTest(Type.ELEMENT, tokv); |
| 1646 |
} else if (language == EXTENDED_ITEM_TYPE && t.currentToken == Token.AT) { |
| 1647 |
nextToken(); |
| 1648 |
if (t.currentToken == Token.PREFIX) { |
| 1649 |
String tokv = t.currentTokenValue; |
| 1650 |
nextToken(); |
| 1651 |
return makeNamespaceTest(Type.ATTRIBUTE, tokv); |
| 1652 |
} else if (t.currentToken == Token.SUFFIX) { |
| 1653 |
nextToken(); |
| 1654 |
expect(Token.NAME); |
| 1655 |
String tokv = t.currentTokenValue; |
| 1656 |
nextToken(); |
| 1657 |
return makeLocalNameTest(Type.ATTRIBUTE, tokv); |
| 1658 |
} else { |
| 1659 |
grumble("Expected NodeTest after '@'"); |
| 1660 |
return ANY_ATOMIC; |
| 1661 |
} |
| 1662 |
} else { |
| 1663 |
grumble("Expected type name in SequenceType, found " + Token.tokens[t.currentToken]); |
| 1664 |
return ANY_ATOMIC; |
| 1665 |
} |
| 1666 |
return primaryType; |
| 1667 |
} |
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
protected ItemType parseFunctionItemType(AnnotationList annotations) throws XPathException { |
| 1680 |
return parserExtension.parseFunctionItemType(this, annotations); |
| 1681 |
} |
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
protected ItemType parseMapItemType() throws XPathException { |
| 1696 |
checkMapExtensions(); |
| 1697 |
Tokenizer t = getTokenizer(); |
| 1698 |
nextToken(); |
| 1699 |
if (t.currentToken == Token.STAR || t.currentToken == Token.MULT) { |
| 1700 |
|
| 1701 |
nextToken(); |
| 1702 |
expect(Token.RPAR); |
| 1703 |
nextToken(); |
| 1704 |
return MapType.ANY_MAP_TYPE; |
| 1705 |
} else { |
| 1706 |
ItemType keyType = parseItemType(); |
| 1707 |
expect(Token.COMMA); |
| 1708 |
nextToken(); |
| 1709 |
SequenceType valueType = parseSequenceType(); |
| 1710 |
expect(Token.RPAR); |
| 1711 |
nextToken(); |
| 1712 |
if (!(keyType instanceof AtomicType)) { |
| 1713 |
grumble("Key type of a map must be atomic"); |
| 1714 |
return null; |
| 1715 |
} |
| 1716 |
return new MapType((AtomicType) keyType, valueType); |
| 1717 |
} |
| 1718 |
} |
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
protected ItemType parseArrayItemType() throws XPathException { |
| 1733 |
checkLanguageVersion31(); |
| 1734 |
Tokenizer t = getTokenizer(); |
| 1735 |
nextToken(); |
| 1736 |
if (t.currentToken == Token.STAR || t.currentToken == Token.MULT) { |
| 1737 |
|
| 1738 |
nextToken(); |
| 1739 |
expect(Token.RPAR); |
| 1740 |
nextToken(); |
| 1741 |
return ArrayItemType.ANY_ARRAY_TYPE; |
| 1742 |
} else { |
| 1743 |
SequenceType memberType = parseSequenceType(); |
| 1744 |
expect(Token.RPAR); |
| 1745 |
nextToken(); |
| 1746 |
return new ArrayItemType(memberType); |
| 1747 |
} |
| 1748 |
} |
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
private ItemType parseParenthesizedItemType() throws XPathException { |
| 1759 |
if (!allowXPath30Syntax) { |
| 1760 |
grumble("Parenthesized item types require 3.0 to be enabled"); |
| 1761 |
} |
| 1762 |
nextToken(); |
| 1763 |
ItemType primaryType = parseItemType(); |
| 1764 |
while (primaryType instanceof NodeTest && language == EXTENDED_ITEM_TYPE && t.currentToken != Token.RPAR) { |
| 1765 |
switch (t.currentToken) { |
| 1766 |
case Token.UNION: |
| 1767 |
case Token.EXCEPT: |
| 1768 |
case Token.INTERSECT: |
| 1769 |
int op = t.currentToken; |
| 1770 |
nextToken(); |
| 1771 |
primaryType = new CombinedNodeTest((NodeTest) primaryType, op, (NodeTest) parseItemType()); |
| 1772 |
} |
| 1773 |
} |
| 1774 |
expect(Token.RPAR); |
| 1775 |
nextToken(); |
| 1776 |
return primaryType; |
| 1777 |
} |
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
private Expression parseUnaryExpression() throws XPathException { |
| 1791 |
Expression exp; |
| 1792 |
switch (t.currentToken) { |
| 1793 |
case Token.MINUS: { |
| 1794 |
nextToken(); |
| 1795 |
Expression operand = parseUnaryExpression(); |
| 1796 |
exp = makeUnaryExpression(Token.NEGATE, operand); |
| 1797 |
break; |
| 1798 |
} |
| 1799 |
case Token.PLUS: { |
| 1800 |
nextToken(); |
| 1801 |
|
| 1802 |
|
| 1803 |
Expression operand = parseUnaryExpression(); |
| 1804 |
exp = makeUnaryExpression(Token.PLUS, operand); |
| 1805 |
break; |
| 1806 |
} |
| 1807 |
case Token.VALIDATE: |
| 1808 |
case Token.VALIDATE_STRICT: |
| 1809 |
case Token.VALIDATE_LAX: |
| 1810 |
case Token.VALIDATE_TYPE: |
| 1811 |
exp = parseValidateExpression(); |
| 1812 |
break; |
| 1813 |
case Token.PRAGMA: |
| 1814 |
exp = parseExtensionExpression(); |
| 1815 |
break; |
| 1816 |
|
| 1817 |
case Token.KEYWORD_CURLY: |
| 1818 |
if (t.currentTokenValue.equals("validate")) { |
| 1819 |
exp = parseValidateExpression(); |
| 1820 |
break; |
| 1821 |
} |
| 1822 |
|
| 1823 |
default: |
| 1824 |
exp = parseSimpleMappingExpression(); |
| 1825 |
} |
| 1826 |
setLocation(exp); |
| 1827 |
return exp; |
| 1828 |
} |
| 1829 |
|
| 1830 |
private Expression makeUnaryExpression(int operator, Expression operand) { |
| 1831 |
if (Literal.isAtomic(operand)) { |
| 1832 |
|
| 1833 |
AtomicValue val = (AtomicValue) ((Literal) operand).getValue(); |
| 1834 |
if (val instanceof NumericValue) { |
| 1835 |
if (env.isInBackwardsCompatibleMode()) { |
| 1836 |
val = new DoubleValue(((NumericValue) val).getDoubleValue()); |
| 1837 |
} |
| 1838 |
AtomicValue value = operator == Token.NEGATE ? ((NumericValue) val).negate() : (NumericValue) val; |
| 1839 |
return Literal.makeLiteral(value); |
| 1840 |
} |
| 1841 |
} |
| 1842 |
return env.getConfiguration().getTypeChecker(env.isInBackwardsCompatibleMode()).makeArithmeticExpression( |
| 1843 |
Literal.makeLiteral(Int64Value.ZERO), operator, operand); |
| 1844 |
} |
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
protected boolean atStartOfRelativePath() { |
| 1853 |
switch (t.currentToken) { |
| 1854 |
case Token.AXIS: |
| 1855 |
case Token.AT: |
| 1856 |
case Token.NAME: |
| 1857 |
case Token.PREFIX: |
| 1858 |
case Token.SUFFIX: |
| 1859 |
case Token.STAR: |
| 1860 |
case Token.NODEKIND: |
| 1861 |
case Token.DOT: |
| 1862 |
case Token.DOTDOT: |
| 1863 |
case Token.FUNCTION: |
| 1864 |
case Token.STRING_LITERAL: |
| 1865 |
case Token.NUMBER: |
| 1866 |
case Token.LPAR: |
| 1867 |
case Token.DOLLAR: |
| 1868 |
case Token.PRAGMA: |
| 1869 |
case Token.ELEMENT_QNAME: |
| 1870 |
case Token.ATTRIBUTE_QNAME: |
| 1871 |
case Token.PI_QNAME: |
| 1872 |
case Token.NAMESPACE_QNAME: |
| 1873 |
case Token.NAMED_FUNCTION_REF: |
| 1874 |
return true; |
| 1875 |
case Token.KEYWORD_CURLY: |
| 1876 |
return t.currentTokenValue.equals("ordered") || t.currentTokenValue.equals("unordered"); |
| 1877 |
default: |
| 1878 |
return false; |
| 1879 |
} |
| 1880 |
} |
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
protected boolean disallowedAtStartOfRelativePath() { |
| 1891 |
switch (t.currentToken) { |
| 1892 |
|
| 1893 |
|
| 1894 |
case Token.CAST_AS: |
| 1895 |
case Token.CASTABLE_AS: |
| 1896 |
case Token.INSTANCE_OF: |
| 1897 |
case Token.TREAT_AS: |
| 1898 |
return true; |
| 1899 |
default: |
| 1900 |
return false; |
| 1901 |
} |
| 1902 |
} |
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
protected Expression parsePathExpression() throws XPathException { |
| 1915 |
int offset = t.currentTokenStartOffset; |
| 1916 |
switch (t.currentToken) { |
| 1917 |
case Token.SLASH: |
| 1918 |
nextToken(); |
| 1919 |
final RootExpression start = new RootExpression(); |
| 1920 |
setLocation(start); |
| 1921 |
if (disallowedAtStartOfRelativePath()) { |
| 1922 |
grumble("Operator '" + Token.tokens[t.currentToken] + "' is not allowed after '/'"); |
| 1923 |
} |
| 1924 |
if (atStartOfRelativePath()) { |
| 1925 |
final Expression path = parseRemainingPath(start); |
| 1926 |
setLocation(path, offset); |
| 1927 |
return path; |
| 1928 |
} else { |
| 1929 |
return start; |
| 1930 |
} |
| 1931 |
|
| 1932 |
case Token.SLASH_SLASH: |
| 1933 |
nextToken(); |
| 1934 |
final RootExpression start2 = new RootExpression(); |
| 1935 |
setLocation(start2, offset); |
| 1936 |
final AxisExpression axisExp = new AxisExpression(AxisInfo.DESCENDANT_OR_SELF, null); |
| 1937 |
setLocation(axisExp, offset); |
| 1938 |
final Expression slashExp = ExpressionTool.makePathExpression(start2, axisExp); |
| 1939 |
setLocation(slashExp, offset); |
| 1940 |
final Expression exp = parseRemainingPath(slashExp); |
| 1941 |
setLocation(exp, offset); |
| 1942 |
return exp; |
| 1943 |
|
| 1944 |
default: |
| 1945 |
if (t.currentToken == Token.NAME && |
| 1946 |
(t.currentTokenValue.equals("true") || t.currentTokenValue.equals("false"))) { |
| 1947 |
warning("The expression is looking for a child element named '" + t.currentTokenValue + |
| 1948 |
"' - perhaps " + t.currentTokenValue + "() was intended? To avoid this warning, use child::" + |
| 1949 |
t.currentTokenValue + " or ./" + t.currentTokenValue + "."); |
| 1950 |
} |
| 1951 |
if (t.currentToken == Token.NAME && t.getBinaryOp(t.currentTokenValue) != Token.UNKNOWN && |
| 1952 |
language != XSLT_PATTERN && (offset > 0 || t.peekAhead() != Token.EOF)) { |
| 1953 |
String s = t.currentTokenValue; |
| 1954 |
warning("The keyword '" + s + "' in this context means 'child::" + s + |
| 1955 |
"'. If this was intended, use 'child::" + s + "' or './" + s + "' to avoid this warning."); |
| 1956 |
} |
| 1957 |
return parseRelativePath(); |
| 1958 |
} |
| 1959 |
|
| 1960 |
} |
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
protected Expression parseSimpleMappingExpression() throws XPathException { |
| 1970 |
int offset = t.currentTokenStartOffset; |
| 1971 |
Expression exp = parsePathExpression(); |
| 1972 |
while (t.currentToken == Token.BANG) { |
| 1973 |
if (!allowXPath30Syntax) { |
| 1974 |
grumble("XPath '!' operator requires XPath 3.0 to be enabled"); |
| 1975 |
} |
| 1976 |
nextToken(); |
| 1977 |
Expression next = parsePathExpression(); |
| 1978 |
exp = new ForEach(exp, next); |
| 1979 |
setLocation(exp, offset); |
| 1980 |
} |
| 1981 |
return exp; |
| 1982 |
} |
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
protected Expression parseRelativePath() throws XPathException { |
| 1994 |
int offset = t.currentTokenStartOffset; |
| 1995 |
Expression exp = parseStepExpression(language == XSLT_PATTERN); |
| 1996 |
while (t.currentToken == Token.SLASH || |
| 1997 |
t.currentToken == Token.SLASH_SLASH) { |
| 1998 |
int op = t.currentToken; |
| 1999 |
nextToken(); |
| 2000 |
Expression next = parseStepExpression(false); |
| 2001 |
if (op == Token.SLASH) { |
| 2002 |
|
| 2003 |
|
| 2004 |
exp = new HomogeneityChecker(new SlashExpression(exp, next)); |
| 2005 |
} else { |
| 2006 |
|
| 2007 |
AxisExpression ae = new AxisExpression(AxisInfo.DESCENDANT_OR_SELF, null); |
| 2008 |
setLocation(ae, offset); |
| 2009 |
Expression one = ExpressionTool.makePathExpression(exp, ae); |
| 2010 |
setLocation(one, offset); |
| 2011 |
exp = ExpressionTool.makePathExpression(one, next); |
| 2012 |
exp = new HomogeneityChecker(exp); |
| 2013 |
} |
| 2014 |
setLocation(exp, offset); |
| 2015 |
} |
| 2016 |
return exp; |
| 2017 |
} |
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
protected Expression parseRemainingPath(Expression start) throws XPathException { |
| 2031 |
int offset = t.currentTokenStartOffset; |
| 2032 |
Expression exp = start; |
| 2033 |
int op = Token.SLASH; |
| 2034 |
while (true) { |
| 2035 |
Expression next = parseStepExpression(false); |
| 2036 |
if (op == Token.SLASH) { |
| 2037 |
|
| 2038 |
|
| 2039 |
exp = new HomogeneityChecker(new SlashExpression(exp, next)); |
| 2040 |
} else if (op == Token.SLASH_SLASH) { |
| 2041 |
|
| 2042 |
AxisExpression descOrSelf = new AxisExpression(AxisInfo.DESCENDANT_OR_SELF, null); |
| 2043 |
setLocation(descOrSelf); |
| 2044 |
Expression step = ExpressionTool.makePathExpression(descOrSelf, next); |
| 2045 |
setLocation(step); |
| 2046 |
exp = ExpressionTool.makePathExpression(exp, step); |
| 2047 |
exp = new HomogeneityChecker(exp); |
| 2048 |
} else { |
| 2049 |
if (!allowXPath30Syntax) { |
| 2050 |
grumble("XPath '!' operator requires XPath 3.0 to be enabled"); |
| 2051 |
} |
| 2052 |
exp = new ForEach(exp, next); |
| 2053 |
} |
| 2054 |
setLocation(exp, offset); |
| 2055 |
op = t.currentToken; |
| 2056 |
if (op != Token.SLASH && op != Token.SLASH_SLASH && op != Token.BANG) { |
| 2057 |
break; |
| 2058 |
} |
| 2059 |
nextToken(); |
| 2060 |
} |
| 2061 |
return exp; |
| 2062 |
} |
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
protected Expression parseStepExpression(boolean firstInPattern) throws XPathException { |
| 2076 |
Expression step = parseBasicStep(firstInPattern); |
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
boolean reverse = (step instanceof AxisExpression) && |
| 2081 |
!AxisInfo.isForwards[((AxisExpression) step).getAxis()]; |
| 2082 |
|
| 2083 |
while (true) { |
| 2084 |
if (t.currentToken == Token.LSQB) { |
| 2085 |
step = parsePredicate(step); |
| 2086 |
} else if (t.currentToken == Token.LPAR) { |
| 2087 |
|
| 2088 |
step = parseDynamicFunctionCall(step, null); |
| 2089 |
setLocation(step); |
| 2090 |
} else if (t.currentToken == Token.QMARK) { |
| 2091 |
step = parseLookup(step); |
| 2092 |
setLocation(step); |
| 2093 |
} else { |
| 2094 |
break; |
| 2095 |
} |
| 2096 |
} |
| 2097 |
if (reverse) { |
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
RetainedStaticContext rsc = env.makeRetainedStaticContext(); |
| 2105 |
step = SystemFunction.makeCall("reverse", rsc, step); |
| 2106 |
assert step != null; |
| 2107 |
return step; |
| 2108 |
} else { |
| 2109 |
return step; |
| 2110 |
} |
| 2111 |
} |
| 2112 |
|
| 2113 |
protected Expression parsePredicate(Expression step) throws XPathException { |
| 2114 |
nextToken(); |
| 2115 |
Expression predicate = parsePredicate(); |
| 2116 |
expect(Token.RSQB); |
| 2117 |
nextToken(); |
| 2118 |
step = new FilterExpression(step, predicate); |
| 2119 |
setLocation(step); |
| 2120 |
return step; |
| 2121 |
} |
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
protected Expression parseArrowPostfix(Expression lhs) throws XPathException { |
| 2131 |
checkLanguageVersion31(); |
| 2132 |
nextToken(); |
| 2133 |
int token = getTokenizer().currentToken; |
| 2134 |
if (token == Token.NAME || token == Token.FUNCTION) { |
| 2135 |
return parseFunctionCall(lhs); |
| 2136 |
} else if (token == Token.DOLLAR) { |
| 2137 |
Expression var = parseVariableReference(); |
| 2138 |
expect(Token.LPAR); |
| 2139 |
return parseDynamicFunctionCall(var, lhs); |
| 2140 |
} else if (token == Token.LPAR) { |
| 2141 |
Expression var = parseParenthesizedExpression(); |
| 2142 |
expect(Token.LPAR); |
| 2143 |
return parseDynamicFunctionCall(var, lhs); |
| 2144 |
} else { |
| 2145 |
grumble("Unexpected " + Token.tokens[token] + " after '=>'"); |
| 2146 |
return null; |
| 2147 |
} |
| 2148 |
} |
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
protected Expression parsePredicate() throws XPathException { |
| 2159 |
return parseExpression(); |
| 2160 |
} |
| 2161 |
|
| 2162 |
protected boolean isReservedInQuery(String uri) { |
| 2163 |
if (allowXPath31Syntax) { |
| 2164 |
return NamespaceConstant.isReservedInQuery31(uri); |
| 2165 |
} else if (allowXPath30Syntax) { |
| 2166 |
return NamespaceConstant.isReservedInQuery30(uri); |
| 2167 |
} else { |
| 2168 |
return NamespaceConstant.isReservedInQuery(uri); |
| 2169 |
} |
| 2170 |
} |
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
protected Expression parseBasicStep(boolean firstInPattern) throws XPathException { |
| 2183 |
switch (t.currentToken) { |
| 2184 |
case Token.DOLLAR: |
| 2185 |
return parseVariableReference(); |
| 2186 |
|
| 2187 |
case Token.LPAR: |
| 2188 |
return parseParenthesizedExpression(); |
| 2189 |
|
| 2190 |
case Token.LSQB: |
| 2191 |
return parseArraySquareConstructor(); |
| 2192 |
|
| 2193 |
case Token.STRING_LITERAL: |
| 2194 |
return parseStringLiteral(true); |
| 2195 |
|
| 2196 |
case Token.STRING_TEMPLATE_COMPLETE: |
| 2197 |
return parseStringTemplate(true); |
| 2198 |
|
| 2199 |
case Token.STRING_TEMPLATE_INITIAL: |
| 2200 |
return parseStringTemplate(false); |
| 2201 |
|
| 2202 |
case Token.NUMBER: |
| 2203 |
return parseNumericLiteral(true); |
| 2204 |
|
| 2205 |
case Token.FUNCTION: |
| 2206 |
return parseFunctionCall(null); |
| 2207 |
|
| 2208 |
case Token.QMARK: |
| 2209 |
return parseLookup(new ContextItemExpression()); |
| 2210 |
|
| 2211 |
case Token.DOT: |
| 2212 |
nextToken(); |
| 2213 |
Expression cie = new ContextItemExpression(); |
| 2214 |
setLocation(cie); |
| 2215 |
return cie; |
| 2216 |
|
| 2217 |
case Token.DOTDOT: |
| 2218 |
nextToken(); |
| 2219 |
Expression pne = new AxisExpression(AxisInfo.PARENT, null); |
| 2220 |
setLocation(pne); |
| 2221 |
return pne; |
| 2222 |
|
| 2223 |
case Token.PERCENT: { |
| 2224 |
AnnotationList annotations = parseAnnotationsList(); |
| 2225 |
if (!t.currentTokenValue.equals("function")) { |
| 2226 |
grumble("Expected 'function' to follow the annotation assertion"); |
| 2227 |
} |
| 2228 |
annotations.check(env.getConfiguration(), "IF"); |
| 2229 |
return parseInlineFunction(annotations); |
| 2230 |
} |
| 2231 |
case Token.NODEKIND: |
| 2232 |
if (t.currentTokenValue.equals("function")) { |
| 2233 |
AnnotationList annotations = AnnotationList.EMPTY; |
| 2234 |
return parseInlineFunction(annotations); |
| 2235 |
|
| 2236 |
|
| 2237 |
} |
| 2238 |
|
| 2239 |
case Token.NAME: |
| 2240 |
case Token.PREFIX: |
| 2241 |
case Token.SUFFIX: |
| 2242 |
case Token.STAR: |
| 2243 |
byte defaultAxis = AxisInfo.CHILD; |
| 2244 |
if (t.currentToken == Token.NODEKIND && |
| 2245 |
(t.currentTokenValue.equals("attribute") || t.currentTokenValue.equals("schema-attribute"))) { |
| 2246 |
defaultAxis = AxisInfo.ATTRIBUTE; |
| 2247 |
} else if (t.currentToken == Token.NODEKIND && t.currentTokenValue.equals("namespace-node")) { |
| 2248 |
defaultAxis = AxisInfo.NAMESPACE; |
| 2249 |
testPermittedAxis(AxisInfo.NAMESPACE, "XQST0134"); |
| 2250 |
} else if (firstInPattern && t.currentToken == Token.NODEKIND && t.currentTokenValue.equals("document-node")) { |
| 2251 |
defaultAxis = AxisInfo.SELF; |
| 2252 |
} |
| 2253 |
NodeTest test = parseNodeTest(Type.ELEMENT); |
| 2254 |
if (test instanceof AnyNodeTest) { |
| 2255 |
|
| 2256 |
test = defaultAxis == AxisInfo.CHILD ? AnyChildNodeTest.getInstance() : NodeKindTest.ATTRIBUTE; |
| 2257 |
} |
| 2258 |
AxisExpression ae = new AxisExpression(defaultAxis, test); |
| 2259 |
setLocation(ae); |
| 2260 |
return ae; |
| 2261 |
|
| 2262 |
case Token.AT: |
| 2263 |
nextToken(); |
| 2264 |
switch (t.currentToken) { |
| 2265 |
|
| 2266 |
case Token.NAME: |
| 2267 |
case Token.PREFIX: |
| 2268 |
case Token.SUFFIX: |
| 2269 |
case Token.STAR: |
| 2270 |
case Token.NODEKIND: |
| 2271 |
AxisExpression ae2 = new AxisExpression(AxisInfo.ATTRIBUTE, parseNodeTest(Type.ATTRIBUTE)); |
| 2272 |
setLocation(ae2); |
| 2273 |
return ae2; |
| 2274 |
|
| 2275 |
default: |
| 2276 |
grumble("@ must be followed by a NodeTest"); |
| 2277 |
} |
| 2278 |
break; |
| 2279 |
|
| 2280 |
case Token.AXIS: |
| 2281 |
byte axis; |
| 2282 |
try { |
| 2283 |
axis = AxisInfo.getAxisNumber(t.currentTokenValue); |
| 2284 |
} catch (XPathException err) { |
| 2285 |
grumble(err.getMessage()); |
| 2286 |
axis = AxisInfo.CHILD; |
| 2287 |
} |
| 2288 |
testPermittedAxis(axis, "XPST0003"); |
| 2289 |
short principalNodeType = AxisInfo.principalNodeType[axis]; |
| 2290 |
nextToken(); |
| 2291 |
switch (t.currentToken) { |
| 2292 |
|
| 2293 |
case Token.NAME: |
| 2294 |
case Token.PREFIX: |
| 2295 |
case Token.SUFFIX: |
| 2296 |
case Token.STAR: |
| 2297 |
case Token.NODEKIND: |
| 2298 |
Expression ax = new AxisExpression(axis, parseNodeTest(principalNodeType)); |
| 2299 |
setLocation(ax); |
| 2300 |
return ax; |
| 2301 |
|
| 2302 |
default: |
| 2303 |
grumble("Unexpected token " + currentTokenDisplay() + " after axis name"); |
| 2304 |
} |
| 2305 |
break; |
| 2306 |
|
| 2307 |
case Token.KEYWORD_CURLY: |
| 2308 |
switch (t.currentTokenValue) { |
| 2309 |
case "map": |
| 2310 |
return parseMapExpression(); |
| 2311 |
case "array": |
| 2312 |
return parseArrayCurlyConstructor(); |
| 2313 |
case "fn": |
| 2314 |
return parserExtension.parseSimpleInlineFunction(this); |
| 2315 |
} |
| 2316 |
|
| 2317 |
case Token.ELEMENT_QNAME: |
| 2318 |
case Token.ATTRIBUTE_QNAME: |
| 2319 |
case Token.NAMESPACE_QNAME: |
| 2320 |
case Token.PI_QNAME: |
| 2321 |
case Token.TAG: |
| 2322 |
return parseConstructor(); |
| 2323 |
|
| 2324 |
case Token.NAMED_FUNCTION_REF: |
| 2325 |
return parseNamedFunctionReference(); |
| 2326 |
|
| 2327 |
default: |
| 2328 |
grumble("Unexpected token " + currentTokenDisplay() + " at start of expression"); |
| 2329 |
|
| 2330 |
} |
| 2331 |
return new ErrorExpression(); |
| 2332 |
} |
| 2333 |
|
| 2334 |
public Expression parseParenthesizedExpression() throws XPathException { |
| 2335 |
nextToken(); |
| 2336 |
if (t.currentToken == Token.RPAR) { |
| 2337 |
nextToken(); |
| 2338 |
return Literal.makeEmptySequence(); |
| 2339 |
} |
| 2340 |
Expression seq = parseExpression(); |
| 2341 |
expect(Token.RPAR); |
| 2342 |
nextToken(); |
| 2343 |
return seq; |
| 2344 |
} |
| 2345 |
|
| 2346 |
protected void testPermittedAxis(byte axis, String errorCode) throws XPathException { |
| 2347 |
|
| 2348 |
} |
| 2349 |
|
| 2350 |
|
| 2351 |
public Expression parseNumericLiteral(boolean traceable) throws XPathException { |
| 2352 |
int offset = t.currentTokenStartOffset; |
| 2353 |
NumericValue number = NumericValue.parseNumber(t.currentTokenValue); |
| 2354 |
if (number.isNaN()) { |
| 2355 |
grumble("Invalid numeric literal " + Err.wrap(t.currentTokenValue, Err.VALUE)); |
| 2356 |
} |
| 2357 |
nextToken(); |
| 2358 |
Literal lit = Literal.makeLiteral(number); |
| 2359 |
setLocation(lit, offset); |
| 2360 |
|
| 2361 |
return traceable ? makeTracer(offset, lit, 0, null) : lit; |
| 2362 |
} |
| 2363 |
|
| 2364 |
protected Expression parseStringLiteral(boolean traceable) throws XPathException { |
| 2365 |
int offset = t.currentTokenStartOffset; |
| 2366 |
Literal literal = makeStringLiteral(t.currentTokenValue); |
| 2367 |
|
| 2368 |
nextToken(); |
| 2369 |
return traceable ? makeTracer(offset, literal, 0, null) : literal; |
| 2370 |
} |
| 2371 |
|
| 2372 |
protected Expression parseStringTemplate(boolean complete) throws XPathException { |
| 2373 |
grumble("String constructor expressions are allowed only in XQuery"); |
| 2374 |
return null; |
| 2375 |
} |
| 2376 |
|
| 2377 |
|
| 2378 |
public Expression parseVariableReference() throws XPathException { |
| 2379 |
int offset = t.currentTokenStartOffset; |
| 2380 |
nextToken(); |
| 2381 |
expect(Token.NAME); |
| 2382 |
String var = t.currentTokenValue; |
| 2383 |
nextToken(); |
| 2384 |
|
| 2385 |
if (scanOnly) { |
| 2386 |
return new ContextItemExpression(); |
| 2387 |
|
| 2388 |
} |
| 2389 |
|
| 2390 |
|
| 2391 |
StructuredQName vtest = makeStructuredQName(var, ""); |
| 2392 |
assert vtest != null; |
| 2393 |
|
| 2394 |
|
| 2395 |
LocalBinding b = findRangeVariable(vtest); |
| 2396 |
Expression ref; |
| 2397 |
if (b != null) { |
| 2398 |
ref = new LocalVariableReference(b); |
| 2399 |
} else { |
| 2400 |
if (catchDepth > 0) { |
| 2401 |
for (StructuredQName errorVariable : StandardNames.errorVariables) { |
| 2402 |
if (errorVariable.getLocalPart().equals(vtest.getLocalPart())) { |
| 2403 |
StructuredQName functionName = |
| 2404 |
new StructuredQName("saxon", NamespaceConstant.SAXON, "dynamic-error-info"); |
| 2405 |
SymbolicName.F sn = new SymbolicName.F(functionName, 1); |
| 2406 |
Expression[] args = new Expression[]{new StringLiteral(vtest.getLocalPart())}; |
| 2407 |
return VendorFunctionSetHE.getInstance().bind(sn, args, env, new ArrayList<>()); |
| 2408 |
} |
| 2409 |
} |
| 2410 |
} |
| 2411 |
try { |
| 2412 |
ref = env.bindVariable(vtest); |
| 2413 |
} catch (XPathException err) { |
| 2414 |
err.maybeSetLocation(makeLocation()); |
| 2415 |
throw err; |
| 2416 |
} |
| 2417 |
} |
| 2418 |
setLocation(ref, offset); |
| 2419 |
return ref; |
| 2420 |
} |
| 2421 |
|
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
protected Literal makeStringLiteral(String currentTokenValue) throws XPathException { |
| 2435 |
StringLiteral literal = new StringLiteral(currentTokenValue); |
| 2436 |
setLocation(literal); |
| 2437 |
return literal; |
| 2438 |
} |
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
protected CharSequence unescape(String token) throws XPathException { |
| 2452 |
return token; |
| 2453 |
} |
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
protected Expression parseConstructor() throws XPathException { |
| 2466 |
grumble("Node constructor expressions are allowed only in XQuery, not in XPath"); |
| 2467 |
return new ErrorExpression(); |
| 2468 |
} |
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
public Expression parseDynamicFunctionCall(Expression functionItem, Expression prefixArgument) throws XPathException { |
| 2481 |
checkLanguageVersion30(); |
| 2482 |
|
| 2483 |
ArrayList<Expression> args = new ArrayList<>(10); |
| 2484 |
if (prefixArgument != null) { |
| 2485 |
args.add(prefixArgument); |
| 2486 |
} |
| 2487 |
IntSet placeMarkers = null; |
| 2488 |
|
| 2489 |
|
| 2490 |
nextToken(); |
| 2491 |
if (t.currentToken != Token.RPAR) { |
| 2492 |
while (true) { |
| 2493 |
Expression arg = parseFunctionArgument(); |
| 2494 |
if (arg == null) { |
| 2495 |
|
| 2496 |
if (placeMarkers == null) { |
| 2497 |
placeMarkers = new IntArraySet(); |
| 2498 |
} |
| 2499 |
placeMarkers.add(args.size()); |
| 2500 |
arg = Literal.makeEmptySequence(); |
| 2501 |
checkHofFeature(); |
| 2502 |
} |
| 2503 |
args.add(arg); |
| 2504 |
if (t.currentToken == Token.COMMA) { |
| 2505 |
nextToken(); |
| 2506 |
} else { |
| 2507 |
break; |
| 2508 |
} |
| 2509 |
} |
| 2510 |
expect(Token.RPAR); |
| 2511 |
} |
| 2512 |
nextToken(); |
| 2513 |
|
| 2514 |
if (placeMarkers == null) { |
| 2515 |
return generateApplyCall(functionItem, args); |
| 2516 |
} else { |
| 2517 |
return parserExtension.createDynamicCurriedFunction(this, functionItem, args, placeMarkers); |
| 2518 |
} |
| 2519 |
} |
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
protected Expression generateApplyCall(Expression functionItem, ArrayList<Expression> args) throws XPathException { |
| 2524 |
SquareArrayConstructor block = new SquareArrayConstructor(args); |
| 2525 |
RetainedStaticContext rsc = new RetainedStaticContext(getStaticContext()); |
| 2526 |
SystemFunction fn = VendorFunctionSetHE.getInstance().makeFunction("apply", 2); |
| 2527 |
fn.setRetainedStaticContext(rsc); |
| 2528 |
Expression call = fn.makeFunctionCall(functionItem, block); |
| 2529 |
((ApplyFn) fn).setDynamicFunctionCall(functionItem.toShortString()); |
| 2530 |
setLocation(call, t.currentTokenStartOffset); |
| 2531 |
return call; |
| 2532 |
} |
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
protected Expression parseLookup(Expression lhs) throws XPathException { |
| 2544 |
checkLanguageVersion31(); |
| 2545 |
Tokenizer t = getTokenizer(); |
| 2546 |
int offset = t.currentTokenStartOffset; |
| 2547 |
t.setState(Tokenizer.BARE_NAME_STATE); |
| 2548 |
t.currentToken = Token.LPAR; |
| 2549 |
nextToken(); |
| 2550 |
int token = t.currentToken; |
| 2551 |
t.setState(Tokenizer.OPERATOR_STATE); |
| 2552 |
|
| 2553 |
Expression result; |
| 2554 |
if (token == Token.NAME) { |
| 2555 |
String name = t.currentTokenValue; |
| 2556 |
if (!NameChecker.isValidNCName(name)) { |
| 2557 |
grumble("The name following '?' must be a valid NCName"); |
| 2558 |
} |
| 2559 |
nextToken(); |
| 2560 |
result = lookupName(lhs, name); |
| 2561 |
} else if (token == Token.NUMBER) { |
| 2562 |
NumericValue number = NumericValue.parseNumber(t.currentTokenValue); |
| 2563 |
if (!(number instanceof IntegerValue)) { |
| 2564 |
grumble("Number following '?' must be an integer"); |
| 2565 |
} |
| 2566 |
nextToken(); |
| 2567 |
result = lookup(this, lhs, Literal.makeLiteral(number)); |
| 2568 |
} else if (token == Token.MULT || token == Token.STAR) { |
| 2569 |
nextToken(); |
| 2570 |
result = lookupStar(lhs); |
| 2571 |
} else if (token == Token.LPAR) { |
| 2572 |
result = lookup(this, lhs, parseParenthesizedExpression()); |
| 2573 |
} else { |
| 2574 |
grumble("Unexpected " + Token.tokens[token] + " after '?'"); |
| 2575 |
return null; |
| 2576 |
} |
| 2577 |
setLocation(result, offset); |
| 2578 |
return result; |
| 2579 |
} |
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
private static Expression lookup(XPathParser parser, Expression lhs, Expression rhs) { |
| 2591 |
return new LookupExpression(lhs, rhs); |
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
} |
| 2633 |
|
| 2634 |
private static SystemFunction makeMapGetFunction() { |
| 2635 |
try { |
| 2636 |
return MapFunctionSet.getInstance().makeFunction("get", 2); |
| 2637 |
} catch (XPathException e) { |
| 2638 |
throw new AssertionError(e); |
| 2639 |
} |
| 2640 |
} |
| 2641 |
|
| 2642 |
private static SystemFunction makeArrayGetFunction() { |
| 2643 |
try { |
| 2644 |
return ArrayFunctionSet.getInstance().makeFunction("get", 2); |
| 2645 |
} catch (XPathException e) { |
| 2646 |
throw new AssertionError(e); |
| 2647 |
} |
| 2648 |
} |
| 2649 |
|
| 2650 |
private static SystemFunction makeMapKeysFunction() { |
| 2651 |
try { |
| 2652 |
return MapFunctionSet.getInstance().makeFunction("keys", 1); |
| 2653 |
} catch (XPathException e) { |
| 2654 |
throw new AssertionError(e); |
| 2655 |
} |
| 2656 |
} |
| 2657 |
|
| 2658 |
private static SystemFunction makeArrayToSequenceFunction() { |
| 2659 |
try { |
| 2660 |
return ArrayFunctionSet.getInstance().makeFunction("_to-sequence", 1); |
| 2661 |
} catch (XPathException e) { |
| 2662 |
throw new AssertionError(e); |
| 2663 |
} |
| 2664 |
} |
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
private Expression lookupName(Expression lhs, String rhs) { |
| 2675 |
return new LookupExpression(lhs, new StringLiteral(rhs)); |
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
} |
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
private static Expression lookupStar(Expression lhs) { |
| 2705 |
return new LookupAllExpression(lhs); |
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
} |
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
protected NodeTest parseNodeTest(short nodeType) throws XPathException { |
| 2752 |
int tok = t.currentToken; |
| 2753 |
String tokv = t.currentTokenValue; |
| 2754 |
switch (tok) { |
| 2755 |
case Token.NAME: |
| 2756 |
nextToken(); |
| 2757 |
return makeNameTest(nodeType, tokv, nodeType == Type.ELEMENT); |
| 2758 |
|
| 2759 |
case Token.PREFIX: |
| 2760 |
nextToken(); |
| 2761 |
return makeNamespaceTest(nodeType, tokv); |
| 2762 |
|
| 2763 |
case Token.SUFFIX: |
| 2764 |
nextToken(); |
| 2765 |
tokv = t.currentTokenValue; |
| 2766 |
expect(Token.NAME); |
| 2767 |
nextToken(); |
| 2768 |
return makeLocalNameTest(nodeType, tokv); |
| 2769 |
|
| 2770 |
case Token.STAR: |
| 2771 |
nextToken(); |
| 2772 |
return NodeKindTest.makeNodeKindTest(nodeType); |
| 2773 |
|
| 2774 |
case Token.NODEKIND: |
| 2775 |
return parseKindTest(); |
| 2776 |
|
| 2777 |
default: |
| 2778 |
grumble("Unrecognized node test"); |
| 2779 |
throw new XPathException(""); |
| 2780 |
} |
| 2781 |
} |
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
private NodeTest parseKindTest() throws XPathException { |
| 2792 |
NamePool pool = env.getConfiguration().getNamePool(); |
| 2793 |
String typeName = t.currentTokenValue; |
| 2794 |
boolean schemaDeclaration = typeName.startsWith("schema-"); |
| 2795 |
int primaryType = getSystemType(typeName); |
| 2796 |
int fp = -1; |
| 2797 |
boolean empty = false; |
| 2798 |
nextToken(); |
| 2799 |
if (t.currentToken == Token.RPAR) { |
| 2800 |
if (schemaDeclaration) { |
| 2801 |
grumble("schema-element() and schema-attribute() require a name to be supplied"); |
| 2802 |
return null; |
| 2803 |
} |
| 2804 |
empty = true; |
| 2805 |
nextToken(); |
| 2806 |
} |
| 2807 |
switch (primaryType) { |
| 2808 |
case Type.ITEM: |
| 2809 |
grumble("item() is not allowed in a path expression"); |
| 2810 |
return null; |
| 2811 |
case Type.NODE: |
| 2812 |
if (empty) { |
| 2813 |
return AnyNodeTest.getInstance(); |
| 2814 |
} else { |
| 2815 |
grumble("Expected ')': no arguments are allowed in node()"); |
| 2816 |
return null; |
| 2817 |
} |
| 2818 |
case Type.TEXT: |
| 2819 |
if (empty) { |
| 2820 |
return NodeKindTest.TEXT; |
| 2821 |
} else { |
| 2822 |
grumble("Expected ')': no arguments are allowed in text()"); |
| 2823 |
return null; |
| 2824 |
} |
| 2825 |
case Type.COMMENT: |
| 2826 |
if (empty) { |
| 2827 |
return NodeKindTest.COMMENT; |
| 2828 |
} else { |
| 2829 |
grumble("Expected ')': no arguments are allowed in comment()"); |
| 2830 |
return null; |
| 2831 |
} |
| 2832 |
case Type.NAMESPACE: |
| 2833 |
if (empty) { |
| 2834 |
if (!isNamespaceTestAllowed()) { |
| 2835 |
grumble("namespace-node() test is not allowed in XPath 2.0/XQuery 1.0"); |
| 2836 |
} |
| 2837 |
return NodeKindTest.NAMESPACE; |
| 2838 |
} else { |
| 2839 |
if (language == EXTENDED_ITEM_TYPE && t.currentToken == Token.NAME) { |
| 2840 |
String nsName = t.currentTokenValue; |
| 2841 |
nextToken(); |
| 2842 |
expect(Token.RPAR); |
| 2843 |
nextToken(); |
| 2844 |
return new NameTest(Type.NAMESPACE, "", nsName, pool); |
| 2845 |
} else { |
| 2846 |
grumble("No arguments are allowed in namespace-node()"); |
| 2847 |
return null; |
| 2848 |
} |
| 2849 |
} |
| 2850 |
case Type.DOCUMENT: |
| 2851 |
if (empty) { |
| 2852 |
return NodeKindTest.DOCUMENT; |
| 2853 |
} else { |
| 2854 |
int innerType; |
| 2855 |
try { |
| 2856 |
innerType = getSystemType(t.currentTokenValue); |
| 2857 |
} catch (XPathException err) { |
| 2858 |
innerType = Type.ITEM; |
| 2859 |
} |
| 2860 |
if (innerType != Type.ELEMENT) { |
| 2861 |
grumble("Argument to document-node() must be an element type descriptor"); |
| 2862 |
return null; |
| 2863 |
} |
| 2864 |
NodeTest inner = parseKindTest(); |
| 2865 |
expect(Token.RPAR); |
| 2866 |
nextToken(); |
| 2867 |
return new DocumentNodeTest(inner); |
| 2868 |
} |
| 2869 |
case Type.PROCESSING_INSTRUCTION: |
| 2870 |
if (empty) { |
| 2871 |
return NodeKindTest.PROCESSING_INSTRUCTION; |
| 2872 |
} else if (t.currentToken == Token.STRING_LITERAL) { |
| 2873 |
String piName = Whitespace.trim(unescape(t.currentTokenValue)); |
| 2874 |
if (!NameChecker.isValidNCName(piName)) { |
| 2875 |
|
| 2876 |
grumble("Processing instruction name must be a valid NCName", "XPTY0004"); |
| 2877 |
} else { |
| 2878 |
fp = pool.allocateFingerprint("", piName); |
| 2879 |
} |
| 2880 |
} else if (t.currentToken == Token.NAME) { |
| 2881 |
try { |
| 2882 |
String[] parts = NameChecker.getQNameParts(t.currentTokenValue); |
| 2883 |
if (parts[0].isEmpty()) { |
| 2884 |
fp = pool.allocateFingerprint("", parts[1]); |
| 2885 |
} else { |
| 2886 |
grumble("Processing instruction name must not contain a colon"); |
| 2887 |
} |
| 2888 |
} catch (QNameException e) { |
| 2889 |
grumble("Invalid processing instruction name. " + e.getMessage()); |
| 2890 |
} |
| 2891 |
} else { |
| 2892 |
grumble("Processing instruction name must be a QName or a string literal"); |
| 2893 |
} |
| 2894 |
nextToken(); |
| 2895 |
expect(Token.RPAR); |
| 2896 |
nextToken(); |
| 2897 |
return new NameTest(Type.PROCESSING_INSTRUCTION, fp, pool); |
| 2898 |
|
| 2899 |
case Type.ATTRIBUTE: |
| 2900 |
|
| 2901 |
|
| 2902 |
case Type.ELEMENT: |
| 2903 |
String nodeName = ""; |
| 2904 |
if (empty) { |
| 2905 |
return NodeKindTest.makeNodeKindTest(primaryType); |
| 2906 |
} else if (t.currentToken == Token.STAR || t.currentToken == Token.MULT) { |
| 2907 |
|
| 2908 |
if (schemaDeclaration) { |
| 2909 |
grumble("schema-element() and schema-attribute() must specify an actual name, not '*'"); |
| 2910 |
return null; |
| 2911 |
} |
| 2912 |
fp = -1; |
| 2913 |
} else if (t.currentToken == Token.NAME) { |
| 2914 |
nodeName = t.currentTokenValue; |
| 2915 |
fp = makeFingerprint(t.currentTokenValue, primaryType == Type.ELEMENT); |
| 2916 |
} else { |
| 2917 |
grumble("Unexpected " + Token.tokens[t.currentToken] + " after '(' in SequenceType"); |
| 2918 |
} |
| 2919 |
String suri = null; |
| 2920 |
if (fp != -1) { |
| 2921 |
suri = pool.getURI(fp); |
| 2922 |
} |
| 2923 |
nextToken(); |
| 2924 |
if (t.currentToken == Token.RPAR) { |
| 2925 |
nextToken(); |
| 2926 |
if (fp == -1) { |
| 2927 |
|
| 2928 |
return NodeKindTest.makeNodeKindTest(primaryType); |
| 2929 |
} else { |
| 2930 |
NodeTest nameTest; |
| 2931 |
if (primaryType == Type.ATTRIBUTE) { |
| 2932 |
|
| 2933 |
if (schemaDeclaration) { |
| 2934 |
|
| 2935 |
SchemaDeclaration attributeDecl = |
| 2936 |
env.getConfiguration().getAttributeDeclaration(fp & 0xfffff); |
| 2937 |
if (!env.isImportedSchema(suri)) { |
| 2938 |
grumble("No schema has been imported for namespace '" + suri + '\'', "XPST0008"); |
| 2939 |
} |
| 2940 |
if (attributeDecl == null) { |
| 2941 |
grumble("There is no declaration for attribute @" + nodeName + " in an imported schema", "XPST0008"); |
| 2942 |
return null; |
| 2943 |
} else { |
| 2944 |
return attributeDecl.makeSchemaNodeTest(); |
| 2945 |
} |
| 2946 |
} else { |
| 2947 |
nameTest = new NameTest(Type.ATTRIBUTE, fp, pool); |
| 2948 |
return nameTest; |
| 2949 |
} |
| 2950 |
} else { |
| 2951 |
|
| 2952 |
if (schemaDeclaration) { |
| 2953 |
|
| 2954 |
if (!env.isImportedSchema(suri)) { |
| 2955 |
grumble("No schema has been imported for namespace '" + suri + '\'', "XPST0008"); |
| 2956 |
} |
| 2957 |
SchemaDeclaration elementDecl = |
| 2958 |
env.getConfiguration().getElementDeclaration(fp & 0xfffff); |
| 2959 |
if (elementDecl == null) { |
| 2960 |
grumble("There is no declaration for element <" + nodeName + "> in an imported schema", "XPST0008"); |
| 2961 |
return null; |
| 2962 |
} else { |
| 2963 |
return elementDecl.makeSchemaNodeTest(); |
| 2964 |
} |
| 2965 |
} else { |
| 2966 |
nameTest = new NameTest(Type.ELEMENT, fp, pool); |
| 2967 |
return nameTest; |
| 2968 |
} |
| 2969 |
} |
| 2970 |
} |
| 2971 |
} else if (t.currentToken == Token.COMMA) { |
| 2972 |
if (schemaDeclaration) { |
| 2973 |
grumble("schema-element() and schema-attribute() must have one argument only"); |
| 2974 |
return null; |
| 2975 |
} |
| 2976 |
nextToken(); |
| 2977 |
NodeTest result; |
| 2978 |
if (t.currentToken == Token.STAR) { |
| 2979 |
grumble("'*' is no longer permitted as the second argument of element() and attribute()"); |
| 2980 |
return null; |
| 2981 |
} else if (t.currentToken == Token.NAME) { |
| 2982 |
SchemaType schemaType; |
| 2983 |
StructuredQName contentType = makeStructuredQName(t.currentTokenValue, env.getDefaultElementNamespace()); |
| 2984 |
assert contentType != null; |
| 2985 |
String uri = contentType.getURI(); |
| 2986 |
String lname = contentType.getLocalPart(); |
| 2987 |
|
| 2988 |
if (uri.equals(NamespaceConstant.SCHEMA)) { |
| 2989 |
schemaType = env.getConfiguration().getSchemaType(contentType); |
| 2990 |
} else { |
| 2991 |
if (!env.isImportedSchema(uri)) { |
| 2992 |
grumble("No schema has been imported for namespace '" + uri + '\'', "XPST0008"); |
| 2993 |
} |
| 2994 |
schemaType = env.getConfiguration().getSchemaType(contentType); |
| 2995 |
} |
| 2996 |
if (schemaType == null) { |
| 2997 |
grumble("Unknown type name " + contentType.getEQName(), "XPST0008"); |
| 2998 |
return null; |
| 2999 |
} |
| 3000 |
if (primaryType == Type.ATTRIBUTE && schemaType.isComplexType()) { |
| 3001 |
warning("An attribute cannot have a complex type"); |
| 3002 |
} |
| 3003 |
ContentTypeTest typeTest = new ContentTypeTest(primaryType, schemaType, env.getConfiguration(), false); |
| 3004 |
if (fp == -1) { |
| 3005 |
|
| 3006 |
result = typeTest; |
| 3007 |
if (primaryType == Type.ATTRIBUTE) { |
| 3008 |
nextToken(); |
| 3009 |
} else { |
| 3010 |
|
| 3011 |
nextToken(); |
| 3012 |
if (t.currentToken == Token.QMARK) { |
| 3013 |
typeTest.setNillable(true); |
| 3014 |
nextToken(); |
| 3015 |
} |
| 3016 |
} |
| 3017 |
} else { |
| 3018 |
if (primaryType == Type.ATTRIBUTE) { |
| 3019 |
NodeTest nameTest = new NameTest(Type.ATTRIBUTE, fp, pool); |
| 3020 |
if (schemaType == AnyType.getInstance() || schemaType == AnySimpleType.getInstance()) { |
| 3021 |
result = nameTest; |
| 3022 |
} else { |
| 3023 |
result = new CombinedNodeTest(nameTest, Token.INTERSECT, typeTest); |
| 3024 |
} |
| 3025 |
nextToken(); |
| 3026 |
} else { |
| 3027 |
|
| 3028 |
NodeTest nameTest = new NameTest(Type.ELEMENT, fp, pool); |
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
result = new CombinedNodeTest(nameTest, Token.INTERSECT, typeTest); |
| 3033 |
|
| 3034 |
nextToken(); |
| 3035 |
if (t.currentToken == Token.QMARK) { |
| 3036 |
typeTest.setNillable(true); |
| 3037 |
nextToken(); |
| 3038 |
} |
| 3039 |
} |
| 3040 |
} |
| 3041 |
} else { |
| 3042 |
grumble("Unexpected " + Token.tokens[t.currentToken] + " after ',' in SequenceType"); |
| 3043 |
return null; |
| 3044 |
} |
| 3045 |
|
| 3046 |
expect(Token.RPAR); |
| 3047 |
nextToken(); |
| 3048 |
return result; |
| 3049 |
} else { |
| 3050 |
grumble("Expected ')' or ',' in SequenceType"); |
| 3051 |
} |
| 3052 |
return null; |
| 3053 |
default: |
| 3054 |
|
| 3055 |
grumble("Unknown node kind"); |
| 3056 |
return null; |
| 3057 |
} |
| 3058 |
} |
| 3059 |
|
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
protected boolean isNamespaceTestAllowed() { |
| 3067 |
return allowXPath30Syntax; |
| 3068 |
} |
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
|
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
private int getSystemType(String name) throws XPathException { |
| 3079 |
if ("item".equals(name)) { |
| 3080 |
return Type.ITEM; |
| 3081 |
} else if ("document-node".equals(name)) { |
| 3082 |
return Type.DOCUMENT; |
| 3083 |
} else if ("element".equals(name)) { |
| 3084 |
return Type.ELEMENT; |
| 3085 |
} else if ("schema-element".equals(name)) { |
| 3086 |
return Type.ELEMENT; |
| 3087 |
} else if ("attribute".equals(name)) { |
| 3088 |
return Type.ATTRIBUTE; |
| 3089 |
} else if ("schema-attribute".equals(name)) { |
| 3090 |
return Type.ATTRIBUTE; |
| 3091 |
} else if ("text".equals(name)) { |
| 3092 |
return Type.TEXT; |
| 3093 |
} else if ("comment".equals(name)) { |
| 3094 |
return Type.COMMENT; |
| 3095 |
} else if ("processing-instruction".equals(name)) { |
| 3096 |
return Type.PROCESSING_INSTRUCTION; |
| 3097 |
} else if ("namespace-node".equals(name)) { |
| 3098 |
return Type.NAMESPACE; |
| 3099 |
} else if ("node".equals(name)) { |
| 3100 |
return Type.NODE; |
| 3101 |
} else { |
| 3102 |
grumble("Unknown type " + name); |
| 3103 |
return -1; |
| 3104 |
} |
| 3105 |
} |
| 3106 |
|
| 3107 |
|
| 3108 |
|
| 3109 |
|
| 3110 |
|
| 3111 |
|
| 3112 |
|
| 3113 |
protected void checkLanguageVersion30() throws XPathException { |
| 3114 |
if (!allowXPath30Syntax) { |
| 3115 |
grumble("To use XPath 3.0 syntax, you must configure the XPath parser to handle it"); |
| 3116 |
} |
| 3117 |
} |
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
|
| 3122 |
|
| 3123 |
|
| 3124 |
|
| 3125 |
protected void checkLanguageVersion31() throws XPathException { |
| 3126 |
if (!allowXPath31Syntax) { |
| 3127 |
grumble("The XPath parser is not configured to allow use of XPath 3.1 syntax"); |
| 3128 |
} |
| 3129 |
} |
| 3130 |
|
| 3131 |
|
| 3132 |
|
| 3133 |
|
| 3134 |
|
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
protected void checkMapExtensions() throws XPathException { |
| 3139 |
if (!(allowXPath31Syntax || allowXPath30XSLTExtensions)) { |
| 3140 |
grumble("The XPath parser is not configured to allow use of the map syntax from XSLT 3.0 or XPath 3.1"); |
| 3141 |
} |
| 3142 |
} |
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
|
| 3148 |
|
| 3149 |
public void checkSyntaxExtensions(String construct) throws XPathException { |
| 3150 |
if (!allowSaxonExtensions) { |
| 3151 |
grumble("Saxon XPath syntax extensions have not been enabled: " + construct + " is not allowed"); |
| 3152 |
} |
| 3153 |
} |
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
|
| 3158 |
|
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
protected Expression parseMapExpression() throws XPathException { |
| 3166 |
checkMapExtensions(); |
| 3167 |
|
| 3168 |
|
| 3169 |
Tokenizer t = getTokenizer(); |
| 3170 |
int offset = t.currentTokenStartOffset; |
| 3171 |
List<Expression> entries = new ArrayList<>(); |
| 3172 |
nextToken(); |
| 3173 |
if (t.currentToken != Token.RCURLY) { |
| 3174 |
while (true) { |
| 3175 |
Expression key = parseExprSingle(); |
| 3176 |
if (t.currentToken == Token.ASSIGN) { |
| 3177 |
grumble("The ':=' notation is no longer accepted in map expressions: use ':' instead"); |
| 3178 |
} |
| 3179 |
expect(Token.COLON); |
| 3180 |
nextToken(); |
| 3181 |
Expression value = parseExprSingle(); |
| 3182 |
Expression entry; |
| 3183 |
if (key instanceof Literal && ((Literal)key).getValue() instanceof AtomicValue |
| 3184 |
&& value instanceof Literal) { |
| 3185 |
entry = Literal.makeLiteral( |
| 3186 |
new SingleEntryMap((AtomicValue) ((Literal)key).getValue(), |
| 3187 |
((Literal)value).getValue())); |
| 3188 |
} else { |
| 3189 |
entry = MapFunctionSet.getInstance().makeFunction("entry", 2).makeFunctionCall(key, value); |
| 3190 |
} |
| 3191 |
entries.add(entry); |
| 3192 |
if (t.currentToken == Token.RCURLY) { |
| 3193 |
break; |
| 3194 |
} else { |
| 3195 |
expect(Token.COMMA); |
| 3196 |
nextToken(); |
| 3197 |
} |
| 3198 |
} |
| 3199 |
} |
| 3200 |
t.lookAhead(); |
| 3201 |
nextToken(); |
| 3202 |
|
| 3203 |
Expression result; |
| 3204 |
switch (entries.size()) { |
| 3205 |
case 0: |
| 3206 |
result = Literal.makeLiteral(new HashTrieMap()); |
| 3207 |
break; |
| 3208 |
case 1: |
| 3209 |
result = entries.get(0); |
| 3210 |
break; |
| 3211 |
default: |
| 3212 |
Expression[] entriesArray = new Expression[entries.size()]; |
| 3213 |
Block block = new Block(entries.toArray(entriesArray)); |
| 3214 |
DictionaryMap options = new DictionaryMap(); |
| 3215 |
options.initialPut("duplicates", new StringValue("reject")); |
| 3216 |
options.initialPut("duplicates-error-code", new StringValue("XQDY0137")); |
| 3217 |
result = MapFunctionSet.getInstance().makeFunction("merge", 2).makeFunctionCall(block, Literal.makeLiteral(options)); |
| 3218 |
break; |
| 3219 |
} |
| 3220 |
setLocation(result, offset); |
| 3221 |
return result; |
| 3222 |
|
| 3223 |
} |
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
protected Expression parseArraySquareConstructor() throws XPathException { |
| 3231 |
checkLanguageVersion31(); |
| 3232 |
Tokenizer t = getTokenizer(); |
| 3233 |
int offset = t.currentTokenStartOffset; |
| 3234 |
List<Expression> members = new ArrayList<>(); |
| 3235 |
nextToken(); |
| 3236 |
if (t.currentToken == Token.RSQB) { |
| 3237 |
nextToken(); |
| 3238 |
SquareArrayConstructor block = new SquareArrayConstructor(members); |
| 3239 |
setLocation(block, offset); |
| 3240 |
return block; |
| 3241 |
} |
| 3242 |
while (true) { |
| 3243 |
Expression member = parseExprSingle(); |
| 3244 |
members.add(member); |
| 3245 |
if (t.currentToken == Token.COMMA) { |
| 3246 |
nextToken(); |
| 3247 |
continue; |
| 3248 |
} else if (t.currentToken == Token.RSQB) { |
| 3249 |
nextToken(); |
| 3250 |
break; |
| 3251 |
} |
| 3252 |
grumble("Expected ',' or ']', " + |
| 3253 |
"found " + Token.tokens[t.currentToken]); |
| 3254 |
return new ErrorExpression(); |
| 3255 |
} |
| 3256 |
SquareArrayConstructor block = new SquareArrayConstructor(members); |
| 3257 |
setLocation(block, offset); |
| 3258 |
return block; |
| 3259 |
} |
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
protected Expression parseArrayCurlyConstructor() throws XPathException { |
| 3271 |
checkLanguageVersion31(); |
| 3272 |
Tokenizer t = getTokenizer(); |
| 3273 |
int offset = t.currentTokenStartOffset; |
| 3274 |
nextToken(); |
| 3275 |
if (t.currentToken == Token.RCURLY) { |
| 3276 |
t.lookAhead(); |
| 3277 |
nextToken(); |
| 3278 |
return Literal.makeLiteral(SimpleArrayItem.EMPTY_ARRAY); |
| 3279 |
} |
| 3280 |
Expression body = parseExpression(); |
| 3281 |
expect(Token.RCURLY); |
| 3282 |
t.lookAhead(); |
| 3283 |
nextToken(); |
| 3284 |
|
| 3285 |
SystemFunction sf = ArrayFunctionSet.getInstance().makeFunction("_from-sequence", 1); |
| 3286 |
Expression result = sf.makeFunctionCall(body); |
| 3287 |
|
| 3288 |
|
| 3289 |
|
| 3290 |
setLocation(result, offset); |
| 3291 |
return result; |
| 3292 |
} |
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
|
| 3297 |
|
| 3298 |
|
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
public Expression parseFunctionCall(Expression prefixArgument) throws XPathException { |
| 3306 |
|
| 3307 |
String fname = t.currentTokenValue; |
| 3308 |
int offset = t.currentTokenStartOffset; |
| 3309 |
ArrayList<Expression> args = new ArrayList<>(10); |
| 3310 |
if (prefixArgument != null) { |
| 3311 |
args.add(prefixArgument); |
| 3312 |
} |
| 3313 |
|
| 3314 |
StructuredQName functionName = resolveFunctionName(fname); |
| 3315 |
IntSet placeMarkers = null; |
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
nextToken(); |
| 3320 |
if (t.currentToken != Token.RPAR) { |
| 3321 |
while (true) { |
| 3322 |
Expression arg = parseFunctionArgument(); |
| 3323 |
if (arg == null) { |
| 3324 |
|
| 3325 |
if (placeMarkers == null) { |
| 3326 |
placeMarkers = new IntArraySet(); |
| 3327 |
} |
| 3328 |
placeMarkers.add(args.size()); |
| 3329 |
arg = Literal.makeEmptySequence(); |
| 3330 |
} |
| 3331 |
args.add(arg); |
| 3332 |
if (t.currentToken == Token.COMMA) { |
| 3333 |
nextToken(); |
| 3334 |
} else { |
| 3335 |
break; |
| 3336 |
} |
| 3337 |
} |
| 3338 |
expect(Token.RPAR); |
| 3339 |
} |
| 3340 |
nextToken(); |
| 3341 |
|
| 3342 |
if (scanOnly) { |
| 3343 |
return new StringLiteral(StringValue.EMPTY_STRING); |
| 3344 |
} |
| 3345 |
|
| 3346 |
Expression[] arguments = new Expression[args.size()]; |
| 3347 |
args.toArray(arguments); |
| 3348 |
|
| 3349 |
if (placeMarkers != null) { |
| 3350 |
return parserExtension.makeCurriedFunction(this, offset, functionName, arguments, placeMarkers); |
| 3351 |
} |
| 3352 |
|
| 3353 |
Expression fcall; |
| 3354 |
SymbolicName.F sn = new SymbolicName.F(functionName, args.size()); |
| 3355 |
List<String> reasons = new ArrayList<>(); |
| 3356 |
fcall = env.getFunctionLibrary().bind(sn, arguments, env, reasons); |
| 3357 |
if (fcall == null) { |
| 3358 |
return reportMissingFunction(offset, functionName, arguments, reasons); |
| 3359 |
} |
| 3360 |
|
| 3361 |
|
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
|
| 3366 |
if (language == XSLT_PATTERN) { |
| 3367 |
if (fcall.isCallOn(RegexGroup.class)) { |
| 3368 |
return Literal.makeEmptySequence(); |
| 3369 |
} else if (fcall instanceof CurrentGroupCall) { |
| 3370 |
grumble("The current-group() function cannot be used in a pattern", |
| 3371 |
"XTSE1060", offset); |
| 3372 |
return new ErrorExpression(); |
| 3373 |
} else if (fcall instanceof CurrentGroupingKeyCall) { |
| 3374 |
grumble("The current-grouping-key() function cannot be used in a pattern", |
| 3375 |
"XTSE1070", offset); |
| 3376 |
return new ErrorExpression(); |
| 3377 |
} else if (fcall.isCallOn(CurrentMergeGroup.class)) { |
| 3378 |
grumble("The current-merge-group() function cannot be used in a pattern", |
| 3379 |
"XTSE3470", offset); |
| 3380 |
return new ErrorExpression(); |
| 3381 |
} else if (fcall.isCallOn(CurrentMergeKey.class)) { |
| 3382 |
grumble("The current-merge-key() function cannot be used in a pattern", |
| 3383 |
"XTSE3500", offset); |
| 3384 |
return new ErrorExpression(); |
| 3385 |
} |
| 3386 |
} |
| 3387 |
setLocation(fcall, offset); |
| 3388 |
for (Expression argument : arguments) { |
| 3389 |
if (fcall != argument && !functionName.hasURI(NamespaceConstant.GLOBAL_JS)) { |
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
fcall.adoptChildExpression(argument); |
| 3394 |
} |
| 3395 |
} |
| 3396 |
|
| 3397 |
return makeTracer(offset, fcall, LocationKind.FUNCTION_CALL, functionName); |
| 3398 |
|
| 3399 |
} |
| 3400 |
|
| 3401 |
|
| 3402 |
public Expression reportMissingFunction(int offset, StructuredQName functionName, Expression[] arguments, List<String> reasons) throws XPathException { |
| 3403 |
StringBuilder sb = new StringBuilder(); |
| 3404 |
sb.append("Cannot find a ").append(arguments.length).append( |
| 3405 |
"-argument function named ").append(functionName.getEQName()).append("()"); |
| 3406 |
Configuration config = env.getConfiguration(); |
| 3407 |
for (String reason : reasons) { |
| 3408 |
sb.append(". ").append(reason); |
| 3409 |
} |
| 3410 |
if (config.getBooleanProperty(Feature.ALLOW_EXTERNAL_FUNCTIONS)) { |
| 3411 |
boolean existsWithDifferentArity = false; |
| 3412 |
for (int i = 0; i < arguments.length + 5; i++) { |
| 3413 |
if (i != arguments.length) { |
| 3414 |
SymbolicName.F sn = new SymbolicName.F(functionName, i); |
| 3415 |
if (env.getFunctionLibrary().isAvailable(sn)) { |
| 3416 |
existsWithDifferentArity = true; |
| 3417 |
break; |
| 3418 |
} |
| 3419 |
} |
| 3420 |
} |
| 3421 |
if (existsWithDifferentArity) { |
| 3422 |
sb.append(". The namespace URI and local name are recognized, but the number of arguments is wrong"); |
| 3423 |
} else { |
| 3424 |
String supplementary = getMissingFunctionExplanation(functionName, config); |
| 3425 |
if (supplementary != null) { |
| 3426 |
sb.append(". ").append(supplementary); |
| 3427 |
} |
| 3428 |
} |
| 3429 |
} else { |
| 3430 |
sb.append(". External function calls have been disabled"); |
| 3431 |
} |
| 3432 |
if (env.isInBackwardsCompatibleMode()) { |
| 3433 |
|
| 3434 |
return new ErrorExpression(sb.toString(), "XTDE1425", false); |
| 3435 |
} else { |
| 3436 |
grumble(sb.toString(), "XPST0017", offset); |
| 3437 |
return null; |
| 3438 |
} |
| 3439 |
} |
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
|
| 3448 |
public static String getMissingFunctionExplanation(StructuredQName functionName, Configuration config) { |
| 3449 |
String actualURI = functionName.getURI(); |
| 3450 |
String similarNamespace = NamespaceConstant.findSimilarNamespace(actualURI); |
| 3451 |
if (similarNamespace != null) { |
| 3452 |
if (similarNamespace.equals(actualURI)) { |
| 3453 |
switch (similarNamespace) { |
| 3454 |
case NamespaceConstant.FN: |
| 3455 |
String[] hof = new String[]{"apply", "filter", "fold-left", "fold-right", |
| 3456 |
"for-each", "for-each-pair", "function-arity", "function-lookup", "function-name", |
| 3457 |
"load-xquery-module", "random-number-generator"}; |
| 3458 |
if (Arrays.binarySearch(hof, functionName.getLocalPart()) >= 0) { |
| 3459 |
return "Higher-order functions are not available in this Configuration"; |
| 3460 |
} |
| 3461 |
return null; |
| 3462 |
case NamespaceConstant.SAXON: |
| 3463 |
if (config.getEditionCode().equals("HE")) { |
| 3464 |
return "Saxon extension functions are not available under Saxon-HE"; |
| 3465 |
} else if (!config.isLicensedFeature(Configuration.LicenseFeature.PROFESSIONAL_EDITION)) { |
| 3466 |
return "Saxon extension functions require a Saxon-PE or Saxon-EE license"; |
| 3467 |
} |
| 3468 |
break; |
| 3469 |
case NamespaceConstant.XSLT: |
| 3470 |
if (functionName.getLocalPart().equals("original")) { |
| 3471 |
return "Function name xsl:original is only available within an overriding function"; |
| 3472 |
} else { |
| 3473 |
return "There are no functions defined in the XSLT namespace"; |
| 3474 |
} |
| 3475 |
} |
| 3476 |
} else { |
| 3477 |
return "Perhaps the intended namespace was '" + similarNamespace + "'"; |
| 3478 |
} |
| 3479 |
} else if (actualURI.contains("java")) { |
| 3480 |
if (config.getEditionCode().equals("HE")) { |
| 3481 |
return "Reflexive calls to Java methods are not available under Saxon-HE"; |
| 3482 |
} else if (!config.isLicensedFeature(Configuration.LicenseFeature.PROFESSIONAL_EDITION)) { |
| 3483 |
return "Reflexive calls to Java methods require a Saxon-PE or Saxon-EE license, and none was found"; |
| 3484 |
} else { |
| 3485 |
return "For diagnostics on calls to Java methods, use the -TJ command line option " + |
| 3486 |
"or set the Configuration property FeatureKeys.TRACE_EXTERNAL_FUNCTIONS"; |
| 3487 |
} |
| 3488 |
} else if (actualURI.startsWith("clitype:")) { |
| 3489 |
if (config.getEditionCode().equals("HE")) { |
| 3490 |
return "Reflexive calls to external .NET methods are not available under Saxon-HE"; |
| 3491 |
} else if (!config.isLicensedFeature(Configuration.LicenseFeature.PROFESSIONAL_EDITION)) { |
| 3492 |
return "Reflexive calls to external .NET methods require a Saxon-PE or Saxon-EE license, and none was found"; |
| 3493 |
} else { |
| 3494 |
return "For diagnostics on calls to .NET methods, use the -TJ command line option " + |
| 3495 |
"or call processor.SetProperty(\"http://saxon.sf.net/feature/trace-external-functions\", \"true\")"; |
| 3496 |
} |
| 3497 |
} |
| 3498 |
return null; |
| 3499 |
} |
| 3500 |
|
| 3501 |
|
| 3502 |
|
| 3503 |
|
| 3504 |
|
| 3505 |
|
| 3506 |
|
| 3507 |
|
| 3508 |
|
| 3509 |
|
| 3510 |
|
| 3511 |
|
| 3512 |
protected StructuredQName resolveFunctionName(String fname) throws XPathException { |
| 3513 |
if (scanOnly) { |
| 3514 |
return new StructuredQName("", NamespaceConstant.SAXON, "dummy"); |
| 3515 |
} |
| 3516 |
StructuredQName functionName = null; |
| 3517 |
qNameParser.setDefaultNamespace(env.getDefaultFunctionNamespace()); |
| 3518 |
try { |
| 3519 |
functionName = qNameParser.parse(fname); |
| 3520 |
} catch (XPathException e) { |
| 3521 |
grumble(e.getMessage(), e.getErrorCodeLocalPart()); |
| 3522 |
assert false; |
| 3523 |
} |
| 3524 |
|
| 3525 |
if (functionName.hasURI(NamespaceConstant.SCHEMA)) { |
| 3526 |
ItemType t = Type.getBuiltInItemType(functionName.getURI(), functionName.getLocalPart()); |
| 3527 |
if (t instanceof BuiltInAtomicType) { |
| 3528 |
checkAllowedType(env, (BuiltInAtomicType) t); |
| 3529 |
} |
| 3530 |
} |
| 3531 |
return functionName; |
| 3532 |
} |
| 3533 |
|
| 3534 |
|
| 3535 |
|
| 3536 |
|
| 3537 |
|
| 3538 |
|
| 3539 |
|
| 3540 |
|
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
public Expression parseFunctionArgument() throws XPathException { |
| 3545 |
if (t.currentToken == Token.QMARK) { |
| 3546 |
int next = t.peekAhead(); |
| 3547 |
if (next == Token.COMMA || next == Token.RPAR) { |
| 3548 |
nextToken(); |
| 3549 |
return parserExtension.makeArgumentPlaceMarker(this); |
| 3550 |
} |
| 3551 |
} |
| 3552 |
return parseExprSingle(); |
| 3553 |
} |
| 3554 |
|
| 3555 |
|
| 3556 |
|
| 3557 |
|
| 3558 |
|
| 3559 |
|
| 3560 |
|
| 3561 |
|
| 3562 |
|
| 3563 |
|
| 3564 |
|
| 3565 |
protected Expression parseNamedFunctionReference() throws XPathException { |
| 3566 |
return parserExtension.parseNamedFunctionReference(this); |
| 3567 |
} |
| 3568 |
|
| 3569 |
|
| 3570 |
|
| 3571 |
|
| 3572 |
|
| 3573 |
|
| 3574 |
|
| 3575 |
|
| 3576 |
protected AnnotationList parseAnnotationsList() throws XPathException { |
| 3577 |
grumble("Inline functions are not allowed in Saxon-HE"); |
| 3578 |
return null; |
| 3579 |
} |
| 3580 |
|
| 3581 |
|
| 3582 |
|
| 3583 |
|
| 3584 |
|
| 3585 |
|
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
protected Expression parseInlineFunction(AnnotationList annotations) throws XPathException { |
| 3593 |
return parserExtension.parseInlineFunction(this, annotations); |
| 3594 |
} |
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
|
| 3599 |
|
| 3600 |
|
| 3601 |
|
| 3602 |
|
| 3603 |
|
| 3604 |
|
| 3605 |
|
| 3606 |
|
| 3607 |
|
| 3608 |
|
| 3609 |
protected Expression makeCurriedFunction( |
| 3610 |
int offset, StructuredQName name, Expression[] args, IntSet placeMarkers) |
| 3611 |
throws XPathException { |
| 3612 |
grumble("Partial function application is not allowed in Saxon-HE"); |
| 3613 |
return new ErrorExpression(); |
| 3614 |
} |
| 3615 |
|
| 3616 |
|
| 3617 |
|
| 3618 |
private final static String[] reservedFunctionNames30 = new String[]{ |
| 3619 |
"attribute", "comment", "document-node", "element", "empty-sequence", "function", "if", "item", |
| 3620 |
"namespace-node", "node", "processing-instruction", "schema-attribute", "schema-element", "switch", "text", "typeswitch" |
| 3621 |
}; |
| 3622 |
|
| 3623 |
|
| 3624 |
|
| 3625 |
|
| 3626 |
|
| 3627 |
|
| 3628 |
|
| 3629 |
|
| 3630 |
protected static boolean isReservedFunctionName30(String name) { |
| 3631 |
int x = Arrays.binarySearch(reservedFunctionNames30, name); |
| 3632 |
return x >= 0; |
| 3633 |
} |
| 3634 |
|
| 3635 |
|
| 3636 |
|
| 3637 |
private final static String[] reservedFunctionNames31 = new String[]{ |
| 3638 |
"array", "attribute", "comment", "document-node", "element", "empty-sequence", "function", "if", "item", "map", |
| 3639 |
"namespace-node", "node", "processing-instruction", "schema-attribute", "schema-element", "switch", "text", "typeswitch" |
| 3640 |
}; |
| 3641 |
|
| 3642 |
|
| 3643 |
|
| 3644 |
|
| 3645 |
|
| 3646 |
|
| 3647 |
|
| 3648 |
|
| 3649 |
public static boolean isReservedFunctionName31(String name) { |
| 3650 |
int x = Arrays.binarySearch(reservedFunctionNames31, name); |
| 3651 |
return x >= 0; |
| 3652 |
} |
| 3653 |
|
| 3654 |
|
| 3655 |
|
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
|
| 3660 |
|
| 3661 |
|
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
public Stack<LocalBinding> getRangeVariables() { |
| 3666 |
return rangeVariables; |
| 3667 |
} |
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
|
| 3673 |
|
| 3674 |
|
| 3675 |
public void setRangeVariables(Stack<LocalBinding> variables) { |
| 3676 |
this.rangeVariables = variables; |
| 3677 |
} |
| 3678 |
|
| 3679 |
|
| 3680 |
|
| 3681 |
|
| 3682 |
|
| 3683 |
|
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
public void declareRangeVariable(LocalBinding declaration) { |
| 3688 |
rangeVariables.push(declaration); |
| 3689 |
} |
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
|
| 3695 |
public void undeclareRangeVariable() { |
| 3696 |
rangeVariables.pop(); |
| 3697 |
} |
| 3698 |
|
| 3699 |
|
| 3700 |
|
| 3701 |
|
| 3702 |
|
| 3703 |
|
| 3704 |
|
| 3705 |
|
| 3706 |
|
| 3707 |
|
| 3708 |
|
| 3709 |
protected LocalBinding findRangeVariable(StructuredQName qName) { |
| 3710 |
for (int v = rangeVariables.size() - 1; v >= 0; v--) { |
| 3711 |
LocalBinding b = rangeVariables.elementAt(v); |
| 3712 |
if (b.getVariableQName().equals(qName)) { |
| 3713 |
return b; |
| 3714 |
} |
| 3715 |
} |
| 3716 |
return parserExtension.findOuterRangeVariable(this, qName); |
| 3717 |
} |
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
|
| 3726 |
public void setRangeVariableStack(Stack<LocalBinding> stack) { |
| 3727 |
rangeVariables = stack; |
| 3728 |
} |
| 3729 |
|
| 3730 |
|
| 3731 |
|
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
|
| 3738 |
|
| 3739 |
|
| 3740 |
|
| 3741 |
|
| 3742 |
|
| 3743 |
|
| 3744 |
public final int makeFingerprint( String qname, boolean useDefault) throws XPathException { |
| 3745 |
if (scanOnly) { |
| 3746 |
return StandardNames.XML_SPACE; |
| 3747 |
} |
| 3748 |
try { |
| 3749 |
qNameParser.setDefaultNamespace(useDefault ? env.getDefaultElementNamespace() : ""); |
| 3750 |
StructuredQName sq = qNameParser.parse(qname); |
| 3751 |
return env.getConfiguration().getNamePool().allocateFingerprint(sq.getURI(), sq.getLocalPart()); |
| 3752 |
} catch (XPathException e) { |
| 3753 |
grumble(e.getMessage(), e.getErrorCodeLocalPart()); |
| 3754 |
return -1; |
| 3755 |
} |
| 3756 |
} |
| 3757 |
|
| 3758 |
|
| 3759 |
|
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
|
| 3764 |
|
| 3765 |
|
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
public final StructuredQName makeStructuredQNameSilently( String qname, String defaultUri) |
| 3772 |
throws XPathException { |
| 3773 |
if (scanOnly) { |
| 3774 |
return new StructuredQName("", NamespaceConstant.SAXON, "dummy"); |
| 3775 |
} |
| 3776 |
qNameParser.setDefaultNamespace(defaultUri); |
| 3777 |
return qNameParser.parse(qname); |
| 3778 |
} |
| 3779 |
|
| 3780 |
|
| 3781 |
|
| 3782 |
|
| 3783 |
|
| 3784 |
|
| 3785 |
|
| 3786 |
|
| 3787 |
|
| 3788 |
|
| 3789 |
|
| 3790 |
|
| 3791 |
|
| 3792 |
public final StructuredQName makeStructuredQName( String qname, String defaultUri) throws XPathException { |
| 3793 |
try { |
| 3794 |
return makeStructuredQNameSilently(qname, defaultUri); |
| 3795 |
} catch (XPathException err) { |
| 3796 |
grumble(err.getMessage(), err.getErrorCodeLocalPart()); |
| 3797 |
return new StructuredQName("", "", "error"); |
| 3798 |
} |
| 3799 |
} |
| 3800 |
|
| 3801 |
|
| 3802 |
|
| 3803 |
|
| 3804 |
|
| 3805 |
|
| 3806 |
|
| 3807 |
|
| 3808 |
|
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
public final NodeName makeNodeName(String qname, boolean useDefault) throws XPathException { |
| 3816 |
StructuredQName sq = makeStructuredQNameSilently(qname, useDefault ? env.getDefaultElementNamespace() : ""); |
| 3817 |
String prefix = sq.getPrefix(); |
| 3818 |
String uri = sq.getURI(); |
| 3819 |
String local = sq.getLocalPart(); |
| 3820 |
if (uri.isEmpty()) { |
| 3821 |
int fp = env.getConfiguration().getNamePool().allocateFingerprint("", qname); |
| 3822 |
return new NoNamespaceName(qname, fp); |
| 3823 |
} else { |
| 3824 |
int fp = env.getConfiguration().getNamePool().allocateFingerprint(uri, local); |
| 3825 |
return new FingerprintedQName(prefix, uri, local, fp); |
| 3826 |
} |
| 3827 |
} |
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
public NameTest makeNameTest(short nodeType, String qname, boolean useDefault) |
| 3846 |
throws XPathException { |
| 3847 |
NamePool pool = env.getConfiguration().getNamePool(); |
| 3848 |
StructuredQName q = makeStructuredQName(qname, useDefault ? env.getDefaultElementNamespace() : ""); |
| 3849 |
assert q != null; |
| 3850 |
int fp = pool.allocateFingerprint(q.getURI(), q.getLocalPart()); |
| 3851 |
return new NameTest(nodeType, fp, pool); |
| 3852 |
} |
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
public NamespaceTest makeNamespaceTest(short nodeType, String prefix) |
| 3866 |
throws XPathException { |
| 3867 |
NamePool pool = env.getConfiguration().getNamePool(); |
| 3868 |
if (scanOnly) { |
| 3869 |
|
| 3870 |
return new NamespaceTest(pool, nodeType, NamespaceConstant.SAXON); |
| 3871 |
} |
| 3872 |
if (prefix.startsWith("Q{")) { |
| 3873 |
String uri = prefix.substring(2, prefix.length() - 2); |
| 3874 |
return new NamespaceTest(pool, nodeType, uri); |
| 3875 |
} |
| 3876 |
try { |
| 3877 |
StructuredQName sq = qNameParser.parse(prefix + ":dummy"); |
| 3878 |
return new NamespaceTest(pool, nodeType, sq.getURI()); |
| 3879 |
} catch (XPathException err) { |
| 3880 |
grumble(err.getMessage(), err.getErrorCodeLocalPart()); |
| 3881 |
return null; |
| 3882 |
} |
| 3883 |
} |
| 3884 |
|
| 3885 |
|
| 3886 |
|
| 3887 |
|
| 3888 |
|
| 3889 |
|
| 3890 |
|
| 3891 |
|
| 3892 |
|
| 3893 |
|
| 3894 |
|
| 3895 |
|
| 3896 |
public LocalNameTest makeLocalNameTest(short nodeType, String localName) |
| 3897 |
throws XPathException { |
| 3898 |
if (!NameChecker.isValidNCName(localName)) { |
| 3899 |
grumble("Local name [" + localName + "] contains invalid characters"); |
| 3900 |
} |
| 3901 |
return new LocalNameTest(env.getConfiguration().getNamePool(), nodeType, localName); |
| 3902 |
} |
| 3903 |
|
| 3904 |
|
| 3905 |
|
| 3906 |
|
| 3907 |
|
| 3908 |
|
| 3909 |
|
| 3910 |
|
| 3911 |
protected void setLocation( Expression exp) { |
| 3912 |
setLocation(exp, t.currentTokenStartOffset); |
| 3913 |
} |
| 3914 |
|
| 3915 |
|
| 3916 |
|
| 3917 |
|
| 3918 |
|
| 3919 |
|
| 3920 |
|
| 3921 |
|
| 3922 |
|
| 3923 |
|
| 3924 |
|
| 3925 |
public void setLocation(Expression exp, int offset) { |
| 3926 |
if (exp != null) { |
| 3927 |
int line = t.getLineNumber(offset); |
| 3928 |
int column = t.getColumnNumber(offset); |
| 3929 |
if (exp.getLocation() == null || exp.getLocation() == ExplicitLocation.UNKNOWN_LOCATION) { |
| 3930 |
Location loc = makeNestedLocation(env.getContainingLocation(), line, column, null); |
| 3931 |
exp.setLocation(loc); |
| 3932 |
} |
| 3933 |
} |
| 3934 |
} |
| 3935 |
|
| 3936 |
|
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
|
| 3944 |
|
| 3945 |
public void setLocation(Clause clause, int offset) { |
| 3946 |
int line = t.getLineNumber(offset); |
| 3947 |
int column = t.getColumnNumber(offset); |
| 3948 |
Location loc = makeNestedLocation(env.getContainingLocation(), line, column, null); |
| 3949 |
clause.setLocation(loc); |
| 3950 |
clause.setPackageData(env.getPackageData()); |
| 3951 |
} |
| 3952 |
|
| 3953 |
private Location mostRecentLocation = ExplicitLocation.UNKNOWN_LOCATION; |
| 3954 |
|
| 3955 |
public Location makeLocation() { |
| 3956 |
if (t.getLineNumber() == mostRecentLocation.getLineNumber() && |
| 3957 |
t.getColumnNumber() == mostRecentLocation.getColumnNumber() && |
| 3958 |
((env.getSystemId() == null && mostRecentLocation.getSystemId() == null) || |
| 3959 |
env.getSystemId().equals(mostRecentLocation.getSystemId()))) { |
| 3960 |
return mostRecentLocation; |
| 3961 |
} else { |
| 3962 |
int line = t.getLineNumber(); |
| 3963 |
int column = t.getColumnNumber(); |
| 3964 |
mostRecentLocation = makeNestedLocation(env.getContainingLocation(), line, column, null); |
| 3965 |
return mostRecentLocation; |
| 3966 |
} |
| 3967 |
} |
| 3968 |
|
| 3969 |
|
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
|
| 3977 |
|
| 3978 |
public Location makeNestedLocation(Location containingLoc, int line, int column, String nearbyText) { |
| 3979 |
if (containingLoc instanceof ExplicitLocation && |
| 3980 |
containingLoc.getLineNumber() <= 1 && containingLoc.getColumnNumber() == -1 && |
| 3981 |
nearbyText == null) { |
| 3982 |
|
| 3983 |
return new ExplicitLocation(env.getSystemId(), line + 1, column + 1); |
| 3984 |
} else { |
| 3985 |
return new NestedLocation(containingLoc, line, column, nearbyText); |
| 3986 |
} |
| 3987 |
} |
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
|
| 3996 |
|
| 3997 |
|
| 3998 |
|
| 3999 |
|
| 4000 |
public Expression makeTracer(int startOffset, Expression exp, int construct, StructuredQName qName) { |
| 4001 |
exp.setRetainedStaticContextLocally(env.makeRetainedStaticContext()); |
| 4002 |
if (codeInjector != null) { |
| 4003 |
return codeInjector.inject(exp, env, construct, qName); |
| 4004 |
} else { |
| 4005 |
return exp; |
| 4006 |
} |
| 4007 |
} |
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
|
| 4016 |
protected boolean isKeyword(String s) { |
| 4017 |
return t.currentToken == Token.NAME && t.currentTokenValue.equals(s); |
| 4018 |
} |
| 4019 |
|
| 4020 |
|
| 4021 |
|
| 4022 |
|
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
public void setScanOnly(boolean scanOnly) { |
| 4029 |
this.scanOnly = scanOnly; |
| 4030 |
} |
| 4031 |
|
| 4032 |
|
| 4033 |
|
| 4034 |
|
| 4035 |
|
| 4036 |
|
| 4037 |
|
| 4038 |
|
| 4039 |
|
| 4040 |
public void setAllowAbsentExpression(boolean allowEmpty) { |
| 4041 |
this.allowAbsentExpression = allowEmpty; |
| 4042 |
} |
| 4043 |
|
| 4044 |
|
| 4045 |
|
| 4046 |
|
| 4047 |
|
| 4048 |
|
| 4049 |
|
| 4050 |
|
| 4051 |
|
| 4052 |
public boolean isAllowAbsentExpression(boolean allowEmpty) { |
| 4053 |
return this.allowAbsentExpression; |
| 4054 |
} |
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
public void checkHofFeature() { |
| 4063 |
env.getConfiguration().checkLicensedFeature(Configuration.LicenseFeature.PROFESSIONAL_EDITION, "higher-order functions", -1); |
| 4064 |
} |
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
|
| 4071 |
|
| 4072 |
|
| 4073 |
public static class NestedLocation implements Location { |
| 4074 |
|
| 4075 |
private final Location containingLocation; |
| 4076 |
private final int localLineNumber; |
| 4077 |
private final int localColumnNumber; |
| 4078 |
private String nearbyText; |
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
|
| 4085 |
|
| 4086 |
|
| 4087 |
|
| 4088 |
public NestedLocation(Location containingLocation, int localLineNumber, int localColumnNumber) { |
| 4089 |
this.containingLocation = containingLocation.saveLocation(); |
| 4090 |
this.localLineNumber = localLineNumber; |
| 4091 |
this.localColumnNumber = localColumnNumber; |
| 4092 |
} |
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
|
| 4097 |
|
| 4098 |
|
| 4099 |
|
| 4100 |
|
| 4101 |
|
| 4102 |
|
| 4103 |
|
| 4104 |
public NestedLocation(Location containingLocation, int localLineNumber, int localColumnNumber, String nearbyText) { |
| 4105 |
this.containingLocation = containingLocation.saveLocation(); |
| 4106 |
this.localLineNumber = localLineNumber; |
| 4107 |
this.localColumnNumber = localColumnNumber; |
| 4108 |
this.nearbyText = nearbyText; |
| 4109 |
} |
| 4110 |
|
| 4111 |
|
| 4112 |
|
| 4113 |
|
| 4114 |
|
| 4115 |
|
| 4116 |
|
| 4117 |
|
| 4118 |
|
| 4119 |
public Location getContainingLocation() { |
| 4120 |
return containingLocation; |
| 4121 |
} |
| 4122 |
|
| 4123 |
|
| 4124 |
|
| 4125 |
|
| 4126 |
|
| 4127 |
|
| 4128 |
|
| 4129 |
|
| 4130 |
|
| 4131 |
|
| 4132 |
|
| 4133 |
public int getColumnNumber() { |
| 4134 |
return localColumnNumber; |
| 4135 |
} |
| 4136 |
|
| 4137 |
|
| 4138 |
|
| 4139 |
|
| 4140 |
|
| 4141 |
|
| 4142 |
|
| 4143 |
|
| 4144 |
public String getSystemId() { |
| 4145 |
return containingLocation.getSystemId(); |
| 4146 |
} |
| 4147 |
|
| 4148 |
|
| 4149 |
|
| 4150 |
|
| 4151 |
|
| 4152 |
|
| 4153 |
|
| 4154 |
|
| 4155 |
public String getPublicId() { |
| 4156 |
return containingLocation.getPublicId(); |
| 4157 |
} |
| 4158 |
|
| 4159 |
|
| 4160 |
|
| 4161 |
|
| 4162 |
|
| 4163 |
|
| 4164 |
|
| 4165 |
|
| 4166 |
|
| 4167 |
|
| 4168 |
|
| 4169 |
|
| 4170 |
public int getLocalLineNumber() { |
| 4171 |
return localLineNumber; |
| 4172 |
} |
| 4173 |
|
| 4174 |
|
| 4175 |
|
| 4176 |
|
| 4177 |
|
| 4178 |
|
| 4179 |
|
| 4180 |
|
| 4181 |
public int getLineNumber() { |
| 4182 |
return containingLocation.getLineNumber() + localLineNumber; |
| 4183 |
} |
| 4184 |
|
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
public String getNearbyText() { |
| 4193 |
return nearbyText; |
| 4194 |
} |
| 4195 |
|
| 4196 |
|
| 4197 |
|
| 4198 |
|
| 4199 |
|
| 4200 |
|
| 4201 |
|
| 4202 |
|
| 4203 |
public Location saveLocation() { |
| 4204 |
return this; |
| 4205 |
} |
| 4206 |
} |
| 4207 |
|
| 4208 |
} |
| 4209 |
|
| 4210 |
|
| 4211 |
|
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
|
| 4216 |
|
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
|
| 4224 |
|
| 4225 |
|
| 4226 |
|
| 4227 |
|
| 4228 |
|
| 4229 |
|
| 4230 |
|
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
|
| 4237 |
|
| 4238 |
|
| 4239 |
|
| 4240 |
|
| 4241 |
|