public int getColumn() { if (column == null) { return super.getCharPositionInLine(); } else { return column; } }
public void setTtlDays(CommonTree treeElement) { String ttlString = treeElement.getText(); if (ttlString == null) { throw new IllegalArgumentException(String.format("Cannot set ttl to null at %s:%s", treeElement.getLine(), treeElement.getCharPositionInLine())); } else { try { this.ttlMillis = Long.parseLong(ttlString) * 3600 * 24 * 1000; } catch (NumberFormatException e) { throw new IllegalArgumentException( String.format("Error parsing TTL at %s:%s", treeElement.getLine(), treeElement.getCharPositionInLine()), e); } } }
public ScribbleException(CommonTree blame, String arg0) { // char position indexes are obscure because only certain (child) nodes/tokens are actually recorded, e.g., name nodes (the keyword nodes, e.g., global, have been discarded) // ...although even taking the above into account, indexes still seem off? -- may be due to tabs (counted as single chars) super(getRootModuleName(blame) + "(line " + blame.getLine() + ":" + (blame.getCharPositionInLine()) + "): " + arg0); // Cf., getTokenStartIndex/getTokenStopIndex ? blame.token.getCharPositionInLine()? }
public AntlrSourceException(CommonTree blame, String arg0) { // char position indexes are obscure because only certain (child) nodes/tokens are actually recorded, e.g., name nodes (the keyword nodes, e.g., global, have been discarded) // ...although even taking the above into account, indexes still seem off? -- may be due to tabs (counted as single chars) super(getRootModuleName(blame) + "(line " + blame.getLine() + ":" + (blame.getCharPositionInLine()) + "): " + arg0); // Cf., getTokenStartIndex/getTokenStopIndex ? blame.token.getCharPositionInLine()? }
private char convertNonTypeable(CommonTree node) throws SyntaxError { switch (node.getText().charAt(1)) { case 'r' : return '\r'; // the carriage-return character case 'n' : return '\n'; // the newline (line feed) character case 't' : return '\t'; // the tab character case 'f' : return '\f'; // the form-feed character case 'a' : return '\u0007'; // the alert (bell) character case 'e' : return '\u001B'; // the escape character default: throw new SyntaxError("invalid non-typeable char", node.getText(), node.getCharPositionInLine(), node.getLine()); } }
private static void convertTableDetail(CommonTree node, DBTable table, DatabaseDialect dialect) { switch (node.getType()) { case SQLLexer.COLUMN_SPEC: convertColumnSpec(node, table); break; case SQLLexer.PRIMARY: convertInlinePK(node, table, dialect); break; default: throw new ParseException("Unknown table detail token type", String.valueOf(node.getText()), node.getLine(), node.getCharPositionInLine()); } }
private static void convertColumnDetail(CommonTree node, DBColumn column) { switch (node.getType()) { case SQLLexer.NOT : column.setNullable(false); break; case SQLLexer.DEFAULT : column.setNullable(false); break; default: throw new ParseException("Unknown column detail token type", String.valueOf(node.getText()), node.getLine(), node.getCharPositionInLine()); } }
private static Quantifier convertQuantifier(CommonTree node) throws SyntaxError { switch (node.getType()) { case RegexLexer.SIMPLEQUANTIFIER : return convertSimpleQuantifier(node); case RegexLexer.QUANT : return convertExplicitQuantifier(node); default: throw new SyntaxError("Error parsing quantifier", node.getText(), node.getCharPositionInLine(), node.getLine()); } }
private Quantifier convertQuantifier(CommonTree node) throws SyntaxError { switch (node.getType()) { case RegexLexer.SIMPLEQUANTIFIER : return convertSimpleQuantifier(node); case RegexLexer.QUANT : return convertExplicitQuantifier(node); default: throw new SyntaxError("Error parsing quantifier", node.getText(), node.getCharPositionInLine(), node.getLine()); } }
private static Quantifier convertSimpleQuantifier(CommonTree node) throws SyntaxError { Assert.equals(RegexLexer.SIMPLEQUANTIFIER, node.getType(), "node is not an simple quantifier"); char letter = node.getText().charAt(0); switch (letter) { case '?' : return new Quantifier(0, 1); case '*' : return new Quantifier(0, null); case '+' : return new Quantifier(1, null); default: throw new SyntaxError("Error parsing simple quantifier", node.getText(), node.getCharPositionInLine(), node.getLine()); } }
private Quantifier convertSimpleQuantifier(CommonTree node) throws SyntaxError { Assert.equals(RegexLexer.SIMPLEQUANTIFIER, node.getType(), "node is not an simple quantifier"); char letter = node.getText().charAt(0); switch (letter) { case '?' : return new Quantifier(0, 1); case '*' : return new Quantifier(0, null); case '+' : return new Quantifier(1, null); default: throw new SyntaxError("Error parsing simple quantifier", node.getText(), node.getCharPositionInLine(), node.getLine()); } }
private static RegexChar convertNonTypeable(CommonTree node) throws SyntaxError { switch (node.getText().charAt(1)) { case 'r' : return new RegexChar('\r'); // the carriage-return character case 'n' : return new RegexChar('\n'); // the newline (line feed) character case 't' : return new RegexChar('\t'); // the tab character case 'f' : return new RegexChar('\f'); // the form-feed character case 'a' : return new RegexChar('\u0007'); // the alert (bell) character case 'e' : return new RegexChar('\u001B'); // the escape character default: throw new SyntaxError("invalid non-typeable char", node.getText(), node.getCharPositionInLine(), node.getLine()); } }
private Node createNodeFor(CommonTree ast) { if (ast == null) return null; final Node node = createNodeObjectFor(ast); if (node != null) { node.setText(ast.getText()); node.setLine(ast.getLine()); node.setColumn(ast.getCharPositionInLine()); if (ast.getChildCount() > 0) { for (Object child : ast.getChildren()) { node.getChildren().add(createNodeFor((CommonTree)child)); } } } return node; }
private RegexCharClass convertPredefClass(CommonTree node) throws SyntaxError { String text = node.getText(); if (".".equals(text)) return new SimpleCharSet(".", CharSet.getAnyCharacters()); char charClass = text.charAt(1); switch (charClass) { case 'd' : return new SimpleCharSet("\\d", CharSet.getDigits()); case 'D' : return new SimpleCharSet("\\D", CharSet.getNonDigits()); case 's' : return new SimpleCharSet("\\s", CharSet.getWhitespaces()); case 'S' : return new SimpleCharSet("\\S", CharSet.getNonWhitespaces()); case 'w' : return new SimpleCharSet("\\w", CharSet.getWordChars(locale)); case 'W' : return new SimpleCharSet("\\W", CharSet.getNonWordChars()); default: throw new SyntaxError("Unsupported character class", text, node.getCharPositionInLine(), node.getLine()); } }
private CharSet convertPredefClass(CommonTree node) throws SyntaxError { String text = node.getText(); if (".".equals(text)) return new CharSet(".", CharSet.getAnyCharacters()); char charClass = text.charAt(1); switch (charClass) { case 'd' : return new CharSet("\\d", CharSet.getDigits()); case 'D' : return new CharSet("\\D", CharSet.getNonDigits()); case 's' : return new CharSet("\\s", CharSet.getWhitespaces()); case 'S' : return new CharSet("\\S", CharSet.getNonWhitespaces()); case 'w' : return new CharSet("\\w", CharSet.getWordChars(locale)); case 'W' : return new CharSet("\\W", CharSet.getNonWordChars()); default: throw new SyntaxError("Unsupported character class", text, node.getCharPositionInLine(), node.getLine()); } }
private static Expression<?>[] convertBeanSpecList(CommonTree node) throws SyntaxError { if (node.getType() == DatabeneScriptLexer.BEANSPEC) return new Expression<?>[] { convertBeanSpec(node) }; else if (node.isNil()) { int childCount = node.getChildCount(); Expression<?>[] specs = new Expression<?>[childCount]; for (int i = 0; i < childCount; i++) specs[i] = convertBeanSpec(childAt(i, node)); return specs; } else throw new SyntaxError("Unexpected token", node.getToken().getText(), node.getLine(), node.getCharPositionInLine()); }
private static BeanSpec[] resolveBeanSpecList(CommonTree node, Context context) throws SyntaxError { if (node.getType() == DatabeneScriptLexer.BEANSPEC) return new BeanSpec[] { resolveBeanSpec(node, context) }; else if (node.isNil()) { int childCount = node.getChildCount(); BeanSpec[] specs = new BeanSpec[childCount]; for (int i = 0; i < childCount; i++) specs[i] = resolveBeanSpec(childAt(i, node), context); return specs; } else throw new SyntaxError("Unexpected token", node.getToken().getText(), node.getLine(), node.getCharPositionInLine()); }
private static WeightedTransition[] convertTransitionList(CommonTree node) throws SyntaxError { if (node.getType() == DatabeneScriptLexer.ARROW) return new WeightedTransition[] { convertTransition(node) }; else if (node.isNil()) { int childCount = node.getChildCount(); WeightedTransition[] transitions = new WeightedTransition[childCount]; for (int i = 0; i < childCount; i++) transitions[i] = convertTransition(childAt(i, node)); return transitions; } else throw new SyntaxError("Unexpected token in transition list: ", node.getToken().getText(), node.getLine(), node.getCharPositionInLine()); }
private RegexPart convertRegexPart(CommonTree node) throws SyntaxError { if (node == null) return null; if (node.getToken() == null) return new RegexString(""); switch (node.getType()) { case RegexLexer.CHOICE: return convertChoice(node); case RegexLexer.GROUP: return convertGroup(node); case RegexLexer.SEQUENCE: return convertSequence(node); case RegexLexer.FACTOR: return convertFactor(node); case RegexLexer.PREDEFINEDCLASS: return convertPredefClass(node); case RegexLexer.CLASS: return convertClass(node); case RegexLexer.RANGE: return convertRange(node); case RegexLexer.SPECIALCHARACTER: return convertAlphanum(node); case RegexLexer.ESCAPEDCHARACTER: return convertEscaped(node); case RegexLexer.NONTYPEABLECHARACTER: return convertNonTypeable(node); case RegexLexer.OCTALCHAR: return convertOctal(node); case RegexLexer.HEXCHAR: return convertHexChar(node); case RegexLexer.CODEDCHAR: return convertCodedChar(node); case RegexLexer.ALPHANUM: return convertAlphanum(node); default: throw new SyntaxError("Not a supported token type: " + node.getToken(), node.toString(), node.getCharPositionInLine(), node.getLine()); } }
private Object convertNode(CommonTree node) throws SyntaxError { if (node == null) return null; if (node.getToken() == null) return ""; switch (node.getType()) { case RegexLexer.CHOICE: return convertChoice(node); case RegexLexer.GROUP: return convertGroup(node); case RegexLexer.SEQUENCE: return convertSequence(node); case RegexLexer.FACTOR: return convertFactor(node); case RegexLexer.SIMPLEQUANTIFIER: return convertSimpleQuantifier(node); case RegexLexer.CLASS: return convertClass(node); case RegexLexer.RANGE: return convertRange(node); case RegexLexer.ALPHANUM: return convertAlphanum(node); case RegexLexer.SPECIALCHARACTER: return convertAlphanum(node); case RegexLexer.ESCAPEDCHARACTER: return convertEscaped(node); case RegexLexer.NONTYPEABLECHARACTER: return convertNonTypeable(node); case RegexLexer.OCTALCHAR: return convertOctal(node); case RegexLexer.HEXCHAR: return convertHexChar(node); case RegexLexer.CODEDCHAR: return convertCodedChar(node); case RegexLexer.PREDEFINEDCLASS: return convertPredefClass(node); default: throw new SyntaxError("Unknown token type: " + node.getToken(), node.toString(), node.getCharPositionInLine(), node.getLine()); } }