Search in sources :

Example 21 with Tree

use of org.antlr.runtime.tree.Tree in project jabref by JabRef.

the class VM method executeInContext.

private void executeInContext(Object o, BstEntry context) {
    if (o instanceof Tree) {
        Tree t = (Tree) o;
        new StackFunction(t).execute(context);
    } else if (o instanceof Identifier) {
        execute(((Identifier) o).getName(), context);
    }
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) Tree(org.antlr.runtime.tree.Tree)

Example 22 with Tree

use of org.antlr.runtime.tree.Tree in project jabref by JabRef.

the class VM method integers.

/**
     * Declares global integer variables. It has one argument, a list of
     * variable names. There are two such automatically-declared variables,
     * entry.max$ and global.max$, used for limiting the lengths of string vari-
     * ables. You may have any number of these commands, but a variable's
     * declaration must precede its use.
     *
     * @param child
     */
private void integers(Tree child) {
    Tree t = child.getChild(0);
    for (int i = 0; i < t.getChildCount(); i++) {
        String name = t.getChild(i).getText();
        integers.put(name, 0);
    }
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) Tree(org.antlr.runtime.tree.Tree)

Example 23 with Tree

use of org.antlr.runtime.tree.Tree in project jabref by JabRef.

the class VM method strings.

/**
     * Declares global string variables. It has one argument, a list of variable
     * names. You may have any number of these commands, but a variable's
     * declaration must precede its use.
     *
     * @param child
     */
private void strings(Tree child) {
    Tree t = child.getChild(0);
    for (int i = 0; i < t.getChildCount(); i++) {
        String name = t.getChild(i).getText();
        strings.put(name, null);
    }
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) Tree(org.antlr.runtime.tree.Tree)

Example 24 with Tree

use of org.antlr.runtime.tree.Tree in project jabref by JabRef.

the class VM method run.

public String run(Collection<BibEntry> bibtex) {
    // Reset
    bbl = new StringBuilder();
    strings = new HashMap<>();
    integers = new HashMap<>();
    integers.put("entry.max$", Integer.MAX_VALUE);
    integers.put("global.max$", Integer.MAX_VALUE);
    functions = new HashMap<>();
    functions.putAll(buildInFunctions);
    stack = new Stack<>();
    // Create entries
    entries = new ArrayList<>(bibtex.size());
    ListIterator<BstEntry> listIter = entries.listIterator();
    for (BibEntry entry : bibtex) {
        listIter.add(new BstEntry(entry));
    }
    // Go
    for (int i = 0; i < tree.getChildCount(); i++) {
        Tree child = tree.getChild(i);
        switch(child.getType()) {
            case BstParser.STRINGS:
                strings(child);
                break;
            case BstParser.INTEGERS:
                integers(child);
                break;
            case BstParser.FUNCTION:
                function(child);
                break;
            case BstParser.EXECUTE:
                execute(child);
                break;
            case BstParser.SORT:
                sort();
                break;
            case BstParser.ITERATE:
                iterate(child);
                break;
            case BstParser.REVERSE:
                reverse(child);
                break;
            case BstParser.ENTRY:
                entry(child);
                break;
            case BstParser.READ:
                read();
                break;
            case BstParser.MACRO:
                macro(child);
                break;
            default:
                LOGGER.info("Unknown type: " + child.getType());
                break;
        }
    }
    return bbl.toString();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) CommonTree(org.antlr.runtime.tree.CommonTree) Tree(org.antlr.runtime.tree.Tree)

Example 25 with Tree

use of org.antlr.runtime.tree.Tree in project hive by apache.

the class BaseSemanticAnalyzer method getSkewedValuesFromASTNode.

/**
 * Retrieve skewed values from ASTNode.
 *
 * @param node
 * @return
 * @throws SemanticException
 */
protected List<String> getSkewedValuesFromASTNode(Node node) throws SemanticException {
    List<String> result = null;
    Tree leafVNode = ((ASTNode) node).getChild(0);
    if (leafVNode == null) {
        throw new SemanticException(ErrorMsg.SKEWED_TABLE_NO_COLUMN_VALUE.getMsg());
    } else {
        ASTNode lVAstNode = (ASTNode) leafVNode;
        if (lVAstNode.getToken().getType() != HiveParser.TOK_TABCOLVALUE) {
            throw new SemanticException(ErrorMsg.SKEWED_TABLE_NO_COLUMN_VALUE.getMsg());
        } else {
            result = new ArrayList<String>(getSkewedValueFromASTNode(lVAstNode));
        }
    }
    return result;
}
Also used : Tree(org.antlr.runtime.tree.Tree)

Aggregations

Tree (org.antlr.runtime.tree.Tree)215 Test (org.junit.Test)98 RuleReturnScope (org.antlr.runtime.RuleReturnScope)82 CommonTree (org.antlr.runtime.tree.CommonTree)39 ArrayList (java.util.ArrayList)27 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)18 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)18 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)18 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)18 DefaultConstraint (org.apache.hadoop.hive.ql.metadata.DefaultConstraint)12 DDLWork (org.apache.hadoop.hive.ql.ddl.DDLWork)11 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)11 HashMap (java.util.HashMap)9 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)9 Node (org.apache.hadoop.hive.ql.lib.Node)9 IOException (java.io.IOException)8 HashSet (java.util.HashSet)8 LinkedHashMap (java.util.LinkedHashMap)8 List (java.util.List)8 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)8