/** * Determines if this token is an integer number. * * @return <tt>true</tt> if this token is an integer number, <tt>false</tt> otherwise */ public boolean isInteger() { return is(TokenType.INTEGER); }
private void parseSelectorPrefix(List<String> selector) { if (tokenizer.more() && tokenizer.current().isSymbol("[")) { StringBuilder sb = new StringBuilder(); parseFilterInSelector(sb); parseOperatorInSelector(sb); selector.add(sb.toString()); } if (tokenizer.more() && tokenizer.current().isSymbol("&")) { selector.add(tokenizer.consume().getTrigger()); } if (tokenizer.more() && tokenizer.current().isSymbol("&:")) { tokenizer.consume(); if (tokenizer.current().is(Token.TokenType.ID)) { selector.add("&"); selector.add(":" + tokenizer.consume().getContents()); } } if (tokenizer.more() && tokenizer.current().isSymbol("&::")) { tokenizer.consume(); if (tokenizer.current().is(Token.TokenType.ID)) { selector.add("&"); selector.add("::" + tokenizer.consume().getContents()); } } if (tokenizer.more() && tokenizer.current().isSymbol("::") && tokenizer.next().is(Token.TokenType.ID)) { tokenizer.consume(); selector.add("::" + tokenizer.consume().getContents()); } }
if (tokenizer.current().is(Token.TokenType.ID)) { String quantifier = tokenizer.current().getContents().intern(); if ("n" == quantifier) {
/** * Determines if this token is a string constant * * @return <tt>true</tt> if this token is a string constant, <tt>false</tt> otherwise */ public boolean isString() { return is(TokenType.STRING); }
/** * Determines if this token is an integer number. * * @return <tt>true</tt> if this token is an integer number, <tt>false</tt> otherwise */ public boolean isInteger() { return is(TokenType.INTEGER); }
/** * Determines if this token is a decimal number. * * @return <tt>true</tt> if this token is a decimal number, <tt>false</tt> otherwise */ public boolean isDecimal() { return is(TokenType.DECIMAL); }
/** * Determines if this token is a decimal number. * * @return <tt>true</tt> if this token is a decimal number, <tt>false</tt> otherwise */ public boolean isDecimal() { return is(TokenType.DECIMAL); }
/** * Determines if this token is a string constant * * @return <tt>true</tt> if this token is a string constant, <tt>false</tt> otherwise */ public boolean isString() { return is(TokenType.STRING); }
/** * Determines if this token is a special identifier. * <p> * If a list of <tt>triggers</tt> is given, this method checks that the trigger matches one of them. * * @param triggers the triggers to check for. If the list es empty, only the token type is checked. * @return <tt>true</tt> if this token is a special identifier and matches one of the given <tt>triggers</tt> * if the list is not empty. */ public boolean isSpecialIdentifier(String... triggers) { if (triggers.length == 0) { return is(TokenType.SPECIAL_ID); } for (String possibleTrigger : triggers) { if (matches(TokenType.SPECIAL_ID, possibleTrigger)) { return true; } } return false; }
/** * Determines if this token is a keyword. * <p> * If a list of <tt>symbols</tt> is given, this method checks that the trigger matches one of them. * * @param keywords the keywords to check for. If the list es empty, only the token type is checked. * @return <tt>true</tt> if this token is a keyword and matches one of the given <tt>keywords</tt> if the list * is not empty. */ public boolean isKeyword(String... keywords) { if (keywords.length == 0) { return is(TokenType.KEYWORD); } for (String keyword : keywords) { if (matches(TokenType.KEYWORD, keyword)) { return true; } } return false; }
/** * Determines if this token has the given type and trigger. * * @param type the expected type * @param trigger the expected trigger * @return <tt>true</tt> if this token matches the given type and trigger, <tt>false</tt> otherwise */ @SuppressWarnings("squid:S1698") public boolean matches(TokenType type, String trigger) { if (!is(type)) { return false; } if (trigger == null) { throw new IllegalArgumentException("trigger must not be null"); } return getTrigger() == trigger.intern(); }
/** * Determines if this token has the given type and trigger. * * @param type the expected type * @param trigger the expected trigger * @return <tt>true</tt> if this token matches the given type and trigger, <tt>false</tt> otherwise */ @SuppressWarnings("squid:S1698") public boolean matches(TokenType type, String trigger) { if (!is(type)) { return false; } if (trigger == null) { throw new IllegalArgumentException("trigger must not be null"); } return getTrigger() == trigger.intern(); }
/** * Determines if this token is a symbol. * <p> * If a list of <tt>symbols</tt> is given, this method checks that the trigger matches one of them. * * @param symbols the symbols to check for. If the list es empty, only the token type is checked. * @return <tt>true</tt> if this token is a symbol and matches one of the given <tt>symbols</tt> if the list * is not empty. */ public boolean isSymbol(String... symbols) { if (symbols.length == 0) { return is(TokenType.SYMBOL); } for (String symbol : symbols) { if (matches(TokenType.SYMBOL, symbol)) { return true; } } return false; }
/** * Determines if this token is a special identifier. * <p> * If a list of <tt>triggers</tt> is given, this method checks that the trigger matches one of them. * * @param triggers the triggers to check for. If the list es empty, only the token type is checked. * @return <tt>true</tt> if this token is a special identifier and matches one of the given <tt>triggers</tt> * if the list is not empty. */ public boolean isSpecialIdentifier(String... triggers) { if (triggers.length == 0) { return is(TokenType.SPECIAL_ID); } for (String possibleTrigger : triggers) { if (matches(TokenType.SPECIAL_ID, possibleTrigger)) { return true; } } return false; }
/** * Determines if this token is a keyword. * <p> * If a list of <tt>symbols</tt> is given, this method checks that the trigger matches one of them. * * @param keywords the keywords to check for. If the list es empty, only the token type is checked. * @return <tt>true</tt> if this token is a keyword and matches one of the given <tt>keywords</tt> if the list * is not empty. */ public boolean isKeyword(String... keywords) { if (keywords.length == 0) { return is(TokenType.KEYWORD); } for (String keyword : keywords) { if (matches(TokenType.KEYWORD, keyword)) { return true; } } return false; }
/** * Determines if this token is an identifier. * <p> * If a list of <tt>values</tt> is given, this method checks that the content matches one of them. * * @param values the values to check for. If the list es empty, only the token type is checked. * @return <tt>true</tt> if this token is an identifier and matches one of the given <tt>values</tt> if the list * is not empty. */ public boolean isIdentifier(String... values) { if (values.length == 0) { return is(TokenType.ID); } for (String value : values) { if (matches(TokenType.ID, value)) { return true; } } return false; }
/** * Determines if this token is an identifier. * <p> * If a list of <tt>values</tt> is given, this method checks that the content matches one of them. * * @param values the values to check for. If the list es empty, only the token type is checked. * @return <tt>true</tt> if this token is an identifier and matches one of the given <tt>values</tt> if the list * is not empty. */ public boolean isIdentifier(String... values) { if (values.length == 0) { return is(TokenType.ID); } for (String value : values) { if (matches(TokenType.ID, value)) { return true; } } return false; }
/** * Determines if this token is a symbol. * <p> * If a list of <tt>symbols</tt> is given, this method checks that the trigger matches one of them. * * @param symbols the symbols to check for. If the list es empty, only the token type is checked. * @return <tt>true</tt> if this token is a symbol and matches one of the given <tt>symbols</tt> if the list * is not empty. */ public boolean isSymbol(String... symbols) { if (symbols.length == 0) { return is(TokenType.SYMBOL); } for (String symbol : symbols) { if (matches(TokenType.SYMBOL, symbol)) { return true; } } return false; }
/** * Reads and returns a number. * * @return the parsed number as Token */ protected Token fetchNumber() { Token result = Token.create(Token.TokenType.INTEGER, input.current()); result.addToContent(input.consume()); while (input.current().isDigit() || input.current().is(decimalSeparator) || (input.current() .is(groupingSeparator) && input.next().isDigit())) { if (input.current().is(groupingSeparator)) { result.addToSource(input.consume()); } else if (input.current().is(decimalSeparator)) { if (result.is(Token.TokenType.DECIMAL)) { problemCollector.add(ParseError.error(input.current(), "Unexpected decimal separators")); } else { Token decimalToken = Token.create(Token.TokenType.DECIMAL, result); decimalToken.setContent(result.getContents() + effectiveDecimalSeparator); decimalToken.setSource(result.getSource()); result = decimalToken; } result.addToSource(input.consume()); } else { result.addToContent(input.consume()); } } return result; }
/** * Reads and returns a number. * * @return the parsed number as Token */ protected Token fetchNumber() { Token result = Token.create(Token.TokenType.INTEGER, input.current()); result.addToContent(input.consume()); while (input.current().isDigit() || input.current().is(decimalSeparator) || (input.current() .is(groupingSeparator) && input.next().isDigit())) { if (input.current().is(groupingSeparator)) { result.addToSource(input.consume()); } else if (input.current().is(decimalSeparator)) { if (result.is(Token.TokenType.DECIMAL)) { problemCollector.add(ParseError.error(input.current(), "Unexpected decimal separators")); } else { Token decimalToken = Token.create(Token.TokenType.DECIMAL, result); decimalToken.setContent(result.getContents() + effectiveDecimalSeparator); decimalToken.setSource(result.getSource()); result = decimalToken; } result.addToSource(input.consume()); } else { result.addToContent(input.consume()); } } return result; }