protected ProcessingInstructionTest parsePITest( TokenStream tokens ) { if (tokens.canConsume("processing-instruction", "(")) { if (tokens.canConsume(")")) return new ProcessingInstructionTest(null); String nameOrStringLiteral = tokens.consume(); tokens.consume(")"); return new ProcessingInstructionTest(nameOrStringLiteral); } return null; }
protected ProcessingInstructionTest parsePITest( TokenStream tokens ) { if (tokens.canConsume("processing-instruction", "(")) { if (tokens.canConsume(")")) return new ProcessingInstructionTest(null); String nameOrStringLiteral = tokens.consume(); tokens.consume(")"); return new ProcessingInstructionTest(nameOrStringLiteral); } return null; }
protected List<Component> parsePredicates( TokenStream tokens ) { List<Component> predicates = new ArrayList<Component>(); while (tokens.canConsume('[')) { predicates.add(collapse(parseExpr(tokens))); tokens.consume(']'); } return predicates; }
protected FunctionCall parseFunctionCall( TokenStream tokens ) { NameTest name = parseQName(tokens); tokens.consume("("); List<Component> args = new ArrayList<Component>(); if (!tokens.matches(')')) { do { args.add(collapse(parseExprSingle(tokens))); } while (tokens.canConsume(",")); } tokens.consume(")"); return new FunctionCall(name, args); }
@Test public void shouldConsumeInCaseInsensitiveMannerWithExpectedValuesWhenMatchingNonExactCase() { makeCaseInsensitive(); tokens.consume("SELECT"); tokens.consume("ALL"); tokens.consume("COLUMNS"); tokens.consume("FROM"); tokens.consume("THIS"); tokens.consume("TABLE"); assertThat(tokens.hasNext(), is(false)); }
protected Literal parseStringLiteral( TokenStream tokens ) { boolean removeQuotes = tokens.matches(XPathTokenizer.QUOTED_STRING); String value = tokens.consume(); if (removeQuotes) value = removeQuotes(value); return new Literal(value); }
protected SchemaElementTest parseSchemaElementTest( TokenStream tokens ) { if (tokens.canConsume("schema-element", "(")) { NameTest elementDeclarationName = parseNameTest(tokens); SchemaElementTest result = new SchemaElementTest(elementDeclarationName); tokens.consume(")"); return result; } return null; }
protected SchemaAttributeTest parseSchemaAttributeTest( TokenStream tokens ) { if (tokens.canConsume("schema-attribute", "(")) { NameTest attributeDeclarationName = parseNameTest(tokens); SchemaAttributeTest result = new SchemaAttributeTest(attributeDeclarationName); tokens.consume(")"); return result; } return null; }
protected String parseNCName( TokenStream tokens ) { String name = tokens.consume(); if (!XmlCharacters.isValidNcName(name)) { throw new ParsingException(tokens.previousPosition(), "Expected valid NCName but found " + name); } return name; }
protected SchemaElementTest parseSchemaElementTest( TokenStream tokens ) { if (tokens.canConsume("schema-element", "(")) { NameTest elementDeclarationName = parseNameTest(tokens); SchemaElementTest result = new SchemaElementTest(elementDeclarationName); tokens.consume(")"); return result; } return null; }
protected Term parseTerm( TokenStream tokens ) { boolean negated = tokens.canConsume('-'); if (!negated) tokens.canConsume('+'); Term result = new SimpleTerm(removeQuotes(tokens.consume())); return negated ? new NegationTerm(result) : result; }
protected Term parseTerm( TokenStream tokens ) { boolean negated = tokens.canConsume('-'); if (!negated) tokens.canConsume('+'); Term result = new SimpleTerm(removeQuotes(tokens.consume())); return negated ? new NegationTerm(result) : result; }
@Test( expected = ParsingException.class ) public void shouldFailToConsumeMultipleTokensIfTheyDoNotMatch() { makeCaseInsensitive(); tokens.consume("SELECT", "ALL", "COLUMNS", "FROM", "TABLE"); }
@FixFor( "MODE-2497" ) @Test public void shouldConsumeCaseInsensitiveStringInOriginalCase() { makeCaseInsensitive(); String firstToken = tokens.consume(); assertThat(firstToken, is("Select")); }
protected NameTest parseQName( TokenStream tokens ) { String firstPart = parseNCName(tokens); if (tokens.canConsume(':')) { String secondPart = tokens.consume(); return new NameTest(decode(firstPart), decode(secondPart)); } return new NameTest(null, decode(firstPart)); }
protected BindVariableName parseBindVariableName( TokenStream tokens, TypeSystem typeSystem ) { // The variable name must conform to a valid prefix, which is defined as a valid NCName ... String value = tokens.consume(); if (!XmlCharacters.isValidNcName(value)) { Position pos = tokens.previousPosition(); String msg = GraphI18n.bindVariableMustConformToNcName.text(value, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } return bindVariableName(value); }
@Test public void shouldFindPreviousPositionStartIndex() { makeCaseInsensitive(); // "Select all columns from this table"; tokens.consume(); tokens.consume(); // previous position should be line 1, column 8 assertThat(tokens.previousPosition().getIndexInContent(), is(7)); assertThat(tokens.previousPosition().getColumn(), is(8)); assertThat(tokens.previousPosition().getLine(), is(1)); }