当前位置: 首页>>代码示例>>Java>>正文


Java Interval.of方法代码示例

本文整理汇总了Java中org.antlr.v4.runtime.misc.Interval.of方法的典型用法代码示例。如果您正苦于以下问题:Java Interval.of方法的具体用法?Java Interval.of怎么用?Java Interval.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.antlr.v4.runtime.misc.Interval的用法示例。


在下文中一共展示了Interval.of方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStateToGrammarRegionMap

import org.antlr.v4.runtime.misc.Interval; //导入方法依赖的package包/类
public static Map<Integer, Interval> getStateToGrammarRegionMap(GrammarRootAST ast, IntervalSet grammarTokenTypes) {
	Map<Integer, Interval> stateToGrammarRegionMap = new HashMap<Integer, Interval>();
	if ( ast==null ) return stateToGrammarRegionMap;

	List<GrammarAST> nodes = ast.getNodesWithType(grammarTokenTypes);
	for (GrammarAST n : nodes) {
		if (n.atnState != null) {
			Interval tokenRegion = Interval.of(n.getTokenStartIndex(), n.getTokenStopIndex());
			org.antlr.runtime.tree.Tree ruleNode = null;
			// RULEs, BLOCKs of transformed recursive rules point to original token interval
			switch ( n.getType() ) {
				case ANTLRParser.RULE :
					ruleNode = n;
					break;
				case ANTLRParser.BLOCK :
				case ANTLRParser.CLOSURE :
					ruleNode = n.getAncestor(ANTLRParser.RULE);
					break;
			}
			if ( ruleNode instanceof RuleAST ) {
				String ruleName = ((RuleAST) ruleNode).getRuleName();
				Rule r = ast.g.getRule(ruleName);
				if ( r instanceof LeftRecursiveRule ) {
					RuleAST originalAST = ((LeftRecursiveRule) r).getOriginalAST();
					tokenRegion = Interval.of(originalAST.getTokenStartIndex(), originalAST.getTokenStopIndex());
				}
			}
			stateToGrammarRegionMap.put(n.atnState.stateNumber, tokenRegion);
		}
	}
	return stateToGrammarRegionMap;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:33,代码来源:Grammar.java

示例2: reportAttemptingFullContext

import org.antlr.v4.runtime.misc.Interval; //导入方法依赖的package包/类
protected void reportAttemptingFullContext(@NotNull DFA dfa, @Nullable BitSet conflictingAlts, @NotNull ATNConfigSet configs, int startIndex, int stopIndex) {
     if ( debug || retry_debug ) {
Interval interval = Interval.of(startIndex, stopIndex);
System.out.println("reportAttemptingFullContext decision="+dfa.decision+":"+configs+
                            ", input="+parser.getTokenStream().getText(interval));
     }
     if ( parser!=null ) parser.getErrorListenerDispatch().reportAttemptingFullContext(parser, dfa, startIndex, stopIndex, conflictingAlts, configs);
 }
 
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:9,代码来源:ParserATNSimulator.java

示例3: reportContextSensitivity

import org.antlr.v4.runtime.misc.Interval; //导入方法依赖的package包/类
protected void reportContextSensitivity(@NotNull DFA dfa, int prediction, @NotNull ATNConfigSet configs, int startIndex, int stopIndex) {
     if ( debug || retry_debug ) {
Interval interval = Interval.of(startIndex, stopIndex);
         System.out.println("reportContextSensitivity decision="+dfa.decision+":"+configs+
                            ", input="+parser.getTokenStream().getText(interval));
     }
     if ( parser!=null ) parser.getErrorListenerDispatch().reportContextSensitivity(parser, dfa, startIndex, stopIndex, prediction, configs);
 }
 
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:9,代码来源:ParserATNSimulator.java

示例4: reportAmbiguity

import org.antlr.v4.runtime.misc.Interval; //导入方法依赖的package包/类
/** If context sensitive parsing, we know it's ambiguity not conflict */
   protected void reportAmbiguity(@NotNull DFA dfa, DFAState D, int startIndex, int stopIndex,
							   boolean exact,
							   @Nullable BitSet ambigAlts,
							   @NotNull ATNConfigSet configs)
{
	if ( debug || retry_debug ) {
		Interval interval = Interval.of(startIndex, stopIndex);
		System.out.println("reportAmbiguity "+
						   ambigAlts+":"+configs+
                              ", input="+parser.getTokenStream().getText(interval));
       }
       if ( parser!=null ) parser.getErrorListenerDispatch().reportAmbiguity(parser, dfa, startIndex, stopIndex,
																		  exact, ambigAlts, configs);
   }
 
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:16,代码来源:ParserATNSimulator.java

示例5: showTokenInfoUponCtrlKey

import org.antlr.v4.runtime.misc.Interval; //导入方法依赖的package包/类
/**
	 * Show token information if the ctrl-key is down and mouse movement occurs
	 */
	public void showTokenInfoUponCtrlKey(Editor editor, PreviewState previewState, int offset) {
		Token tokenUnderCursor = ParsingUtils.getTokenUnderCursor(previewState, offset);
		if ( tokenUnderCursor==null ) {
			PreviewParser parser = (PreviewParser) previewState.parsingResult.parser;
			CommonTokenStream tokenStream = (CommonTokenStream) parser.getInputStream();
			tokenUnderCursor = ParsingUtils.getSkippedTokenUnderCursor(tokenStream, offset);
		}

		if ( tokenUnderCursor==null ) {
			return;
		}

//		System.out.println("token = "+tokenUnderCursor);
		String channelInfo = "";
		int channel = tokenUnderCursor.getChannel();
		if ( channel!=Token.DEFAULT_CHANNEL ) {
			String chNum = channel==Token.HIDDEN_CHANNEL ? "hidden" : String.valueOf(channel);
			channelInfo = ", Channel "+chNum;
		}
		JBColor color = JBColor.BLUE;
		String tokenInfo =
			String.format("#%d Type %s, Line %d:%d%s",
			              tokenUnderCursor.getTokenIndex(),
			              previewState.g.getTokenDisplayName(tokenUnderCursor.getType()),
			              tokenUnderCursor.getLine(),
			              tokenUnderCursor.getCharPositionInLine(),
			              channelInfo
			             );
		if ( channel==-1 ) {
			tokenInfo = "Skipped";
			color = JBColor.gray;
		}

		Interval sourceInterval = Interval.of(tokenUnderCursor.getStartIndex(),
		                                      tokenUnderCursor.getStopIndex()+1);
		highlightAndOfferHint(editor, offset, sourceInterval,
		                      color, EffectType.LINE_UNDERSCORE, tokenInfo);
	}
 
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:42,代码来源:InputPanel.java

示例6: popupLookaheadTreesDialog

import org.antlr.v4.runtime.misc.Interval; //导入方法依赖的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

示例7: rangeToInterval

import org.antlr.v4.runtime.misc.Interval; //导入方法依赖的package包/类
private static Interval rangeToInterval(Range range) {
    return Interval.of((int) range.getBegin(), (int) range.getEnd());
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:4,代码来源:RangeUtils.java

示例8: getSourceInterval

import org.antlr.v4.runtime.misc.Interval; //导入方法依赖的package包/类
@Override
public Interval getSourceInterval() {
	if ( start==null || stop==null ) return Interval.INVALID;
	return Interval.of(start.getTokenIndex(), stop.getTokenIndex());
}
 
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:6,代码来源:ParserRuleContext.java

示例9: showParseRegion

import org.antlr.v4.runtime.misc.Interval; //导入方法依赖的package包/类
/**
	 * Show tokens/region associated with parse tree parent of this token
	 * if the alt-key is down and mouse movement occurs.
	 */
	public void showParseRegion(EditorMouseEvent event, Editor editor,
	                            PreviewState previewState, int offset) {
		Token tokenUnderCursor = ParsingUtils.getTokenUnderCursor(previewState, offset);
		if ( tokenUnderCursor==null ) {
			return;
		}

		ParseTree tree = previewState.parsingResult.tree;
		TerminalNode nodeWithToken =
			(TerminalNode) ParsingUtils.getParseTreeNodeWithToken(tree, tokenUnderCursor);
		if ( nodeWithToken==null ) {
			// hidden token
			return;
		}

		PreviewParser parser = (PreviewParser) previewState.parsingResult.parser;
		CommonTokenStream tokenStream = (CommonTokenStream) parser.getInputStream();
		ParserRuleContext parent = (ParserRuleContext) nodeWithToken.getParent();
		Interval tokenInterval = parent.getSourceInterval();
		Token startToken = tokenStream.get(tokenInterval.a);
		Token stopToken = tokenStream.get(tokenInterval.b);
		Interval sourceInterval =
			Interval.of(startToken.getStartIndex(), stopToken.getStopIndex()+1);
//		int ruleIndex = parent.getRuleIndex();
//		String ruleName = parser.getRuleNames()[ruleIndex];
//        System.out.println("parent " + ruleName + " region " + sourceInterval);

		List<String> stack = parser.getRuleInvocationStack(parent);
		Collections.reverse(stack);

		if ( stack.size()>MAX_STACK_DISPLAY ) {
			// collapse contiguous dups to handle left-recursive stacks
			List<Pair<String, Integer>> smaller = new ArrayList<Pair<String, Integer>>();
			int last = 0;
			smaller.add(new Pair<String, Integer>(stack.get(0), 1)); // init to having first element, count of 1
			for (int i = 1; i<stack.size(); i++) {
				String s = stack.get(i);
				if ( smaller.get(last).a.equals(s) ) {
					smaller.set(last, new Pair<String, Integer>(s, smaller.get(last).b+1));
				}
				else {
					smaller.add(new Pair<String, Integer>(s, 1));
					last++;
				}
			}
			stack = new ArrayList<String>();
			for (int i = 0; i<smaller.size(); i++) {
				Pair<String, Integer> pair = smaller.get(i);
				if ( pair.b>1 ) {
					stack.add(pair.a+"^"+pair.b);
				}
				else {
					stack.add(pair.a);
				}
			}
		}
		String stackS = Utils.join(stack.toArray(), "\n");
		highlightAndOfferHint(editor, offset, sourceInterval,
		                      JBColor.BLUE, EffectType.ROUNDED_BOX, stackS);


		// Code for a balloon.

//		JBPopupFactory popupFactory = JBPopupFactory.getInstance();
//		BalloonBuilder builder =
//		    popupFactory.createHtmlTextBalloonBuilder(Utils.join(stack.toArray(), "<br>"),
//												  MessageType.INFO, null);
//		builder.setHideOnClickOutside(true);
//		Balloon balloon = builder.createBalloon();
//		MouseEvent mouseEvent = event.getMouseEvent();
//		Point point = mouseEvent.getPoint();
//		point.translate(10, -15);
//		RelativePoint where = new RelativePoint(mouseEvent.getComponent(), point);
//		balloon.show(where, Balloon.Position.above);
	}
 
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:80,代码来源:InputPanel.java


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