• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ParserInterpreter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.antlr.v4.runtime.ParserInterpreter的典型用法代码示例。如果您正苦于以下问题:Java ParserInterpreter类的具体用法?Java ParserInterpreter怎么用?Java ParserInterpreter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ParserInterpreter类属于org.antlr.v4.runtime包,在下文中一共展示了ParserInterpreter类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createParserInterpreter

import org.antlr.v4.runtime.ParserInterpreter; //导入依赖的package包/类
public ParserInterpreter createParserInterpreter(TokenStream tokenStream) {
	if (this.isLexer()) {
		throw new IllegalStateException("A parser interpreter can only be created for a parser or combined grammar.");
	}

	char[] serializedAtn = ATNSerializer.getSerializedAsChars(atn);
	ATN deserialized = new ATNDeserializer().deserialize(serializedAtn);
	return new ParserInterpreter(fileName, getVocabulary(), Arrays.asList(getRuleNames()), deserialized, tokenStream);
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:10,代码来源:Grammar.java


示例2: popupLookaheadTreesDialog

import org.antlr.v4.runtime.ParserInterpreter; //导入依赖的package包/类
public static void popupLookaheadTreesDialog(PreviewState previewState, LookaheadEventInfo lookaheadInfo) {
	// pop up subtrees for lookahead
	ShowAmbigTreesDialog dialog = new ShowAmbigTreesDialog();
	ParserInterpreter parser = (ParserInterpreter) previewState.parsingResult.parser;
	int startRuleIndex = parser.getRuleIndex(previewState.startRuleName);
	List<ParserRuleContext> lookaheadParseTrees =
		GrammarParserInterpreter.getLookaheadParseTrees(previewState.g,
		                                                parser,
		                                                parser.getTokenStream(),
		                                                startRuleIndex,
		                                                lookaheadInfo.decision,
		                                                lookaheadInfo.startIndex,
		                                                lookaheadInfo.stopIndex);
	if ( parser.getNumberOfSyntaxErrors()>0 ) {
		// should be no errors for ambiguities, unless original
		// input itself has errors. Just display error in this case.
		JBPanel errPanel = new JBPanel(new BorderLayout());
		errPanel.add(new JBLabel("Cannot display lookahead trees while there are syntax errors in your input."));
		dialog.treeScrollPane.setViewportView(errPanel);
		lookaheadParseTrees = null;
	}
	if ( lookaheadParseTrees!=null ) {
		Interval range = Interval.of(lookaheadInfo.startIndex, lookaheadInfo.stopIndex);
		String phrase = parser.getTokenStream().getText(range);
		if ( phrase.length()>MAX_PHRASE_WIDTH ) {
			phrase = phrase.substring(0, MAX_PHRASE_WIDTH)+"...";
		}
		String title = lookaheadParseTrees.size()+
			" Interpretations of Lookahead Phrase: "+
			phrase;
		dialog.ambigPhraseLabel.setText(title);
		dialog.setTrees(previewState, lookaheadParseTrees, title, lookaheadInfo.predictedAlt-1,
		                lookaheadInfo.startIndex, lookaheadInfo.stopIndex, false);
	}
	dialog.pack();
	dialog.setVisible(true);
}
 
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:38,代码来源:ShowAmbigTreesDialog.java


示例3: getLookaheadParseTrees

import org.antlr.v4.runtime.ParserInterpreter; //导入依赖的package包/类
/** Return a list of parse trees, one for each alternative in a decision
 *  given the same input.
 *
 *  Very similar to {@link #getAllPossibleParseTrees} except
 *  that it re-parses the input for every alternative in a decision,
 *  not just the ambiguous ones (there is no alts parameter here).
 *  This method also tries to reduce the size of the parse trees
 *  by stripping away children of the tree that are completely out of range
 *  of startIndex..stopIndex. Also, because errors are expected, we
 *  use a specialized error handler that more or less bails out
 *  but that also consumes the first erroneous token at least. This
 *  ensures that an error node will be in the parse tree for display.
 *
 *  NOTES:
   // we must parse the entire input now with decision overrides
// we cannot parse a subset because it could be that a decision
// above our decision of interest needs to read way past
// lookaheadInfo.stopIndex. It seems like there is no escaping
// the use of a full and complete token stream if we are
// resetting to token index 0 and re-parsing from the start symbol.
// It's not easy to restart parsing somewhere in the middle like a
// continuation because our call stack does not match the
// tree stack because of left recursive rule rewriting. grrrr!
 *
 * @since 4.5.1
 */
public static List<ParserRuleContext> getLookaheadParseTrees(Grammar g,
															 ParserInterpreter originalParser,
															 TokenStream tokens,
															 int startRuleIndex,
															 int decision,
															 int startIndex,
															 int stopIndex)
{
	List<ParserRuleContext> trees = new ArrayList<ParserRuleContext>();
	// Create a new parser interpreter to parse the ambiguous subphrase
	ParserInterpreter parser = deriveTempParserInterpreter(g, originalParser, tokens);
	BailButConsumeErrorStrategy errorHandler = new BailButConsumeErrorStrategy();
	parser.setErrorHandler(errorHandler);

	DecisionState decisionState = originalParser.getATN().decisionToState.get(decision);

	for (int alt=1; alt<=decisionState.getTransitions().length; alt++) {
		// re-parse entire input for all ambiguous alternatives
		// (don't have to do first as it's been parsed, but do again for simplicity
		//  using this temp parser.)
		parser.reset();
		parser.addDecisionOverride(decision, startIndex, alt);
		ParserRuleContext tt = parser.parse(startRuleIndex);
		int stopTreeAt = stopIndex;
		if ( errorHandler.firstErrorTokenIndex>=0 ) {
			stopTreeAt = errorHandler.firstErrorTokenIndex; // cut off rest at first error
		}
		ParserRuleContext subtree =
			Trees.getRootOfSubtreeEnclosingRegion(tt,
												  startIndex,
												  stopTreeAt);
		// Use higher of overridden decision tree or tree enclosing all tokens
		if ( Trees.isAncestorOf(parser.getOverrideDecisionRoot(), subtree) ) {
			subtree = parser.getOverrideDecisionRoot();
		}
		Trees.stripChildrenOutOfRange(subtree, parser.getOverrideDecisionRoot(), startIndex, stopTreeAt);
		trees.add(subtree);
	}

	return trees;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:68,代码来源:GrammarParserInterpreter.java


示例4: getParserInterpreter

import org.antlr.v4.runtime.ParserInterpreter; //导入依赖的package包/类
@Override
public ParserInterpreter getParserInterpreter() {
	return parser;
}
 
开发者ID:danishdynamite,项目名称:templates4j,代码行数:5,代码来源:Templates4jMojo.java


示例5: getParserInterpreter

import org.antlr.v4.runtime.ParserInterpreter; //导入依赖的package包/类
public ParserInterpreter getParserInterpreter(); 
开发者ID:danishdynamite,项目名称:templates4j,代码行数:2,代码来源:ParserInterpreterProvider.java



注:本文中的org.antlr.v4.runtime.ParserInterpreter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DynamicHeightImageView类代码示例发布时间:2022-05-23
下一篇:
Java TimeList类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap