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);
}
ShowAmbigTreesDialog.java 文件源码
java
阅读 19
收藏 0
点赞 0
评论 0
项目:intellij-plugin-v4
作者:
评论列表
文章目录