Java 类org.antlr.runtime.Parser 实例源码

项目:sstable-adaptor    文件:ErrorCollector.java   
/**
 * {@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());
}
项目:JavaGraph    文件:ParseTree.java   
/** 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);
    }
}
项目:cassandra-kmean    文件:ErrorCollector.java   
/**
 * {@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());
}
项目:scylla-tools-java    文件:ErrorCollector.java   
/**
 * {@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());
}
项目:GraphTrek    文件:ErrorCollector.java   
/**
 * {@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());
}
项目:stratio-cassandra    文件:ErrorCollector.java   
/**
 * {@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());
}
项目:sstable-adaptor    文件:ErrorCollector.java   
/**
 * 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);
}
项目:codebuff    文件:ToolANTLRParser.java   
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;
}
项目:cassandra-kmean    文件:ErrorCollector.java   
/**
 * 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);
}
项目:scylla-tools-java    文件:ErrorCollector.java   
/**
 * 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);
}
项目:GraphTrek    文件:ErrorCollector.java   
/**
 * 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);
}
项目:stratio-cassandra    文件:ErrorCollector.java   
/**
 * 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);
}
项目:tesora-dve-pub    文件:Utils.java   
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);
}
项目:templates4j    文件:gUnitBase.java   
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);
}
项目:sstable-adaptor    文件:Cql_Parser.java   
public Parser[] getDelegates() {
    return new Parser[] {};
}
项目:sstable-adaptor    文件:CqlParser.java   
public Parser[] getDelegates() {
    return new Parser[] {gParser};
}
项目:rview    文件:QueryParser.java   
public Parser[] getDelegates() {
    return new Parser[] {};
}
项目:GemFireLite    文件:OracleSQLParser.java   
public Parser[] getDelegates() {
    return new Parser[] {};
}
项目:GemFireLite    文件:SybaseSQLParser.java   
public Parser[] getDelegates()
{
  return new Parser[] {};
}
项目:GemFireLite    文件:CreateIndexParser.java   
public Parser[] getDelegates() {
    return new Parser[] {};
}
项目:pm    文件:ParameterizedIndicatorsParser.java   
public Parser[] getDelegates() {
    return new Parser[] {};
}
项目:pm    文件:ParameterizedOperationsParser.java   
public Parser[] getDelegates() {
    return new Parser[] {};
}
项目:hexa.tools    文件:hqlParser.java   
public Parser[] getDelegates() {
    return new Parser[] {};
}
项目:tesora-dve-pub    文件:Utils.java   
public Object buildIdentifier(Parser parser, TreeAdaptor adaptor, String text) {
    return adaptor.create(TokenTypes.Regular_Identifier, text);
}
项目:tesora-dve-pub    文件:Utils.java   
public String extractLine(Parser parser, RecognitionException e) {
    return extractLine(parser.getTokenStream(), e);
}
项目:asup    文件:CLParserHelper.java   
public CLParserHelper(Parser parser) {

        this.parser = parser;
        clObject = new CLObject();
    }
项目:pentaho-kettle    文件:FastSimpleGenericEdifactDirectXMLParser.java   
public Parser[] getDelegates() {
  return new Parser[] {};
}