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);
}
}
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);
}
}
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);
}
}
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();
}
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;
}
Aggregations