當前位置: 首頁>>代碼示例>>Java>>正文


Java Interval類代碼示例

本文整理匯總了Java中org.antlr.v4.runtime.misc.Interval的典型用法代碼示例。如果您正苦於以下問題:Java Interval類的具體用法?Java Interval怎麽用?Java Interval使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Interval類屬於org.antlr.v4.runtime.misc包,在下文中一共展示了Interval類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: recover

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@Override
public void recover(final LexerNoViableAltException lnvae) {
    final CharStream charStream = lnvae.getInputStream();
    final int startIndex = lnvae.getStartIndex();
    final String text = charStream.getText(Interval.of(startIndex, charStream.index()));

    Location location = new Location(sourceName, _tokenStartCharIndex);
    String message = "unexpected character [" + getErrorDisplay(text) + "].";
    char firstChar = text.charAt(0);
    if ((firstChar == '\'' || firstChar == '"') && text.length() - 2 > 0 && text.charAt(text.length() - 2) == '\\') {
        /* Use a simple heuristic to guess if the unrecognized characters were trying to be a string but has a broken escape sequence.
         * If it was add an extra message about valid string escape sequences. */
        message += " The only valid escape sequences in strings starting with [" + firstChar + "] are [\\\\] and [\\"
                + firstChar + "].";
    }
    throw location.createError(new IllegalArgumentException(message, lnvae));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:EnhancedPainlessLexer.java

示例2: dot

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
/**
 "If an operator has whitespace on the right side only, it is treated as a
 postfix unary operator. As an example, the ++ operator in a++ b is treated
 as a postfix unary operator."
 "If an operator has no whitespace on the left but is followed immediately
 by a dot (.), it is treated as a postfix unary operator. As an example,
 the ++ operator in a++.b is treated as a postfix unary operator (a++ .b
 rather than a ++ .b)."
 */
public static boolean isPostfixOp(TokenStream tokens) {
	int stop = getLastOpTokenIndex(tokens);
	if ( stop==-1 ) return false;

	int start = tokens.index();
	Token prevToken = tokens.get(start-1); // includes hidden-channel tokens
	Token nextToken = tokens.get(stop+1);
	boolean prevIsWS = isLeftOperatorWS(prevToken);
	boolean nextIsWS = isRightOperatorWS(nextToken);
	boolean result =
		!prevIsWS && nextIsWS ||
		!prevIsWS && nextToken.getType()==SwiftParser.DOT;
	String text = tokens.getText(Interval.of(start, stop));
	//System.out.println("isPostfixOp: '"+prevToken+"','"+text+"','"+nextToken+"' is "+result);
	return result;
}
 
開發者ID:marcelganczak,項目名稱:ts-swift-transpiler,代碼行數:26,代碼來源:SwiftSupport.java

示例3: getOriginalCodeText

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
/**
 * Get the original program text for the given parser-rule context.
 * This is required for preserving whitespaces.
 */
private String getOriginalCodeText(ParserRuleContext ctx) {
	int start = ctx.start.getStartIndex();
	int stop = ctx.stop.getStopIndex();
	Interval interval = new Interval(start, stop);
	return ctx.start.getInputStream().getText(interval);
}
 
開發者ID:ghaffarian,項目名稱:progex,代碼行數:11,代碼來源:JavaDDGBuilder.java

示例4: print

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
public static void print(final ParseTree node, final int level, CommonTokenStream stream) {
	final Interval sourceInterval = node.getSourceInterval();

	final Token firstToken = stream.get(sourceInterval.a);

	int line = firstToken.getLine();
	int charStart = firstToken.getCharPositionInLine();

	int endLine = line;
	int endChar = charStart + firstToken.getText().length();

	String data = "@(" + line + ":" + charStart + "," + endLine + ":" + endChar + ") with text: "
			+ firstToken.getText();
	final int tmp = level + 1;
	final StringBuilder sb = new StringBuilder();
	sb.append(StringUtils.repeat("\t", level));
	sb.append(node.getClass().getSimpleName() + ": " + data + " :" + node.getText());
	System.out.println(sb.toString());
	final int n = node.getChildCount();
	for (int i = 0; i < n; i++) {

		final ParseTree c = node.getChild(i);
		print(c, tmp, stream);

	}
}
 
開發者ID:gretard,項目名稱:sonar-tsql-plugin,代碼行數:27,代碼來源:Antlr4Utils.java

示例5: getStatementStrings

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
public List<String> getStatementStrings(String ksqlString) {
  List<SqlBaseParser.SingleStatementContext> statementContexts =
      new KsqlParser().getStatements(ksqlString);
  List<String> result = new ArrayList<>(statementContexts.size());
  for (SqlBaseParser.SingleStatementContext statementContext : statementContexts) {
    // Taken from http://stackoverflow.com/questions/16343288/how-do-i-get-the-original-text-that-an-antlr4-rule-matched
    CharStream charStream = statementContext.start.getInputStream();
    result.add(
        charStream.getText(
            new Interval(
                statementContext.start.getStartIndex(),
                statementContext.stop.getStopIndex()
            )
        )
    );
  }
  return result;
}
 
開發者ID:confluentinc,項目名稱:ksql,代碼行數:19,代碼來源:KsqlResource.java

示例6: getText

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@NotNull
private String getText(TokenStream tokens, Interval interval)
{
    int start = interval.a;
    int stop = interval.b;
    if (start < 0 || stop < 0)
        return "";
    
    if (stop >= tokens.size())
        stop = tokens.size() - 1;
    
    StringBuilder buf = new StringBuilder();
    for (int i = start; i <= stop; i++)
    {
        Token t = tokens.get(i);
        if (t.getType() == Token.EOF)
            break;
        buf.append(t.getText());
        if (i != stop)
        {
            buf.append(" ");
        }
    }
    return buf.toString();
}
 
開發者ID:HuaweiBigData,項目名稱:StreamCQL,代碼行數:26,代碼來源:CQLErrorStrategy.java

示例7: syntaxError

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@Override
	public void syntaxError(Recognizer<?, ?> recognizer,
							Object offendingSymbol,
							int line,
							int charPositionInLine,
							String msg,
							RecognitionException e)
	{
		if ( offendingSymbol==null ) {
			final Lexer lexer = (Lexer) recognizer;
			int i = lexer.getCharIndex();
			final int n = lexer.getInputStream().size();
			if (i >= n) {
				i = n - 1;
			}
			final String text = lexer.getInputStream().getText(new Interval(i, i));
			CommonToken t = (CommonToken) lexer.getTokenFactory().create(Token.INVALID_TYPE, text);
			t.setStartIndex(i);
			t.setStopIndex(i);
			t.setLine(line);
			t.setCharPositionInLine(charPositionInLine);
			offendingSymbol = t;
		}
//		System.out.println("lex error: " + offendingSymbol);
		issues.add(new Issue(msg, (Token)offendingSymbol));
	}
 
開發者ID:antlr,項目名稱:jetbrains-plugin-st4,代碼行數:27,代碼來源:LexerErrorListener.java

示例8: emit

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@Override
public Token emit() {
    if (_type == ID) {
        String firstChar = _input.getText(Interval.of(_tokenStartCharIndex, _tokenStartCharIndex));
        if (Grammar.isTokenName(firstChar)) {
            _type = TOKEN_REF;
        } else {
            _type = RULE_REF;
        }

        if (_ruleType == Token.INVALID_TYPE) {
            _ruleType = _type;
        }
    } else if (_type == SEMI) {
        _ruleType = Token.INVALID_TYPE;
    }

    return super.emit();
}
 
開發者ID:tunnelvisionlabs,項目名稱:goworks,代碼行數:20,代碼來源:GrammarLexer.java

示例9: updateVersionNumber

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
private void updateVersionNumber(TerminalNode currentVersionToken, final int newVersion) {
    Interval sourceInterval = ParseTrees.getSourceInterval(currentVersionToken);
    OffsetRegion region = OffsetRegion.fromBounds(sourceInterval.a, sourceInterval.b + 1);
    TrackingPositionRegion trackingRegion = _snapshot.createTrackingRegion(region, TrackingPositionRegion.Bias.Forward);
    final SnapshotPositionRegion currentRegion = trackingRegion.getRegion(_snapshot.getVersionedDocument().getCurrentSnapshot());
    final BaseDocument baseDocument = (BaseDocument)_snapshot.getVersionedDocument().getDocument();
    if (baseDocument == null) {
        throw new UnsupportedOperationException("No document available");
    }

    baseDocument.runAtomicAsUser(new Runnable() {

        @Override
        public void run() {
            try {
                baseDocument.remove(currentRegion.getStart().getOffset(), currentRegion.getLength());
                baseDocument.insertString(currentRegion.getStart().getOffset(), Integer.toString(newVersion), null);
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    });
}
 
開發者ID:tunnelvisionlabs,項目名稱:goworks,代碼行數:24,代碼來源:IncrementRuleVersionAction.java

示例10: findRuleForDescription

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@CheckForNull
@RuleDependency(recognizer=GrammarParser.class, rule=GrammarParser.RULE_parserRuleSpec, version=0, dependents=Dependents.SELF)
private static ParserRuleSpecContext findRuleForDescription(@NonNull Map<ParserRuleSpecContext, String> rules, @NonNull Description description) {
    for (Map.Entry<ParserRuleSpecContext, String> entry : rules.entrySet()) {
        if (!description.getName().equals(entry.getValue())) {
            continue;
        }

        Interval sourceInterval = ParseTrees.getSourceInterval(entry.getKey());
        if (sourceInterval.a <= description.getOffset() && sourceInterval.b >= description.getOffset()) {
            return entry.getKey();
        }
    }

    return null;
}
 
開發者ID:tunnelvisionlabs,項目名稱:goworks,代碼行數:17,代碼來源:IncrementRuleVersionAction.java

示例11: enterConstSpec

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@Override
@RuleDependencies({
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_constSpec, version=0),
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_identifierList, version=0),
})
public void enterConstSpec(ConstSpecContext ctx) {
    if (!isTopLevel(ctx)) {
        return;
    }

    IdentifierListContext idListContext = ctx.identifierList();
    List<? extends TerminalNode> identifiers = idListContext.IDENTIFIER();
    String type = ctx.type() != null ? String.format(" : <font color='808080'>%s</font>", HtmlSignatureVisitor.UNCOLORED.visit(ctx.type())) : "";
    for (TerminalNode identifier : identifiers) {
        Interval sourceInterval = new Interval(identifier.getSymbol().getStartIndex(), ParseTrees.getStopSymbol(ctx).getStopIndex());
        String name = identifier.getSymbol().getText();
        String signature = name + type;

        GoNode.DeclarationDescription description = new GoNode.DeclarationDescription(name, DeclarationKind.CONSTANT);
        description.setOffset(snapshot, getCurrentParent().getFileObject(), sourceInterval.a);
        description.setHtmlHeader(signature);
        getCurrentParent().getChildren().add(description);
    }
}
 
開發者ID:tunnelvisionlabs,項目名稱:goworks,代碼行數:25,代碼來源:GoDeclarationsScanner.java

示例12: enterShortVarDecl

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@Override
@RuleDependencies({
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_shortVarDecl, version=1),
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_identifierList, version=0),
})
public void enterShortVarDecl(ShortVarDeclContext ctx) {
    // no locals in navigator
    if (blockLevel > 0) {
        return;
    }

    IdentifierListContext idListContext = ctx.identifierList();
    List<? extends TerminalNode> identifiers = idListContext.IDENTIFIER();
    for (TerminalNode identifier : identifiers) {
        Interval sourceInterval = new Interval(identifier.getSymbol().getStartIndex(), ParseTrees.getStopSymbol(ctx).getStopIndex());
        String name = identifier.getSymbol().getText();
        String signature = name;

        GoNode.DeclarationDescription description = new GoNode.DeclarationDescription(name, DeclarationKind.VARIABLE);
        description.setOffset(snapshot, getCurrentParent().getFileObject(), sourceInterval.a);
        description.setHtmlHeader(String.format("%s", Description.htmlEscape(signature)));
        getCurrentParent().getChildren().add(description);
    }
}
 
開發者ID:tunnelvisionlabs,項目名稱:goworks,代碼行數:25,代碼來源:GoDeclarationsScanner.java

示例13: enterInterfaceType

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@Override
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_interfaceType, version=0)
public void enterInterfaceType(InterfaceTypeContext ctx) {
    if (isAnonymousType(ctx)) {
        return;
    }

    Interval sourceInterval = ParseTrees.getSourceInterval(ctx);
    String name = typeNameStack.isEmpty() ? "?interface?" : typeNameStack.peek();
    String signature = name;

    GoNode.DeclarationDescription description = new GoNode.DeclarationDescription(name, DeclarationKind.INTERFACE);
    description.setOffset(snapshot, getCurrentParent().getFileObject(), sourceInterval.a);
    description.setHtmlHeader(String.format("%s", signature));
    getCurrentParent().getChildren().add(description);
    descriptionStack.push(description);
}
 
開發者ID:tunnelvisionlabs,項目名稱:goworks,代碼行數:18,代碼來源:GoDeclarationsScanner.java

示例14: enterStructType

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@Override
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_structType, version=0)
public void enterStructType(StructTypeContext ctx) {
    if (isAnonymousType(ctx)) {
        return;
    }

    Interval sourceInterval = ParseTrees.getSourceInterval(ctx);
    String name = typeNameStack.isEmpty() ? "?struct?" : typeNameStack.peek();
    String signature = name;

    GoNode.DeclarationDescription description = new GoNode.DeclarationDescription(name, DeclarationKind.STRUCT);
    description.setOffset(snapshot, getCurrentParent().getFileObject(), sourceInterval.a);
    description.setHtmlHeader(String.format("%s", signature));
    getCurrentParent().getChildren().add(description);
    descriptionStack.push(description);
}
 
開發者ID:tunnelvisionlabs,項目名稱:goworks,代碼行數:18,代碼來源:GoDeclarationsScanner.java

示例15: enterMethodDecl

import org.antlr.v4.runtime.misc.Interval; //導入依賴的package包/類
@Override
@RuleDependencies({
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_methodDecl, version=0),
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_methodName, version=0),
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_receiver, version=0),
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_baseTypeName, version=0),
})
public void enterMethodDecl(MethodDeclContext ctx) {
    Interval sourceInterval = ParseTrees.getSourceInterval(ctx);
    String name = ctx.methodName() != null && ctx.methodName().IDENTIFIER() != null ? ctx.methodName().IDENTIFIER().getSymbol().getText() : "?";
    String signature = HtmlSignatureVisitor.COLORED.visit(ctx);

    GoNode.DeclarationDescription description = new GoNode.DeclarationDescription(name, DeclarationKind.METHOD);
    description.setOffset(snapshot, getCurrentParent().getFileObject(), sourceInterval.a);
    description.setHtmlHeader(signature);
    getCurrentParent().getChildren().add(description);

    ReceiverContext receiverContext = ctx.receiver();
    BaseTypeNameContext baseTypeNameContext = receiverContext != null ? receiverContext.baseTypeName() : null;
    if (baseTypeNameContext != null && baseTypeNameContext.IDENTIFIER() != null) {
        String receiverTypeName = baseTypeNameContext.IDENTIFIER().getText();
        _methodDescriptions.add(Tuple.create(receiverTypeName, getCurrentParent(), description));
    }

    descriptionStack.push(description);
}
 
開發者ID:tunnelvisionlabs,項目名稱:goworks,代碼行數:27,代碼來源:GoDeclarationsScanner.java


注:本文中的org.antlr.v4.runtime.misc.Interval類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。