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


Java Parser类代码示例

本文整理汇总了Java中org.antlr.runtime.Parser的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: syntaxError

import org.antlr.runtime.Parser; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void syntaxError(BaseRecognizer recognizer, String[] tokenNames, RecognitionException e)
{
    String hdr = recognizer.getErrorHeader(e);
    String msg = recognizer.getErrorMessage(e, tokenNames);

    StringBuilder builder = new StringBuilder().append(hdr)
            .append(' ')
            .append(msg);

    if (recognizer instanceof Parser)
        appendQuerySnippet((Parser) recognizer, builder);

    errorMsgs.add(builder.toString());
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:19,代码来源:ErrorCollector.java

示例2: createParser

import org.antlr.runtime.Parser; //导入依赖的package包/类
/** Creates a parser for a given term, generating trees of this kind. */
public <P extends Parser> P createParser(Class<P> parserType, I info, String term) {
    try {
        // find the lexer type
        String parserName = parserType.getName();
        String lexerName = parserName.substring(0, parserName.indexOf("Parser"))
            .concat("Lexer");
        @SuppressWarnings("unchecked") Class<? extends Lexer> lexerType =
            (Class<? extends Lexer>) Class.forName(lexerName);
        Lexer lexer = createLexer(lexerType, info, term);
        // instantiate the parser
        CommonTokenStream tokenStream = new CommonTokenStream(lexer);
        Constructor<P> parserConstructor = parserType.getConstructor(TokenStream.class);
        P result = parserConstructor.newInstance(tokenStream);
        Method adaptorSetter = parserType.getMethod("setTreeAdaptor", TreeAdaptor.class);
        adaptorSetter.invoke(result, new ParseTreeAdaptor<>(this, info, tokenStream));
        callInitialise(result, info);
        return result;
    } catch (Exception e) {
        throw toRuntime(e);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:23,代码来源:ParseTree.java

示例3: appendQuerySnippet

import org.antlr.runtime.Parser; //导入依赖的package包/类
/**
 * Appends a query snippet to the message to help the user to understand the problem.
 *
 * @param parser the parser used to parse the query
 * @param builder the <code>StringBuilder</code> used to build the error message
 */
private void appendQuerySnippet(Parser parser, StringBuilder builder)
{
    TokenStream tokenStream = parser.getTokenStream();
    int index = tokenStream.index();
    int size = tokenStream.size();

    Token from = tokenStream.get(getSnippetFirstTokenIndex(index));
    Token to = tokenStream.get(getSnippetLastTokenIndex(index, size));
    Token offending = tokenStream.get(getOffendingTokenIndex(index, size));

    appendSnippet(builder, from, to, offending);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:19,代码来源:ErrorCollector.java

示例4: getParserErrorMessage

import org.antlr.runtime.Parser; //导入依赖的package包/类
public String getParserErrorMessage(Parser parser, RecognitionException e) {
	String msg;
	if ( e instanceof NoViableAltException) {
		String name = parser.getTokenErrorDisplay(e.token);
		msg = name+" came as a complete surprise to me";
	}
	else if ( e instanceof v4ParserException) {
		msg = ((v4ParserException)e).msg;
	}
	else {
		msg = parser.getErrorMessage(e, parser.getTokenNames());
	}
	return msg;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:15,代码来源:ToolANTLRParser.java

示例5: buildKeywordEscapeIdentifier

import org.antlr.runtime.Parser; //导入依赖的package包/类
public Object buildKeywordEscapeIdentifier(Parser parser, TreeAdaptor adaptor, Object tree) {
	CommonTree ct = (CommonTree)tree;
	String txt = ct.getText();
	if (txt == null) {
		CommonToken leftToken = (CommonToken) parser.getTokenStream().get(ct.getTokenStartIndex());
		CommonToken rightToken = (CommonToken) parser.getTokenStream().get(ct.getTokenStopIndex());
		txt = leftToken.getInputStream().substring(leftToken.getStartIndex(), rightToken.getStopIndex());
	}

	return adaptor.create(TokenTypes.Regular_Identifier, ct.getToken(), /*ct.getText()*/txt);
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:12,代码来源:Utils.java

示例6: execParser

import org.antlr.runtime.Parser; //导入依赖的package包/类
public Object execParser(
    String ruleName,
    String input,
    int scriptLine)
    throws Exception
{
    ANTLRStringStream is = new ANTLRStringStream(input);
    Class<? extends TokenSource> lexerClass = Class.forName(lexerClassName).asSubclass(TokenSource.class);
    Constructor<? extends TokenSource> lexConstructor = lexerClass.getConstructor(CharStream.class);
    TokenSource lexer = lexConstructor.newInstance(is);
    is.setLine(scriptLine);

    CommonTokenStream tokens = new CommonTokenStream(lexer);

    Class<? extends Parser> parserClass = Class.forName(parserClassName).asSubclass(Parser.class);
    Constructor<? extends Parser> parConstructor = parserClass.getConstructor(TokenStream.class);
    Parser parser = parConstructor.newInstance(tokens);

    // set up customized tree adaptor if necessary
    if ( adaptorClassName!=null ) {
        Method m = parserClass.getMethod("setTreeAdaptor", TreeAdaptor.class);
        Class<? extends TreeAdaptor> adaptorClass = Class.forName(adaptorClassName).asSubclass(TreeAdaptor.class);
        m.invoke(parser, adaptorClass.newInstance());
    }

    Method ruleMethod = parserClass.getMethod(ruleName);

    // INVOKE RULE
    return ruleMethod.invoke(parser);
}
 
开发者ID:danishdynamite,项目名称:templates4j,代码行数:31,代码来源:gUnitBase.java

示例7: getDelegates

import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates() {
	return new Parser[] {};
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:4,代码来源:Cql_Parser.java

示例8: getDelegates

import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates() {
	return new Parser[] {gParser};
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:4,代码来源:CqlParser.java

示例9: getDelegates

import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates() {
    return new Parser[] {};
}
 
开发者ID:jruesga,项目名称:rview,代码行数:4,代码来源:QueryParser.java

示例10: getDelegates

import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates()
{
  return new Parser[] {};
}
 
开发者ID:iisi-nj,项目名称:GemFireLite,代码行数:5,代码来源:SybaseSQLParser.java

示例11: buildIdentifier

import org.antlr.runtime.Parser; //导入依赖的package包/类
public Object buildIdentifier(Parser parser, TreeAdaptor adaptor, String text) {
	return adaptor.create(TokenTypes.Regular_Identifier, text);
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:4,代码来源:Utils.java

示例12: extractLine

import org.antlr.runtime.Parser; //导入依赖的package包/类
public String extractLine(Parser parser, RecognitionException e) {
	return extractLine(parser.getTokenStream(), e);
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:4,代码来源:Utils.java

示例13: CLParserHelper

import org.antlr.runtime.Parser; //导入依赖的package包/类
public CLParserHelper(Parser parser) {

        this.parser = parser;
        clObject = new CLObject();
    }
 
开发者ID:asupdev,项目名称:asup,代码行数:6,代码来源:CLParserHelper.java

示例14: getDelegates

import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates() {
  return new Parser[] {};
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:4,代码来源:FastSimpleGenericEdifactDirectXMLParser.java


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