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


Java TokenStream.getText方法代码示例

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


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

示例1: dot

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

示例2: reportNoViableAlternative

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {
  TokenStream tokens = recognizer.getInputStream();
  String input;
  if (tokens != null) {
    if (e.getStartToken().getType() == -1) {
      input = "<EOF>";
    } else {
      input = tokens.getText(e.getStartToken(), e.getOffendingToken());
    }
  } else {
    input = "<unknown input>";
  }

  String msg = "no viable alternative at input " + this.escapeWSAndQuote(input);
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:17,代码来源:KsqlParserErrorStrategy.java

示例3: syntaxError

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
@Override
public final void syntaxError(final Recognizer<?, ?> recognizer,
    final Object offendingSymbol, final int line,
    final int charPositionInLine, final String msg,
    final RecognitionException e) {
  String input;
  if (recognizer instanceof Lexer) {
    final CharStream cs = ((Lexer) recognizer).getInputStream();
    input = cs.getText(new Interval(0, cs.size()));
  } else if (recognizer instanceof Parser) {
    final TokenStream tokens = ((Parser) recognizer).getInputStream();
    if (tokens != null) {
      input = tokens.getText();
    } else {
      input = "<unknown input>";
    }
  } else {
    input = "<unknown input>";
  }
  throw new AntlrParseException(input, line, charPositionInLine, msg);
}
 
开发者ID:Haixing-Hu,项目名称:criteria,代码行数:22,代码来源:ThrowExceptionErrorListener.java

示例4: isBinaryOp

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
/**
 "If an operator has whitespace around both sides or around neither side,
 it is treated as a binary operator. As an example, the + operator in a+b
 and a + b is treated as a binary operator."
 */
public static boolean isBinaryOp(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 && !nextIsWS);
	String text = tokens.getText(Interval.of(start, stop));
	//System.out.println("isBinaryOp: '"+prevToken+"','"+text+"','"+nextToken+"' is "+result);
	return result;
}
 
开发者ID:marcelganczak,项目名称:ts-swift-transpiler,代码行数:20,代码来源:SwiftSupport.java

示例5: isPrefixOp

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
/**
 "If an operator has whitespace on the left side only, it is treated as a
 prefix unary operator. As an example, the ++ operator in a ++b is treated
 as a prefix unary operator."
*/
public static boolean isPrefixOp(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;
	String text = tokens.getText(Interval.of(start, stop));
	//System.out.println("isPrefixOp: '"+prevToken+"','"+text+"','"+nextToken+"' is "+result);
	return result;
}
 
开发者ID:marcelganczak,项目名称:ts-swift-transpiler,代码行数:20,代码来源:SwiftSupport.java

示例6: isOperator

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
public static boolean isOperator(TokenStream tokens, String op) {
	int stop = getLastOpTokenIndex(tokens);
	if ( stop==-1 ) return false;

	int start = tokens.index();
	String text = tokens.getText(Interval.of(start, stop));
	return text.equals(op);
}
 
开发者ID:marcelganczak,项目名称:ts-swift-transpiler,代码行数:9,代码来源:SwiftSupport.java

示例7: enterMethodDeclaration

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
/** Listen to matches of methodDeclaration */
@Override
public void enterMethodDeclaration(
    JavaParser.MethodDeclarationContext ctx
)
{
    // need parser to get tokens
    TokenStream tokens = parser.getTokenStream();
    String type = "void";
    if ( ctx.type()!=null ) {
        type = tokens.getText(ctx.type());
    }
    String args = tokens.getText(ctx.formalParameters());
    System.out.println("\t"+type+" "+ctx.Identifier()+args+";");
}
 
开发者ID:mwqdream,项目名称:antlrgroup,代码行数:16,代码来源:ExtractInterfaceListener.java

示例8: noViableAlt

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
public static String noViableAlt(Parser recognizer, NoViableAltException e) {
    TokenStream tokens = recognizer.getInputStream();
    String input = null;
    if (tokens != null) {
        Token startToken = e.getStartToken();
        if (startToken.getType() == Token.EOF) {
            input = "<EOF>";
        } else {
            input = tokens.getText(
                    startToken, e.getOffendingToken()
            );
        }
    }
    return "syntax error at input:" + input;
}
 
开发者ID:kasonyang,项目名称:kalang,代码行数:16,代码来源:AntlrErrorString.java

示例9: isOperator

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
public static boolean isOperator(TokenStream tokens, String op) {
    int stop = getLastOpTokenIndex(tokens);
    if (stop == -1) return false;

    int start = tokens.index();
    String text = tokens.getText(Interval.of(start, stop));
    return text.equals(op);
}
 
开发者ID:alexsaveliev,项目名称:srclib-basic,代码行数:9,代码来源:SwiftSupport.java

示例10: enterAliasRule

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
@Override
public void enterAliasRule(AliasRuleContext ctx) {
       TokenStream tokens = parser.getTokenStream();
       String newName = null;
       if ( ctx.name()!=null && mapping.getDestination() != null) {
       	newName = tokens.getText(ctx.name());
           mapping.getDestination().setName(newName);
       }
}
 
开发者ID:cqframework,项目名称:ProfileGenerator,代码行数:10,代码来源:MappingAnnotationListener.java

示例11: enterCardinality

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
@Override
public void enterCardinality(CardinalityContext ctx) {
	TokenStream tokens = parser.getTokenStream();
       String low = null;
       String high = null;
       if ( ctx.INTEGER()!=null && mapping.getDestination() != null) {
       	low = ctx.INTEGER().getText();
       	mapping.getDestination().setLow(Integer.valueOf(low));
       }
       if ( ctx.high()!=null && mapping.getDestination() != null) {
       	high = tokens.getText(ctx.high());
       	high = (high.equals("*"))?"-1":high;
       	mapping.getDestination().setHigh(Integer.valueOf(high));
       }
}
 
开发者ID:cqframework,项目名称:ProfileGenerator,代码行数:16,代码来源:MappingAnnotationListener.java

示例12: reportNoViableAlternative

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e)
{
	TokenStream tokens = recognizer.getInputStream();
	String input;
	if (tokens instanceof TokenStream)
	{
		if (e.getStartToken().getType() == Token.EOF)
			input = "<文件尾>";
		else
			input = tokens.getText(e.getStartToken(), e.getOffendingToken());
	}
	else
	{
		input = "<未知输入>";
	}
	BeetlException exception = null;
	if(keys.contains(e.getOffendingToken().getText())){
		 exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR,
					"不允许"+e.getOffendingToken().getText()+"关键出现在这里"+":"+escapeWSAndQuote(input), e);
	}else{
		exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR,
				escapeWSAndQuote(input), e);
	}
	//		String msg = "no viable alternative at input " + escapeWSAndQuote(input);

	exception.pushToken(this.getGrammarToken(e.getOffendingToken()));

	throw exception;
}
 
开发者ID:javamonkey,项目名称:beetl2.0,代码行数:30,代码来源:BeetlAntlrErrorStrategy.java

示例13: printCurrentToken

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
private void printCurrentToken(String flag,  ParserRuleContext ctx) {

        if (logger.isDebugEnabled()) {
            TokenStream tokens = parser.getTokenStream(); // need parser to get tokens
            String text = tokens.getText(ctx);
            logger.debug(flag + ":" + getTokenText(ctx));
        }
    }
 
开发者ID:kiegroup,项目名称:jbpm-data-modeler,代码行数:9,代码来源:DataObjectListener.java

示例14: popupAmbigTreesDialog

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
public static void popupAmbigTreesDialog(PreviewState previewState, AmbiguityInfo ambigInfo) {
	// pop up subtrees for ambig intrepretation
	ShowAmbigTreesDialog dialog = new ShowAmbigTreesDialog();
	Parser parser = previewState.parsingResult.parser;
	int startRuleIndex = parser.getRuleIndex(previewState.startRuleName);
	List<ParserRuleContext> ambiguousParseTrees = null;
	try {
		ambiguousParseTrees =
			GrammarParserInterpreter.getAllPossibleParseTrees(previewState.g,
			                                                  parser,
			                                                  parser.getTokenStream(),
			                                                  ambigInfo.decision,
			                                                  ambigInfo.ambigAlts,
			                                                  ambigInfo.startIndex,
			                                                  ambigInfo.stopIndex,
			                                                  startRuleIndex);
	} catch (ParseCancellationException pce) {
		// 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 ambiguous trees while there are syntax errors in your input."));
		dialog.treeScrollPane.setViewportView(errPanel);
	}

	if ( ambiguousParseTrees!=null ) {
		TokenStream tokens = previewState.parsingResult.parser.getInputStream();
		String phrase = tokens.getText(Interval.of(ambigInfo.startIndex, ambigInfo.stopIndex));
		if ( phrase.length()>MAX_PHRASE_WIDTH ) {
			phrase = phrase.substring(0, MAX_PHRASE_WIDTH)+"...";
		}
		String title = ambiguousParseTrees.size()+
			" Interpretations of Ambiguous Input Phrase: "+
			phrase;
		dialog.ambigPhraseLabel.setText(title);
		dialog.setTrees(previewState, ambiguousParseTrees, title, 0,
		                ambigInfo.startIndex, ambigInfo.stopIndex, true);
	}

	dialog.pack();
	dialog.setVisible(true);
}
 
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:42,代码来源:ShowAmbigTreesDialog.java

示例15: getTokenText

import org.antlr.v4.runtime.TokenStream; //导入方法依赖的package包/类
private String getTokenText(ParserRuleContext ctx) {
    TokenStream tokens = parser.getTokenStream(); // need parser to get tokens
    return tokens.getText(ctx);
}
 
开发者ID:kiegroup,项目名称:jbpm-data-modeler,代码行数:5,代码来源:DataObjectListener.java


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