protected Term parseDisjunctedTerms( TokenStream tokens ) { List<Term> terms = new ArrayList<Term>(); do { Term term = parseTerm(tokens); if (term == null) break; terms.add(term); } while (tokens.hasNext() && !tokens.matches("OR")); if (terms.isEmpty()) return null; return terms.size() > 1 ? new Conjunction(terms) : terms.iterator().next(); }
protected Term parseDisjunctedTerms( TokenStream tokens ) { List<Term> terms = new ArrayList<Term>(); do { Term term = parseTerm(tokens); if (term == null) break; terms.add(term); } while (tokens.hasNext() && !tokens.matches("OR")); if (terms.isEmpty()) return null; return terms.size() > 1 ? new Conjunction(terms) : terms.iterator().next(); }
protected Term parseDisjunctedTerms( TokenStream tokens ) { List<Term> terms = new ArrayList<Term>(); do { Term term = parseTerm(tokens); if (term == null) break; terms.add(term); } while (tokens.hasNext() && !tokens.matches("OR")); if (terms.isEmpty()) return null; return terms.size() > 1 ? new Conjunction(terms) : terms.iterator().next(); }
protected Component parseExpr( TokenStream tokens ) { Component result = parseExprSingle(tokens); if (tokens.matches(',')) { throw new ParsingException(tokens.nextPosition(), "Multiple XPath expressions are not supported"); } return result; }
protected Component parseTreatExpr( TokenStream tokens ) { Component result = parseCastableExpr(tokens); if (tokens.matches("treat", "as")) { throw new ParsingException(tokens.nextPosition(), "XPath 'treat as' expressions are not supported"); } return result; }
protected Component parseRangeExpr( TokenStream tokens ) { Component result = parseAdditiveExpr(tokens); if (tokens.matches("to")) { throw new ParsingException(tokens.nextPosition(), "XPath range expressions with 'to' are not supported"); } return result; }
protected Component parseInstanceofExpr( TokenStream tokens ) { Component result = parseTreatExpr(tokens); if (tokens.matches("instance", "of")) { throw new ParsingException(tokens.nextPosition(), "XPath 'instance of' expressions are not supported"); } return result; }
protected Component parseRangeExpr( TokenStream tokens ) { Component result = parseAdditiveExpr(tokens); if (tokens.matches("to")) { throw new ParsingException(tokens.nextPosition(), "XPath range expressions with 'to' are not supported"); } return result; }
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 Component parseInstanceofExpr( TokenStream tokens ) { Component result = parseTreatExpr(tokens); if (tokens.matches("instance", "of")) { throw new ParsingException(tokens.nextPosition(), "XPath 'instance of' expressions are not supported"); } return result; }
protected Component parseCastableExpr( TokenStream tokens ) { Component result = parseCastExpr(tokens); if (tokens.matches("castable", "as")) { throw new ParsingException(tokens.nextPosition(), "XPath 'castable as' expressions are not supported"); } return result; }
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 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 shouldReturnTrueFromMatchesWithCaseSensitiveTokenStreamIfMatchStringDoesMatchCaseExactly() { makeCaseSensitive(); assertThat(tokens.matches("Select"), is(true)); assertThat(tokens.matches("select"), is(false)); assertThat(tokens.canConsume("Select"), is(true)); assertThat(tokens.matches("all"), is(true)); assertThat(tokens.canConsume("all"), is(true)); }
@Test public void shouldReturnTrueFromMatchIfAllTypeValuesMatch() { makeCaseInsensitive(); assertThat(tokens.matches(BasicTokenizer.WORD, BasicTokenizer.WORD), is(true)); }
@Test( expected = IllegalStateException.class ) public void shouldNotAllowMatchesBeforeStartIsCalled() { tokens = new TokenStream(content, TokenStream.basicTokenizer(false), false); tokens.matches("Select"); }
@Test public void shouldReturnTrueFromCanConsumeArrayOfTokensIfTheyAllMatch() { makeCaseInsensitive(); assertThat(tokens.matches(new String[] {"SELECT", "ALL", "COLUMNS", "FROM", "THIS", "TABLE"}), is(true)); assertThat(tokens.canConsume(new String[] {"SELECT", "ALL", "COLUMNS", "FROM", "THIS", "TABLE"}), is(true)); assertThat(tokens.hasNext(), is(false)); }