private static StringBuilder addTree(StringBuilder sb, CommonTree tree, int nest) { sb.append("\n"); for (int i = 0; i < nest; i++) { sb.append(" "); } if (!tree.isNil()) sb.append("("); sb.append(tree.toString()).append(" |").append(tree.getType()).append( "| "); return sb; } }
private static StringBuilder addTree(StringBuilder sb, CommonTree tree, int nest) { sb.append("\n"); for (int i = 0; i < nest; i++) { sb.append(" "); } if (!tree.isNil()) sb.append("("); sb.append(tree.toString()).append(" |").append(tree.getType()).append( "| "); return sb; } }
@Override public String toString() { if ( isNil() ) { return "nil"; } if ( getType()==Token.INVALID_TOKEN_TYPE ) { return "<errornode>"; } if ( token==null ) { return null; } return token.getText(); } }
public String toString() { if ( isNil() ) { return "nil"; } if ( getType()==Token.INVALID_TOKEN_TYPE ) { return "<errornode>"; } if ( token==null ) { return null; } return token.getText(); } }
@Override public String toString() { if ( isNil() ) { return "nil"; } if ( getType()==Token.INVALID_TOKEN_TYPE ) { return "<errornode>"; } if ( token==null ) { return null; } return token.getText(); } }
@Override public String toString() { if ( isNil() ) { return "nil"; } if ( getType()==Token.INVALID_TOKEN_TYPE ) { return "<errornode>"; } if ( token==null ) { return null; } return token.getText(); } }
@Override public String toString() { if ( isNil() ) { return "nil"; } if ( getType()==Token.INVALID_TOKEN_TYPE ) { return "<errornode>"; } if ( token==null ) { return null; } return token.getText(); } }
@Override public String toString() { if ( isNil() ) { return "nil"; } if ( getType()==Token.INVALID_TOKEN_TYPE ) { return "<errornode>"; } if ( token==null ) { return null; } return token.getText(); } }
private static void nest(CommonTree tree, StringBuilder sb, int nest) { assert tree != null; if (tree.getChildCount() == 0) { addTree(sb, tree, nest); return; } if (!tree.isNil()) { addTree(sb, tree, nest); } for (int i = 0; i < tree.getChildCount(); i++) { CommonTree n = (CommonTree) tree.getChild(i); nest(n, sb, nest + 1); } if (!tree.isNil()) { sb.append(")"); } }
private static void nest(CommonTree tree, StringBuilder sb, int nest) { assert tree != null; if (tree.getChildCount() == 0) { addTree(sb, tree, nest); return; } if (!tree.isNil()) { addTree(sb, tree, nest); } for (int i = 0; i < tree.getChildCount(); i++) { CommonTree n = (CommonTree) tree.getChild(i); nest(n, sb, nest + 1); } if (!tree.isNil()) { sb.append(")"); } }
private static void dump_tree(CommonTree tree, TokenStream s, int depth) { int i; int n; CommonTree t; for (i = 0; i < depth; i++) { System.out.print(" "); } if ((tree != null) && (!tree.isNil())) { Location loc = get_tree_position(s, tree); if (loc != null) { ParsePosition start_position = loc.start_position; ParsePosition stop_position = loc.end_position; // System.out.println(tree.toString() + " [" // + start_position.getLine() + "," + start_position.getCol() // + "] -> [" + stop_position.getLine() + "," // + stop_position.getCol() + "]"); } else { // System.out.println(tree.toString()); } } else { // System.out.println("<no text>\n"); } if ((tree != null) && (!tree.isNil()) && (tree.getChildCount() != 0)) { n = tree.getChildCount(); for (i = 0; i < n; i++) { t = (CommonTree) tree.getChild(i); dump_tree(t, s, depth + 1); } } }
private static WeightedSample<?>[] convertWeightedLiteralList(CommonTree node) throws SyntaxError { if (!node.isNil()) return new WeightedSample[] { convertWeightedLiteral(node) }; else { int childCount = node.getChildCount(); WeightedSample<?>[] transitions = new WeightedSample[childCount]; for (int i = 0; i < childCount; i++) transitions[i] = convertWeightedLiteral(childAt(i, node)); return transitions; } }
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 static Object convertNode(CommonTree node, DatabaseDialect dialect) { switch (node.getType()) { case SQLLexer.CREATE_TABLE: return convertCreateTable(node, dialect); case SQLLexer.DROP_TABLE: return convertDropTable(node); case SQLLexer.ALTER_TABLE: return convertAlterTable(node); case SQLLexer.CREATE_SEQUENCE: return convertCreateSequence(node); case SQLLexer.DROP_SEQUENCE: return convertDropSequence(node); case SQLLexer.CREATE_INDEX: return convertCreateIndex(node); case SQLLexer.COMMENT_TABLE: return convertTableComment(node); case SQLLexer.COMMENT_COLUMN: return convertColumnComment(node); } if (node.isNil()) { List<Object> nodes = convertNodes(getChildNodes(node), dialect); return nodes.toArray(); } throw new ParseException("Unknown token type", "'" + node.getText() + "'"); }