Package org.antlr.runtime.tree

Examples of org.antlr.runtime.tree.CommonTree


    private final ISqlJetForeignKey foreignKey;

    public SqlJetTableForeignKey(String name, CommonTree ast) {
        super(name);
        assert "foreign".equalsIgnoreCase(ast.getText());
        CommonTree columnsNode = (CommonTree) ast.getChild(1);
        assert "columns".equalsIgnoreCase(columnsNode.getText()) || "references".equalsIgnoreCase(columnsNode.getText());
        List<String> columnNames = new ArrayList<String>();
        for (int i = 0; i < columnsNode.getChildCount(); i++) {
            columnNames.add(columnsNode.getChild(i).getText());
        }
        this.columnNames = Collections.unmodifiableList(columnNames);
        foreignKey = new SqlJetForeignKey((CommonTree) ast.getChild(1));
    }
View Full Code Here


            arguments = Collections.emptyList();
        } else {
            all = false;
            List<ISqlJetExpression> arguments = new ArrayList<ISqlJetExpression>();
            int i = 1;
            CommonTree child = (CommonTree) ast.getChild(i);
            if (child != null && "distinct".equalsIgnoreCase(child.getText())) {
                distinct = true;
                i++;
            } else {
                distinct = false;
            }
            for (;i<ast.getChildCount();i++) {
                child = (CommonTree) ast.getChild(i);
                if (!"distinct".equalsIgnoreCase(child.getText())) {
                    ISqlJetExpression argument = create(child);
                    arguments.add(argument);
                }
            }
            this.arguments = Collections.unmodifiableList(arguments);
View Full Code Here

    public SqlJetColumnPrimaryKey(SqlJetColumnDef column, String name, CommonTree ast) {
        super(column, name);
        assert "primary".equalsIgnoreCase(ast.getText());
        for (int i = 0; i < ast.getChildCount(); i++) {
            CommonTree child = (CommonTree) ast.getChild(i);
            if ("asc".equalsIgnoreCase(child.getText())) {
                ascending = Boolean.TRUE;
            } else if ("desc".equalsIgnoreCase(child.getText())) {
                ascending = Boolean.FALSE;
            } else if ("autoincrement".equalsIgnoreCase(child.getText())) {
                autoincremented = true;
            } else if ("conflict".equalsIgnoreCase(child.getText())) {
                assert child.getChildCount() == 1;
                child = (CommonTree) child.getChild(0);
                conflictAction = SqlJetConflictAction.decode(child.getText());
            } else {
                assert false;
            }
        }
    }
View Full Code Here

     * @param ast
     * @throws SqlJetException
     */
    public SqlJetAlterTableDef(ParserRuleReturnScope parsedSql) throws SqlJetException {
        this.parsedSql = parsedSql;
        final CommonTree ast = (CommonTree)parsedSql.getTree();
        final int childCount = ast.getChildCount();
        if (childCount < 5) {
            throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
        }
        final CommonTree alterNode = (CommonTree) ast.getChild(0);
        final CommonTree tableNode = (CommonTree) ast.getChild(1);
        if (!"alter".equalsIgnoreCase(alterNode.getText()) || !"table".equalsIgnoreCase(tableNode.getText())) {
            throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
        }
        final CommonTree tableNameNode = (CommonTree) ast.getChild(2);
        tableName = tableNameNode.getText();
        final CommonTree actionNode = (CommonTree) ast.getChild(3);
        final String action = actionNode.getText();
        final CommonTree child = (CommonTree) ast.getChild(4);
        if ("add".equalsIgnoreCase(action)) {
            newTableName = null;
            final CommonTree newColumnNode;
            if ("column".equalsIgnoreCase(child.getText())) {
                if (childCount != 6) {
                    throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
                }
                newColumnNode = (CommonTree) ast.getChild(5);
            } else {
                if (childCount != 5) {
                    throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
                }
                newColumnNode = child;
            }
            newColumnDef = new SqlJetColumnDef(newColumnNode);
        } else if ("rename".equalsIgnoreCase(action)) {
            newColumnDef = null;
            assert ("to".equalsIgnoreCase(child.getText()));
            if (childCount < 6) {
                throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
            }
            final CommonTree newTableNode = (CommonTree) ast.getChild(5);
            newTableName = newTableNode.getText();
        } else {
            newTableName = null;
            newColumnDef = null;
            throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
        }
View Full Code Here

        assert operation != null;
        matchExpression = create((CommonTree) ast.getChild(0));
        boolean not = false;
        ISqlJetExpression expression = null, escapeExpression = null;
        for (int i = 1; i < ast.getChildCount(); i++) {
            CommonTree child = (CommonTree) ast.getChild(1);
            if ("not".equalsIgnoreCase(child.getText())) {
                not = true;
            } else if ("escape".equalsIgnoreCase(child.getText())) {
                escapeExpression = create((CommonTree) child.getChild(0));
            } else {
                escapeExpression = create(child);
            }
        }
        assert expression != null;
View Full Code Here

            final int page = table.getPageField();

            if (TABLE_TYPE.equals(type)) {
                String sql = table.getSqlField();
                // System.err.println(sql);
                final CommonTree ast = (CommonTree) parseTable(sql).getTree();
                if (!isCreateVirtualTable(ast)) {
                    final SqlJetTableDef tableDef = new SqlJetTableDef(ast, page);
                    if (!name.equals(tableDef.getName())) {
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    }
                    tableDef.setRowId(table.getRowId());
                    tableDefs.put(name, tableDef);
                } else {
                    final SqlJetVirtualTableDef virtualTableDef = new SqlJetVirtualTableDef(ast, page);
                    if (!name.equals(virtualTableDef.getTableName())) {
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    }
                    virtualTableDef.setRowId(table.getRowId());
                    virtualTableDefs.put(name, virtualTableDef);
                }
            } else if (INDEX_TYPE.equals(type)) {
                final String tableName = table.getTableField();
                final String sql = table.getSqlField();
                if (null != sql) {
                    // System.err.println(sql);
                    final CommonTree ast = (CommonTree) parseIndex(sql).getTree();
                    final SqlJetIndexDef indexDef = new SqlJetIndexDef(ast, page);
                    if (!name.equals(indexDef.getName())) {
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    }
                    if (!tableName.equals(indexDef.getTableName())) {
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    }
                    indexDef.setRowId(table.getRowId());
                    indexDefs.put(name, indexDef);
                } else {
                    SqlJetBaseIndexDef indexDef = new SqlJetBaseIndexDef(name, tableName, page);
                    indexDef.setRowId(table.getRowId());
                    indexDefs.put(name, indexDef);
                }
            } else if (VIEW_TYPE.equals(type)) {
                final String viewName = table.getTableField();
                final String sql = table.getSqlField();
                final CommonTree ast = (CommonTree) parseView(sql).getTree();
                final SqlJetViewDef viewDef = new SqlJetViewDef(sql, ast);
                viewDef.setRowId(table.getRowId());
                viewDefs.put(viewName, viewDef);
            } else if (TRIGGER_TYPE.equals(type)) {
                final String triggerName = table.getNameField();
                final String sql = table.getSqlField();
               
                final CommonTree ast = (CommonTree) parseTrigger(sql).getTree();
                final SqlJetTriggerDef triggerDef = new SqlJetTriggerDef(sql, ast);
                triggerDef.setRowId(table.getRowId());
                triggerDefs.put(triggerName, triggerDef);
            }
        }
View Full Code Here

    /**
     * @param ast
     * @return
     */
    private boolean isCreateVirtualTable(CommonTree ast) {
        final CommonTree optionsNode = (CommonTree) ast.getChild(0);
        for (int i = 0; i < optionsNode.getChildCount(); i++) {
            CommonTree optionNode = (CommonTree) optionsNode.getChild(i);
            if ("virtual".equalsIgnoreCase(optionNode.getText())) {
                return true;
            }
        }
        return false;
    }
View Full Code Here

    }

    private ISqlJetTableDef createTableSafe(String sql, boolean internal) throws SqlJetException {

        final RuleReturnScope parseTable = parseTable(sql);
        final CommonTree ast = (CommonTree) parseTable.getTree();

        if (isCreateVirtualTable(ast)) {
            throw new SqlJetException(SqlJetErrorCode.ERROR);
        }
View Full Code Here

    private String getCreateVirtualTableSql(RuleReturnScope parseTable) {
        return String.format("CREATE VIRTUAL TABLE %s", getCoreSQL(parseTable));
    }

    private String getCoreSQL(RuleReturnScope parsedSQL) {
        final CommonTree ast = (CommonTree) parsedSQL.getTree();
        final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(1)).getToken();
        final CharStream inputStream = nameToken.getInputStream();
        final CommonToken stopToken = (CommonToken) parsedSQL.getStop();
        return inputStream.substring(nameToken.getStartIndex(), stopToken.getStopIndex());
    }
View Full Code Here

    }

    private ISqlJetIndexDef createIndexSafe(String sql) throws SqlJetException {

        final ParserRuleReturnScope parseIndex = parseIndex(sql);
        final CommonTree ast = (CommonTree) parseIndex.getTree();

        final SqlJetIndexDef indexDef = new SqlJetIndexDef(ast, 0);

        if (null == indexDef.getName())
            throw new SqlJetException(SqlJetErrorCode.ERROR);
View Full Code Here

TOP

Related Classes of org.antlr.runtime.tree.CommonTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.