本文整理汇总了Java中org.antlr.runtime.tree.Tree.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.getType方法的具体用法?Java Tree.getType怎么用?Java Tree.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.runtime.tree.Tree
的用法示例。
在下文中一共展示了Tree.getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasImmediateRecursiveRuleRefs
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
/**
* Match (RULE RULE_REF (BLOCK (ALT .*) (ALT RULE_REF[self] .*) (ALT .*)))
* Match (RULE RULE_REF (BLOCK (ALT .*) (ALT (ASSIGN ID RULE_REF[self]) .*) (ALT .*)))
*/
public static boolean hasImmediateRecursiveRuleRefs(GrammarAST t, String ruleName) {
if ( t==null ) return false;
GrammarAST blk = (GrammarAST)t.getFirstChildWithType(BLOCK);
if ( blk==null ) return false;
int n = blk.getChildren().size();
for (int i = 0; i < n; i++) {
GrammarAST alt = (GrammarAST)blk.getChildren().get(i);
Tree first = alt.getChild(0);
if ( first==null ) continue;
if (first.getType() == ELEMENT_OPTIONS) {
first = alt.getChild(1);
if (first == null) {
continue;
}
}
if ( first.getType()==RULE_REF && first.getText().equals(ruleName) ) return true;
Tree rref = first.getChild(1);
if ( rref!=null && rref.getType()==RULE_REF && rref.getText().equals(ruleName) ) return true;
}
return false;
}
示例2: toPredicate
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
private Predicate<T> toPredicate(Tree r) throws QueryParseException, IllegalArgumentException {
switch (r.getType()) {
case AND:
return and(children(r));
case OR:
return or(children(r));
case NOT:
return not(toPredicate(onlyChildOf(r)));
case DEFAULT_FIELD:
return defaultField(onlyChildOf(r));
case FIELD_NAME:
return operator(r.getText(), onlyChildOf(r));
default:
throw error("Unsupported operator: " + r);
}
}
示例3: translateQuantifier
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public Expression<Boolean> translateQuantifier(Tree n) {
Quantifier q;
switch(n.getType()) {
case EXISTS:
q = Quantifier.EXISTS;
break;
case FORALL:
q = Quantifier.FORALL;
break;
default:
throw new UnexpectedTokenException(n, FORALL, EXISTS);
}
List<? extends Variable<?>> vars = translateTypedVarList(n.getChild(0));
pushContext(vars);
Expression<Boolean> body = translateBoolExpression(n.getChild(1));
popContext();
return new QuantifierExpression(q, vars, body);
}
示例4: getText
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
static private String getText(Tree node)
{
String text = node.getText();
int index;
switch (node.getType())
{
case CMIS_FTSParser.FTSWORD:
index = text.indexOf('\\');
if (index == -1)
{
return text;
}
else
{
return unescape(text);
}
case CMIS_FTSParser.FTSPHRASE:
String phrase = text.substring(1, text.length() - 1);
index = phrase.indexOf('\\');
if (index == -1)
{
return phrase;
}
else
{
return unescape(phrase);
}
default:
return text;
}
}
示例5: getAllChildrenWithType
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public List<GrammarAST> getAllChildrenWithType(int type) {
List<GrammarAST> nodes = new ArrayList<GrammarAST>();
for (int i = 0; children!=null && i < children.size(); i++) {
Tree t = (Tree) children.get(i);
if ( t.getType()==type ) {
nodes.add((GrammarAST)t);
}
}
return nodes;
}
示例6: getLexerAction
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public ActionAST getLexerAction() {
Tree blk = getFirstChildWithType(ANTLRParser.BLOCK);
if ( blk.getChildCount()==1 ) {
Tree onlyAlt = blk.getChild(0);
Tree lastChild = onlyAlt.getChild(onlyAlt.getChildCount()-1);
if ( lastChild.getType()==ANTLRParser.ACTION ) {
return (ActionAST)lastChild;
}
}
return null;
}
示例7: blockHasWildcardAlt
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
/**
* {@code (BLOCK (ALT .))} or {@code (BLOCK (ALT 'a') (ALT .))}.
*/
public static boolean blockHasWildcardAlt(GrammarAST block) {
for (Object alt : block.getChildren()) {
if ( !(alt instanceof AltAST) ) continue;
AltAST altAST = (AltAST)alt;
if ( altAST.getChildCount()==1 || (altAST.getChildCount() == 2 && altAST.getChild(0).getType() == ANTLRParser.ELEMENT_OPTIONS) ) {
Tree e = altAST.getChild(altAST.getChildCount() - 1);
if ( e.getType()==ANTLRParser.WILDCARD ) {
return true;
}
}
}
return false;
}
示例8: executeCount
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
private void executeCount(Tree statement)
throws TException, InvalidRequestException, UnavailableException, TimedOutException
{
if (!CliMain.isConnected() || !hasKeySpace())
return;
Tree columnFamilySpec = statement.getChild(0);
String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, currentCfDefs());
int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
ColumnParent colParent = new ColumnParent(columnFamily).setSuper_column((ByteBuffer) null);
if (columnSpecCnt != 0)
{
Tree columnTree = columnFamilySpec.getChild(2);
byte[] superColumn = (columnTree.getType() == CliParser.FUNCTION_CALL)
? convertValueByFunction(columnTree, null, null).array()
: columnNameAsByteArray(CliCompiler.getColumn(columnFamilySpec, 0), columnFamily);
colParent = new ColumnParent(columnFamily).setSuper_column(superColumn);
}
SliceRange range = new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, Integer.MAX_VALUE);
SlicePredicate predicate = new SlicePredicate().setColumn_names(null).setSlice_range(range);
int count = thriftClient.get_count(getKeyAsBytes(columnFamily, columnFamilySpec.getChild(1)), colParent, predicate, consistencyLevel);
sessionState.out.printf("%d cells%n", count);
}
示例9: getKeyAsBytes
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public ByteBuffer getKeyAsBytes(String columnFamily, Tree keyTree)
{
if (keyTree.getType() == CliParser.FUNCTION_CALL)
return convertValueByFunction(keyTree, null, null);
String key = CliUtils.unescapeSQLString(keyTree.getText());
return getBytesAccordingToType(key, getKeyComparatorForCF(columnFamily));
}
示例10: requireType
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
private static void requireType(Tree n, int ...expected) {
int t = n.getType();
for(int i = 0; i < expected.length; i++) {
if(t == expected[i])
return;
}
throw new UnexpectedTokenException(n, expected);
}
示例11: operator
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
private Predicate<T> operator(String name, Tree val) throws QueryParseException {
switch (val.getType()) {
// Expand multiple values, "foo:(a b c)", as though they were written
// out with the longer form, "foo:a foo:b foo:c".
//
case AND:
case OR:
{
List<Predicate<T>> p = new ArrayList<>(val.getChildCount());
for (int i = 0; i < val.getChildCount(); i++) {
final Tree c = val.getChild(i);
if (c.getType() != DEFAULT_FIELD) {
throw error("Nested operator not expected: " + c);
}
p.add(operator(name, onlyChildOf(c)));
}
return val.getType() == AND ? and(p) : or(p);
}
case SINGLE_WORD:
case EXACT_PHRASE:
if (val.getChildCount() != 0) {
throw error("Expected no children under: " + val);
}
return operator(name, val.getText());
default:
throw error("Unsupported node in operator " + name + ": " + val);
}
}
示例12: translateIdentifier
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public String translateIdentifier(Tree n) {
switch(n.getType()) {
case ExpressionParser.ID:
return n.getText();
case ExpressionParser.QID:
String txt = n.getText();
// TODO : unescape quotes
return txt.substring(1, txt.length() - 1);
}
throw new UnexpectedTokenException(n, ExpressionParser.ID, ExpressionParser.QID);
}
示例13: translateBoolExpression
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public Expression<Boolean> translateBoolExpression(Tree n) {
switch(n.getType()) {
case FORALL:
case EXISTS:
return translateQuantifier(n);
case LIMP:
case LEQ:
case LXOR:
case LOR:
case LAND:
return translatePropositionalCompound(n);
case EQ:
case NE:
case LT:
case LE:
case GT:
case GE:
return translateNumericComparison(n);
case LNOT:
return translateLogicalNegation(n);
case TRUE:
return ExpressionUtil.TRUE;
case FALSE:
return ExpressionUtil.FALSE;
case QID:
case ID:
return (Expression<Boolean>) translateVariable(n);
}
throw new UnexpectedTokenException(n, FORALL, EXISTS, LIMP, LEQ, LXOR, LOR, LAND, EQ, NE, LT, LE, GT, GE, LNOT, TRUE, FALSE);
}
示例14: translateNumericComparison
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public Expression<Boolean> translateNumericComparison(Tree n) {
NumericComparator cmp;
switch(n.getType()) {
case EQ:
cmp = NumericComparator.EQ;
break;
case NE:
cmp = NumericComparator.NE;
break;
case LT:
cmp = NumericComparator.LT;
break;
case LE:
cmp = NumericComparator.LE;
break;
case GT:
cmp = NumericComparator.GT;
break;
case GE:
cmp = NumericComparator.GE;
break;
default:
throw new UnexpectedTokenException(n, EQ, NE, LT, LE, GT, GE);
}
Expression<?> left = translateArithmeticExpression(n.getChild(0));
Expression<?> right = translateArithmeticExpression(n.getChild(1));
return NumericBooleanExpression.create(left, cmp, right);
}
示例15: translateArithmeticExpression
import org.antlr.runtime.tree.Tree; //导入方法依赖的package包/类
public Expression<?> translateArithmeticExpression(Tree n) {
switch(n.getType()) {
case BVOR:
case BVXOR:
case BVAND:
case BVSHL:
case BVSHR:
case BVSHUR:
return translateBitvectorOperator(n);
case BVNEG:
return translateBitvectorNegation(n);
case ADD:
case SUB:
case MUL:
case DIV:
case REM:
return translateNumericCompound(n);
case UNARY_PLUS:
return translateArithmeticExpression(n.getChild(0));
case UNARY_MINUS:
return translateUnaryMinus(n);
case TYPE_CAST:
return translateTypeCast(n);
case ID:
case QID:
return translateVariable(n);
case BYTE_LITERAL:
case SHORT_LITERAL:
case INT_LITERAL:
case LONG_LITERAL:
case FLOAT_LITERAL:
case DOUBLE_LITERAL:
case BIGINT_LITERAL:
case BIGDECIMAL_LITERAL:
return translateLiteral(n);
default:
throw new UnexpectedTokenException(n, BVOR, BVXOR, BVAND, BVSHL, BVSHR, BVSHUR, BVNEG, ADD, SUB, MUL, DIV, REM, UNARY_PLUS, UNARY_MINUS, TYPE_CAST);
}
}