private String readOp() { if (isNotEqual()) { reader.consume(2); return "<>"; } if (reader.current().is('<') && reader.next().is('=')) { reader.consume(2); return "<="; } if (reader.current().is('>') && reader.next().is('=')) { reader.consume(2); return ">="; } if (reader.current().is('=') || reader.current().is(':')) { reader.consume(); return "="; } if (reader.current().is('>')) { reader.consume(); return ">"; } if (reader.current().is('<')) { reader.consume(); return "<"; } else { throw new IllegalStateException(reader.current().toString()); } }
/** * Creates a new tokenizer for the given input * * @param input the input to parse. The reader will be buffered by the implementation so that it can be effectively * read character b character. */ public Tokenizer(Reader input) { this.input = new LookaheadReader(input); this.input.setProblemCollector(problemCollector); // Setup default string handling addStringDelimiter('"', '\\'); addStringDelimiter('\'', '\0'); }
/** * Determines if the underlying input is looking at a valid character to start an identifier * <p> * By default, only letters can start identifiers * * @return <tt>true</tt> if the underlying input is looking at a valid identifier starter, <tt>false</tt> otherwise */ protected boolean isAtStartOfIdentifier() { return input.current().isLetter(); }
/** * Checks if the next characters, starting from the current, match the given string. * * @param string the string to check * @param consume determines if the matched string should be consumed immediately * @return <tt>true</tt> if the next characters of the input match the given string, <tt>false</tt> * otherwise */ protected boolean canConsumeThisString(String string, boolean consume) { if (string == null) { return false; } for (int i = 0; i < string.length(); i++) { if (!input.next(i).is(string.charAt(i))) { return false; } } if (consume) { input.consume(string.length()); } return true; }
@Override public QueryBuilder createQuery() { if (parsed.firstCall()) { LookaheadReader reader = new LookaheadReader(new StringReader(input)); QueryBuilder main = parseQuery(reader); if (!reader.current().isEndOfInput()) { IndexAccess.LOG.FINE("Unexpected character in query: " + reader.current()); } // If we cannot compile a query from a non empty input, we probably dropped all short tokens // like a search for "S 8" would be completely dropped. Therefore we resort to "S8". if (main == null && !Strings.isEmpty(input) && input.contains(" ")) { reader = new LookaheadReader(new StringReader(input.replaceAll("\\s", ""))); main = parseQuery(reader); } finishedQuery = main; } return finishedQuery; }
@Override protected boolean handleStringEscape(char separator, char escapeChar, Token stringToken) { // All escaped characters will be kept in original form... stringToken.addToContent(input.consume()); return true; }
@Override protected boolean isIdentifierChar(Char current) { if (super.isIdentifierChar(current)) { return true; } // CSS selectors can contain "-", "." or "#" as long as it is not the last character of the token return (current.is('-') || current.is('.') || current.is('#')) && !input.next().isWhitepace(); }
/** * Creates a new instance for the given factory entity and query. * * @param factory the factory used to create constraints * @param descriptor the descriptor of entities being queried * @param query the query to compile * @param searchFields the default search fields to query */ protected QueryCompiler(FilterFactory<C> factory, EntityDescriptor descriptor, String query, List<QueryField> searchFields) { this.factory = factory; this.descriptor = descriptor; this.searchFields = searchFields; this.reader = new LookaheadReader(new StringReader(query)); }
@Override public void setProblemCollector(List<ParseError> problemCollector) { super.setProblemCollector(problemCollector); this.input.setProblemCollector(problemCollector); }
/** * Checks if the next characters, starting from the current, match the given string. * * @param string the string to check * @param consume determines if the matched string should be consumed immediately * @return <tt>true</tt> if the next characters of the input match the given string, <tt>false</tt> * otherwise */ protected boolean canConsumeThisString(String string, boolean consume) { if (string == null) { return false; } for (int i = 0; i < string.length(); i++) { if (!input.next(i).is(string.charAt(i))) { return false; } } if (consume) { input.consume(string.length()); } return true; }
@Override public void setProblemCollector(List<ParseError> problemCollector) { super.setProblemCollector(problemCollector); this.input.setProblemCollector(problemCollector); }
@SuppressWarnings("unchecked") private C parseTag() { StringBuilder tag = new StringBuilder(); tag.append(reader.consume()); tag.append(reader.consume()); while (!reader.current().isEndOfInput() && !(reader.current().is('|') && reader.next().is('|'))) { tag.append(reader.consume()); } tag.append(reader.consume()); tag.append(reader.consume()); QueryTag queryTag = QueryTag.parse(tag.toString()); if (queryTag.getType() != null && Strings.isFilled(queryTag.getValue())) { QueryTagHandler<C> handler = ctx.getPart(queryTag.getType(), QueryTagHandler.class); if (handler != null) { return handler.generateConstraint(factory, descriptor, queryTag.getValue()); } } return null; }
/** * Determines if the underlying input is looking at the start of a special id. * <p> * By default this is one of the given <tt>specialIdStarters</tt>. * * @return <tt>true</tt> if the current input is the start of a special id, <tt>false</tt> otherwise */ protected boolean isAtStartOfSpecialId() { return specialIdStarters.contains(input.current().getValue()); }
/** * Creates a new tokenizer for the given input * * @param input the input to parse. The reader will be buffered by the implementation so that it can be effectively * read character b character. */ public Tokenizer(Reader input) { this.input = new LookaheadReader(input); this.input.setProblemCollector(problemCollector); // Setup default string handling addStringDelimiter('"', '\\'); addStringDelimiter('\'', '\0'); }