Package org.antlr.runtime.tree

Examples of org.antlr.runtime.tree.CommonTree


        this.page = page;
        this.rowId = rowid;
    }

    public SqlJetTableDef(CommonTree ast, int page) throws SqlJetException {
        CommonTree optionsNode = (CommonTree) ast.getChild(0);
        temporary = hasOption(optionsNode, "temporary");
        ifNotExists = hasOption(optionsNode, "exists");

        CommonTree nameNode = (CommonTree) ast.getChild(1);
        name = nameNode.getText();
        databaseName = nameNode.getChildCount() > 0 ? nameNode.getChild(0).getText() : null;

        List<ISqlJetColumnDef> columns = new ArrayList<ISqlJetColumnDef>();
        List<ISqlJetTableConstraint> constraints = new ArrayList<ISqlJetTableConstraint>();
        if (ast.getChildCount() > 2) {
            CommonTree defNode = (CommonTree) ast.getChild(2);
            if ("columns".equalsIgnoreCase(defNode.getText())) {
                for (int i = 0; i < defNode.getChildCount(); i++) {
                    columns.add(new SqlJetColumnDef((CommonTree) defNode.getChild(i)));
                }
                if (ast.getChildCount() > 3) {
                    CommonTree constraintsNode = (CommonTree) ast.getChild(3);
                    assert "constraints".equalsIgnoreCase(constraintsNode.getText());
                    for (int i = 0; i < constraintsNode.getChildCount(); i++) {
                        CommonTree constraintRootNode = (CommonTree) constraintsNode.getChild(i);
                        assert "table_constraint".equalsIgnoreCase(constraintRootNode.getText());
                        CommonTree constraintNode = (CommonTree) constraintRootNode.getChild(0);
                        String constraintType = constraintNode.getText();
                        String constraintName = constraintRootNode.getChildCount() > 1 ? constraintRootNode.getChild(1)
                                .getText() : null;
                        if ("primary".equalsIgnoreCase(constraintType)) {
                            constraints.add(new SqlJetTablePrimaryKey(constraintName, constraintNode));
                        } else if ("unique".equalsIgnoreCase(constraintType)) {
View Full Code Here


        return String.format(AUTOINDEX, tableName, i);
    }

    static boolean hasOption(CommonTree optionsNode, String name) {
        for (int i = 0; i < optionsNode.getChildCount(); i++) {
            CommonTree optionNode = (CommonTree) optionsNode.getChild(i);
            if (name.equalsIgnoreCase(optionNode.getText())) {
                return true;
            }
        }
        return false;
    }
View Full Code Here

    }

    private void handleSelect() throws SqlJetException {
        // SELECT starts with a tree of SELECT_CORE statements
        // For now we support only single SELECT_CORE
        CommonTree selectCore = (CommonTree) ast.getChild(0);
        if (!"select_core".equalsIgnoreCase(selectCore.getText())) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Compound select is not supported yet.");
        }
        int i = 0;
        CommonTree child = (CommonTree) selectCore.getChild(i++);
        // SELECT_CORE may start with DISTINCT
        boolean distinct = false;
        if ("distinct".equalsIgnoreCase(child.getText())) {
            distinct = true;
            child = (CommonTree) selectCore.getChild(i++);
        }
        if (distinct) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Distinct select modifier is not supported yet.");
        }
        // All columns are grouped by RESULT_COLUMNS
        // For now we support only *
        assert "columns".equalsIgnoreCase(child.getText());
        if (child.getChildCount() != 1 && !"*".equals(child.getChild(0).getText())) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Can select only * for now.");
        }
        child = (CommonTree) selectCore.getChild(i++);
        // We require FROM to refer to a single table
        if (!"from".equalsIgnoreCase(child.getText())) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Select source should be specified.");
        }
        child = (CommonTree) child.getChild(0);
        if (!"alias".equalsIgnoreCase(child.getText())) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Compound select source is not supported yet.");
        }
        child = (CommonTree) child.getChild(0);
        if ("select".equalsIgnoreCase(child.getText())) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Select as select source is not supported yet.");
        }
        String tableName = child.getText();
        if (selectCore.getChildCount() > i) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Unsupported select syntax.");
        }
        table = db.getTable(tableName);
        if (table != null) {
View Full Code Here

            cursor = table.open();
        }
    }

    private void handleDropTable() throws SqlJetException {
        CommonTree options = (CommonTree) ast.getChild(0);
        boolean ifExists = options.getChildCount() > 0 && "exists".equalsIgnoreCase(options.getChild(0).getText());
        String tableName = ast.getChild(1).getText();
        if (db.getSchema().getTable(tableName) != null) {
            db.dropTable(tableName);
        } else if (!ifExists) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Table does not exists.");
View Full Code Here

            throw new SqlJetException(SqlJetErrorCode.ERROR, "Table does not exists.");
        }
    }

    private void handleDropIndex() throws SqlJetException {
        CommonTree options = (CommonTree) ast.getChild(0);
        boolean ifExists = options.getChildCount() > 0 && "exists".equalsIgnoreCase(options.getChild(0).getText());
        String indexName = ast.getChild(1).getText();
        if (db.getSchema().getIndex(indexName) != null) {
            db.dropIndex(indexName);
        } else if (!ifExists) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Index does not exists.");
View Full Code Here

    private final List<ISqlJetExpression> conditions, values;

    public SqlJetCaseExpression(CommonTree ast) throws SqlJetException {
        assert "case".equalsIgnoreCase(ast.getText());
        int idx = 0;
        CommonTree child = (CommonTree) ast.getChild(idx++);
        if ("when".equalsIgnoreCase(child.getText())) {
            expression = null;
        } else {
            expression = create(child);
            child = (CommonTree) ast.getChild(idx++);
        }
        List<ISqlJetExpression> conditions = new ArrayList<ISqlJetExpression>();
        List<ISqlJetExpression> values = new ArrayList<ISqlJetExpression>();
        while (idx < ast.getChildCount()) {
            if ("when".equalsIgnoreCase(child.getText())) {
                ISqlJetExpression condition = create((CommonTree) child.getChild(0));
                ISqlJetExpression value = create((CommonTree) child.getChild(1));
                conditions.add(condition);
                values.add(value);
                child = (CommonTree) ast.getChild(idx++);
            } else {
                break;
            }
        }
        this.conditions = Collections.unmodifiableList(conditions);
        this.values = Collections.unmodifiableList(values);
        if (idx < child.getChildCount()) {
            defaultValue = create(child);
        } else {
            defaultValue = null;
        }
    }
View Full Code Here

    private final List<ISqlJetExpression> values;

    public SqlJetInValuesExpression(CommonTree ast) throws SqlJetException {
        assert "in_values".equalsIgnoreCase(ast.getText());
        int idx = 0;
        CommonTree child = (CommonTree) ast.getChild(idx++);
        if ("not".equalsIgnoreCase(child.getText())) {
            not = true;
            child = (CommonTree) ast.getChild(idx++);
        } else {
            not = false;
        }
        assert "in".equalsIgnoreCase(child.getText());
        List<ISqlJetExpression> values = new ArrayList<ISqlJetExpression>();
        for (int exprIdx = 0; exprIdx < child.getChildCount(); exprIdx++) {
            values.add(create((CommonTree) child.getChild(exprIdx)));
        }
        this.values = Collections.unmodifiableList(values);
        expression = create((CommonTree) ast.getChild(idx));
    }
View Full Code Here

    public SqlJetColumnCollate(SqlJetColumnDef column, String name, CommonTree ast) {
        super(column, name);
        assert "collate".equalsIgnoreCase(ast.getText());
        assert ast.getChildCount() == 1;
        CommonTree child = (CommonTree) ast.getChild(0);
        collation = child.getText();
    }
View Full Code Here

     * @throws SqlJetException
     *
     */
    public SqlJetVirtualTableDef(CommonTree ast, int page) throws SqlJetException {

        final CommonTree nameNode = (CommonTree) ast.getChild(1);
        tableName = nameNode.getText();
        databaseName = nameNode.getChildCount() > 0 ? nameNode.getChild(0).getText() : null;

        final CommonTree moduleNode = (CommonTree) ast.getChild(2);
        moduleName = moduleNode.getText();

        List<ISqlJetColumnDef> moduleColumns = new ArrayList<ISqlJetColumnDef>();
        if (ast.getChildCount() > 3) {
            CommonTree defNode = (CommonTree) ast.getChild(3);
            if ("columns".equalsIgnoreCase(defNode.getText())) {
                for (int i = 0; i < defNode.getChildCount(); i++) {
                    moduleColumns.add(new SqlJetColumnDef((CommonTree) defNode.getChild(i)));
                }
            }
        }
        this.moduleColumns = Collections.unmodifiableList(moduleColumns);

View Full Code Here

    public SqlJetForeignKeyDeferrable(CommonTree ast) {
        assert "deferrable".equalsIgnoreCase(ast.getText());
        boolean not = false, deferred = false, immediate = false;
        for (int i = 0; i < ast.getChildCount(); i++) {
            CommonTree child = (CommonTree) ast.getChild(i);
            if ("not".equalsIgnoreCase(child.getText())) {
                assert !not;
                not = true;
            } else if ("deferred".equalsIgnoreCase(child.getText())) {
                assert !deferred;
                assert !immediate;
                deferred = true;
            } else if ("immediate".equalsIgnoreCase(child.getText())) {
                assert !deferred;
                assert !immediate;
                immediate = true;
            } else {
                assert false;
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.