當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。