@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e) { throw new ParsingException(message, e, line, charPositionInLine); } };
@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e) { throw new ParsingException(message, e, line, charPositionInLine); } };
@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e) { throw new ParsingException(message, e, line, charPositionInLine); } };
@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e) { throw new ParsingException(message, e, line, charPositionInLine); } };
private LongLiteral(Optional<NodeLocation> location, String value) { super(location); requireNonNull(value, "value is null"); try { this.value = Long.parseLong(value); } catch (NumberFormatException e) { throw new ParsingException("Invalid numeric literal: " + value); } }
private LongLiteral(Optional<NodeLocation> location, String value) { super(location); requireNonNull(value, "value is null"); try { this.value = Long.parseLong(value); } catch (NumberFormatException e) { throw new ParsingException("Invalid numeric literal: " + value); } }
private GenericLiteral(Optional<NodeLocation> location, String type, String value) { super(location); requireNonNull(type, "type is null"); requireNonNull(value, "value is null"); if (type.equalsIgnoreCase("X")) { // we explicitly disallow "X" as type name, so if the user arrived here, // it must be because that he intended to give a binaryLiteral instead, but // added whitespace between the X and quote throw new ParsingException("Spaces are not allowed between 'X' and the starting quote of a binary literal", location.get()); } this.type = type; this.value = value; }
private GenericLiteral(Optional<NodeLocation> location, String type, String value) { super(location); requireNonNull(type, "type is null"); requireNonNull(value, "value is null"); if (type.equalsIgnoreCase("X")) { // we explicitly disallow "X" as type name, so if the user arrived here, // it must be because that he intended to give a binaryLiteral instead, but // added whitespace between the X and quote throw new ParsingException("Spaces are not allowed between 'X' and the starting quote of a binary literal", location.get()); } this.type = type; this.value = value; }
public BinaryLiteral(Optional<NodeLocation> location, String value) { super(location); requireNonNull(value, "value is null"); String hexString = WHITESPACE_PATTERN.matcher(value).replaceAll("").toUpperCase(); if (NOT_HEX_DIGIT_PATTERN.matcher(hexString).matches()) { throw new ParsingException("Binary literal can only contain hexadecimal digits", location.get()); } if (hexString.length() % 2 != 0) { throw new ParsingException("Binary literal must contain an even number of digits", location.get()); } this.value = Slices.wrappedBuffer(BaseEncoding.base16().decode(hexString)); }
@Override public void exitBackQuotedIdentifier(SqlBaseParser.BackQuotedIdentifierContext context) { Token token = context.BACKQUOTED_IDENTIFIER().getSymbol(); throw new ParsingException( "backquoted identifiers are not supported; use double quotes to quote identifiers", null, token.getLine(), token.getCharPositionInLine()); }
@Override public void exitDigitIdentifier(SqlBaseParser.DigitIdentifierContext context) { Token token = context.DIGIT_IDENTIFIER().getSymbol(); throw new ParsingException( "identifiers must not start with a digit; surround the identifier with double quotes", null, token.getLine(), token.getCharPositionInLine()); }
private static ParsingException parseError(String message, ParserRuleContext context) { return new ParsingException(message, null, context.getStart().getLine(), context.getStart().getCharPositionInLine()); } }
@Override public void exitBackQuotedIdentifier(SqlBaseParser.BackQuotedIdentifierContext context) { Token token = context.BACKQUOTED_IDENTIFIER().getSymbol(); throw new ParsingException( "backquoted identifiers are not supported; use double quotes to quote identifiers", null, token.getLine(), token.getCharPositionInLine()); }
@Override public void exitDigitIdentifier(SqlBaseParser.DigitIdentifierContext context) { Token token = context.DIGIT_IDENTIFIER().getSymbol(); throw new ParsingException( "identifiers must not start with a digit; surround the identifier with double quotes", null, token.getLine(), token.getCharPositionInLine()); }
private static ParsingException parseError(String message, ParserRuleContext context) { return new ParsingException(message, null, context.getStart().getLine(), context.getStart().getCharPositionInLine()); } }
public static Long calculateLiteralValue( String calculation, Map<String, Long> inputs) { try { ParserRuleContext tree = parseTypeCalculation(calculation); CalculateTypeVisitor visitor = new CalculateTypeVisitor(inputs); BigInteger result = visitor.visit(tree); return result.longValueExact(); } catch (StackOverflowError e) { throw new ParsingException("Type calculation is too large (stack overflow while parsing)"); } }
public static Long calculateLiteralValue( String calculation, Map<String, Long> inputs) { try { ParserRuleContext tree = parseTypeCalculation(calculation); CalculateTypeVisitor visitor = new CalculateTypeVisitor(inputs); BigInteger result = visitor.visit(tree); return result.longValueExact(); } catch (StackOverflowError e) { throw new ParsingException("Type calculation is too large (stack overflow while parsing)"); } }
@Override public Node visitDecimalLiteral(SqlBaseParser.DecimalLiteralContext context) { switch (parsingOptions.getDecimalLiteralTreatment()) { case AS_DOUBLE: return new DoubleLiteral(getLocation(context), context.getText()); case AS_DECIMAL: return new DecimalLiteral(getLocation(context), context.getText()); case REJECT: throw new ParsingException("Unexpected decimal literal: " + context.getText()); } throw new AssertionError("Unreachable"); }
@Override public void exitUnquotedIdentifier(SqlBaseParser.UnquotedIdentifierContext context) { String identifier = context.IDENTIFIER().getText(); for (IdentifierSymbol identifierSymbol : EnumSet.complementOf(allowedIdentifierSymbols)) { char symbol = identifierSymbol.getSymbol(); if (identifier.indexOf(symbol) >= 0) { throw new ParsingException("identifiers must not contain '" + identifierSymbol.getSymbol() + "'", null, context.IDENTIFIER().getSymbol().getLine(), context.IDENTIFIER().getSymbol().getCharPositionInLine()); } } }
@Override public void exitUnquotedIdentifier(SqlBaseParser.UnquotedIdentifierContext context) { String identifier = context.IDENTIFIER().getText(); for (IdentifierSymbol identifierSymbol : EnumSet.complementOf(allowedIdentifierSymbols)) { char symbol = identifierSymbol.getSymbol(); if (identifier.indexOf(symbol) >= 0) { throw new ParsingException("identifiers must not contain '" + identifierSymbol.getSymbol() + "'", null, context.IDENTIFIER().getSymbol().getLine(), context.IDENTIFIER().getSymbol().getCharPositionInLine()); } } }