本文整理匯總了Java中org.antlr.v4.runtime.tree.ParseTree類的典型用法代碼示例。如果您正苦於以下問題:Java ParseTree類的具體用法?Java ParseTree怎麽用?Java ParseTree使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ParseTree類屬於org.antlr.v4.runtime.tree包,在下文中一共展示了ParseTree類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: eval
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
final ANTLRInputStream is = new ANTLRInputStream(args[0].getStringValue());
final CorpusQLLexer lexer = new CorpusQLLexer(is);
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final CorpusQLParser parser = new CorpusQLParser(tokens);
final ParseTree tree = parser.query();
final MemTreeBuilder builder = new MemTreeBuilder();
builder.startDocument();
final CorpusQLXMLVisitor xmlVisitor = new CorpusQLXMLVisitor(builder);
xmlVisitor.visit(tree);
builder.endDocument();
return builder.getDocument();
}
示例2: enterPattern_matcher
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
@Override
public void enterPattern_matcher(SQLParser.Pattern_matcherContext ctx) {
super.enterPattern_matcher(ctx);
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof TerminalNodeImpl) {
if (isNot(child.getText())) {
currentPredicate.negate();
}
break;
}
}
if (currentPredicate.isNegated()) {
currentPredicate.setOperator("not like");
} else {
currentPredicate.setOperator("like");
}
skipNextTerminal = true;
}
示例3: callSql
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
public PlanNode callSql(String sqlstring, ArrayList list) throws FileNotFoundException, IOException {
for (int i=0; i< list.size() ; i++) {
sqlstring = sqlstring.replaceFirst("\\?", (String) list.get(i));
}
ANTLRInputStream input = new ANTLRInputStream( new ByteArrayInputStream(sqlstring.getBytes()));
PLSQLLexer lexer = new PLSQLLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PLSQLParser parser = new PLSQLParser(tokens);
parser.setBuildParseTree(true);
ParseTree tree = parser.sql_statement();
ParseTreeWalker walker = new ParseTreeWalker();
SQLModel model = new SQLModel();
walker.walk(new MyListener(model), tree);
return model.current;
}
示例4: GraphParser
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
public GraphParser(InputStream is) throws GraphParserException {
DOTLexer lexer = null;
DOTParser parser = null;
try {
lexer = new DOTLexer(new ANTLRInputStream(is));
lexer.addErrorListener(new ErrorListener());
parser = new DOTParser(new CommonTokenStream(lexer));
parser.setErrorHandler(new ExceptionErrorStrategy());
parser.addErrorListener(new ErrorListener());
ParseTree tree = parser.graph();
ParseTreeWalker.DEFAULT.walk(new NodeListener(), tree);
ParseTreeWalker.DEFAULT.walk(new EdgeListener(), tree);
}
catch (Throwable t) {
if (mErrMsg != null) throw new GraphParserException(mErrMsg, t);
if (lexer != null) {
mErrMsg = "at line " + lexer.getLine() + ":" + lexer.getCharPositionInLine();
throw new GraphParserException(mErrMsg, t);
}
throw new GraphParserException(t);
}
if (mErrMsg != null) throw new GraphParserException(mErrMsg);
}
示例5: getFunctionTypeEndingWithVariadic
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
public Expression getFunctionTypeEndingWithVariadic(String varName, ParseTree node) {
String[] params = varName.split("\\$");
if(params.length < 2) return null;
for(int i = params.length - 1; i >= 1; i--) {
String param = params[i];
for(int j = i + 1; j < params.length; j++) if(!params[j].equals(param)) return null;
String subVarName = "";
for(int j = 0; j < i; j++) subVarName += (j > 0 ? "$" : "") + params[j];
subVarName += "$_Array";
CacheObject cache = findCache(subVarName, node);
/*if(cache != null && cache.type instanceof FunctionType) {
List<AbstractType> parameterTypes = ((FunctionType)cache.type).parameterTypes;
if(!parameterTypes.get(parameterTypes.size() - 1).resulting(null).swiftType().equals(param.split("_")[1])) continue;
return new Expression(subVarName, cache.type);
}*/
}
return null;
}
示例6: visitApiFacets
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
@Override
public Object visitApiFacets(RAMLParser.ApiFacetsContext ctx) {
// TODO move creation of security schemes to 1 pass
final RAMLParser.SecuritySchemesFacetContext securitySchemesFacet = ctx.securitySchemesFacet();
if (securitySchemesFacet != null) {
visitSecuritySchemesFacet(securitySchemesFacet);
}
for (int i = 0; i < ctx.getChildCount(); i++) {
final ParseTree child = ctx.getChild(i);
if (child != securitySchemesFacet) {
child.accept(this);
}
}
return scope.eObject();
}
示例7: cloneExprContext
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
/**
* Cloning expression to create new same expression.
*/
public static ExprContext cloneExprContext(final ExprContext expr) {
final ExprContext clone = createContextType(expr);
clone.copyFrom(expr);
for (final ParseTree child : expr.children) {
if (child instanceof TerminalNode) {
clone.addChild(new TerminalNodeImpl(((TerminalNode) child).getSymbol()));
} else if (child instanceof ExprContext) {
final ExprContext cloneChild = cloneExprContext((ExprContext) child);
clone.addChild(cloneChild);
setLeftRight(clone, cloneChild);
} else if (child instanceof Token) {
clone.addChild(new CommonToken((Token) child));
}
}
return clone;
}
示例8: checkValidYangFileForNoSyntaxError
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
/**
* Checks that no exception is generated for YANG file with valid syntax.
*/
@Test
public void checkValidYangFileForNoSyntaxError() throws IOException {
ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithoutSyntaxError.yang");
// Create a lexer that feeds off of input char stream.
GeneratedYangLexer lexer = new GeneratedYangLexer(input);
// Create a buffer of tokens pulled from the lexer.
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Create a parser that feeds off the tokens buffer.
GeneratedYangParser parser = new GeneratedYangParser(tokens);
// Remove console error listener.
parser.removeErrorListeners();
// Create instance of customized error listener.
ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
// Add customized error listener to catch errors during parsing.
parser.addErrorListener(parseTreeErrorListener);
// Begin parsing YANG file and generate parse tree.
ParseTree tree = parser.yangfile();
}
示例9: checkInvalidYangFileForSyntaxError
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
/**
* Checks that exception is generated for YANG file with invalid syntax.
*/
@Test
public void checkInvalidYangFileForSyntaxError() throws IOException {
// Get the exception occurred during parsing.
thrown.expect(ParserException.class);
thrown.expect(CustomExceptionMatcher.errorLocation(3, 0));
thrown.expectMessage("no viable alternative at input 'yang-version 1\\nnamespace'");
ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithSyntaxError.yang");
// Create a lexer that feeds off of input char stream.
GeneratedYangLexer lexer = new GeneratedYangLexer(input);
// Create a buffer of tokens pulled from the lexer.
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Create a parser that feeds off the tokens buffer.
GeneratedYangParser parser = new GeneratedYangParser(tokens);
// Remove console error listener.
parser.removeErrorListeners();
// Create instance of customized error listener.
ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
// Add customized error listener to catch errors during parsing.
parser.addErrorListener(parseTreeErrorListener);
// Begin parsing YANG file and generate parse tree.
ParseTree tree = parser.yangfile();
}
示例10: AntlrBridge
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
public AntlrBridge(String input){
// String inputFile = null;
// if ( input.length()>0 ) inputFile = input;
// InputStream is = input;
// if ( inputFile!=null ) is = new FileInputStream(inputFile);
ANTLRInputStream antlrInput = new ANTLRInputStream(input);
SequenceAnalyzerLexer lexer = new SequenceAnalyzerLexer(antlrInput);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SequenceAnalyzerParser parser = new SequenceAnalyzerParser(tokens);
ParseTree tree = parser.prog(); // parse
CommandObjectVisitor coVisitor = new CommandObjectVisitor();
coVisitor.visit(tree);
Stack<CommandObject> commandObjectStack = coVisitor.commandObjectStack;
commandExecutor.executeStack(commandObjectStack);
}
示例11: inform
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
private void inform(String match, String key, String value, ParseTree ctx) {
Set<MatcherAction> relevantActions = informMatcherActions.get(match.toLowerCase(Locale.ENGLISH));
if (verbose) {
if (relevantActions == null) {
LOG.info("--- Have (0): {}", match);
} else {
LOG.info("+++ Have ({}): {}", relevantActions.size(), match);
int count = 1;
for (MatcherAction action : relevantActions) {
LOG.info("+++ -------> ({}): {}", count, action.toString());
count++;
}
}
}
if (relevantActions != null) {
for (MatcherAction matcherAction : relevantActions) {
matcherAction.inform(key, value, ctx);
}
}
}
示例12: walk
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
@Override
public WalkResult walk(ParseTree tree, String value) {
String actualValue = getActualValue(tree, value);
String filteredValue;
if (tree.getChildCount() == 1 && (
tree.getChild(0) instanceof SingleVersionContext ||
tree.getChild(0) instanceof SingleVersionWithCommasContext)) {
filteredValue = VersionSplitter.getInstance().getSplitRange(actualValue, firstWord, lastWord);
} else {
filteredValue = WordSplitter.getInstance().getSplitRange(actualValue, firstWord, lastWord);
}
if (filteredValue == null) {
return null;
}
return walkNextStep(tree, filteredValue);
}
示例13: getGenerator
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
@SuppressWarnings("unchecked")
static public Generator<ParseTree> getGenerator(ParseTree ctx) throws OrcaException {
Class<?> klass = ctx.getClass();
Generator<ParseTree> generator = _generatorByName.get(klass);
if (generator == null) {
String key = StringUtils.removeStart(klass.getSimpleName(), "FishParser$");
key = StringUtils.removeEnd(key, "Context");
key += "Generator";
try {
key = InstructionGenerator.class.getPackage().getName() + "." + key;
Class<?> generatorClass = Class.forName(key);
generator = (Generator<ParseTree>)generatorClass.newInstance();
_generatorByName.put(klass, generator);
}
catch (Exception x) {
throw new OrcaException("instruction geneartor is not found: " + key, x);
}
}
return generator;
}
示例14: earliestAncestorWithChildStartingAtCharPos
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
/** Walk upwards from node until we find a child of p at t's char position.
* Don't see alignment with self, t, or element *after* us.
* return null if there is no such ancestor p.
*/
public static Pair<ParserRuleContext,Integer> earliestAncestorWithChildStartingAtCharPos(ParserRuleContext node, Token t, int charpos) {
ParserRuleContext p = node;
while ( p!=null ) {
// check all children of p to see if one of them starts at charpos
for (int i = 0; i<p.getChildCount(); i++) {
ParseTree child = p.getChild(i);
Token start;
if ( child instanceof ParserRuleContext ) {
start = ((ParserRuleContext) child).getStart();
}
else { // must be token
start = ((TerminalNode)child).getSymbol();
}
// check that we don't see alignment with self or element *after* us
if ( start.getTokenIndex()<t.getTokenIndex() && start.getCharPositionInLine()==charpos ) {
return new Pair<>(p,i);
}
}
p = p.getParent();
}
return null;
}
示例15: visitATTR_OPER_EXPR
import org.antlr.v4.runtime.tree.ParseTree; //導入依賴的package包/類
/**
* {@inheritDoc}
* <p>
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public String visitATTR_OPER_EXPR(ScimFilterParser.ATTR_OPER_EXPRContext ctx) {
logger.info(" ScimGroupFilterVisitor.visitATTR_OPER_EXPR() ");
ParseTree parent = ctx.getParent();
while (parent != null) {
if (parent.getClass().getSimpleName().equalsIgnoreCase(ScimFilterParser.LBRAC_EXPR_RBRACContext.class.getSimpleName())) {
logger.info("********** PARENT = " + parent.getClass().getSimpleName());
String attrName = ((ScimFilterParser.LBRAC_EXPR_RBRACContext)parent).ATTRNAME() + "." + ctx.ATTRNAME().getText();
return attrOperCriteriaResolver(attrName, visit(ctx.operator()), visit(ctx.expression()));
} else {
parent = parent.getParent();
}
}
return attrOperCriteriaResolver(ctx.ATTRNAME().getText(), visit(ctx.operator()), visit(ctx.expression()));
}