/** * Determines if the given Char is a valid identifier part. * <p> * By default, letters, digits and '_' are valid identifier parts. * * @param current the character to check * @return <tt>true</tt> if the given Char is a valid identifier part, <tt>false</tt> otherwise */ protected boolean isIdentifierChar(Char current) { return current.isDigit() || current.isLetter() || current.is('_'); }
/** * Determines if the given Char is a valid identifier part. * <p> * By default, letters, digits and '_' are valid identifier parts. * * @param current the character to check * @return <tt>true</tt> if the given Char is a valid identifier part, <tt>false</tt> otherwise */ protected boolean isIdentifierChar(Char current) { return current.isDigit() || current.isLetter() || current.is('_'); }
/** * Determines if the underlying input is looking at the start of a number. * <p> * By default this is either indicated by a digit or by '-' followed by a digit or a '.' followed by a digit. * * @return <tt>true</tt> if the current input is the start of a numeric constant, <tt>false</tt> otherwise */ @SuppressWarnings("squid:S1067") protected boolean isAtStartOfNumber() { return input.current().isDigit() || input.current().is('-') && input.next().isDigit() || input.current().is('-') && input.next().is('.') && input.next(2).isDigit() || input.current().is('.') && input.next().isDigit(); }
/** * Determines if the underlying input is looking at the start of a number. * <p> * By default this is either indicated by a digit or by '-' followed by a digit or a '.' followed by a digit. * * @return <tt>true</tt> if the current input is the start of a numeric constant, <tt>false</tt> otherwise */ @SuppressWarnings("squid:S1067") protected boolean isAtStartOfNumber() { return input.current().isDigit() || input.current().is('-') && input.next().isDigit() || input.current().is('-') && input.next().is('.') && input.next(2).isDigit() || input.current().is('.') && input.next().isDigit(); }
protected Tuple<String, String> parseFieldAndValue(LookaheadReader reader) { String field = defaultField; boolean couldBeFieldNameSoFar = true; StringBuilder valueBuilder = new StringBuilder(); while (!reader.current().isEndOfInput() && !reader.current().isWhitepace() && !reader.current().is(')')) { if (reader.current().is(':') && valueBuilder.length() > 0 && couldBeFieldNameSoFar) { field = valueBuilder.toString(); valueBuilder = new StringBuilder(); // Ignore : reader.consume(); couldBeFieldNameSoFar = false; } else { if (couldBeFieldNameSoFar) { couldBeFieldNameSoFar = reader.current().is('-', '_') || reader.current().isLetter() || reader.current().isDigit(); } valueBuilder.append(reader.consume().getValue()); } } return Tuple.create(field, valueBuilder.toString()); }
/** * Determines if the given Char is a symbol character. * <p> * By default these are all non-control characters, which don't match any other class (letter, digit, whitepsace) * * @param ch the character to check * @return <tt>true</tt> if the given character is a valid symbol character, <tt>false</tt> otherwise */ @SuppressWarnings("squid:S1067") protected boolean isSymbolCharacter(Char ch) { if (ch.isEndOfInput() || ch.isDigit() || ch.isLetter() || ch.isWhitepace()) { return false; } char c = ch.getValue(); if (Character.isISOControl(c)) { return false; } return !(isAtBracket(true) || isAtStartOfBlockComment(false) || isAtStartOfLineComment(false) || isAtStartOfNumber() || isAtStartOfIdentifier() || stringDelimiters.containsKey(ch.getValue())); }
/** * Determines if the given Char is a symbol character. * <p> * By default these are all non-control characters, which don't match any other class (letter, digit, whitepsace) * * @param ch the character to check * @return <tt>true</tt> if the given character is a valid symbol character, <tt>false</tt> otherwise */ @SuppressWarnings("squid:S1067") protected boolean isSymbolCharacter(Char ch) { if (ch.isEndOfInput() || ch.isDigit() || ch.isLetter() || ch.isWhitepace()) { return false; } char c = ch.getValue(); if (Character.isISOControl(c)) { return false; } return !(isAtBracket(true) || isAtStartOfBlockComment(false) || isAtStartOfLineComment(false) || isAtStartOfNumber() || isAtStartOfIdentifier() || stringDelimiters.containsKey(ch.getValue())); }
/** * 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; }