Search in sources :

Example 96 with RecognitionException

use of antlr.RecognitionException in project groovy-core by groovy.

the class ClassicGroovyTestGeneratorHelper method parse.

/** run the JSR parser implementation over the supplied source text*/
public void parse(String theSrcText, String testName) throws Exception {
    System.out.println("-------------------------------");
    System.out.println("  " + testName);
    System.out.println("-------------------------------");
    try {
        Reader reader = new BufferedReader(new StringReader(theSrcText));
        GroovyRecognizer recognizer = GroovyRecognizer.make(reader);
        recognizer.compilationUnit();
        System.out.println(decorateWithLineNumbers(theSrcText));
    } catch (RecognitionException parseException) {
        System.out.println(decorateWithLineNumbersAndErrorMessage(theSrcText, parseException));
        throw parseException;
    }
    System.out.println("-------------------------------");
}
Also used : BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) GroovyRecognizer(org.codehaus.groovy.antlr.parser.GroovyRecognizer) RecognitionException(antlr.RecognitionException)

Example 97 with RecognitionException

use of antlr.RecognitionException in project checkstyle by checkstyle.

the class AstTreeStringPrinter method parseFileText.

/**
     * Parse a text and return the parse tree.
     * @param text the text to parse.
     * @param withComments true to include comment nodes to the tree
     * @return the root node of the parse tree.
     * @throws CheckstyleException if the file is not a Java source.
     */
private static DetailAST parseFileText(FileText text, boolean withComments) throws CheckstyleException {
    final FileContents contents = new FileContents(text);
    final DetailAST result;
    try {
        if (withComments) {
            result = TreeWalker.parseWithComments(contents);
        } else {
            result = TreeWalker.parse(contents);
        }
    } catch (RecognitionException | TokenStreamException ex) {
        final String exceptionMsg = String.format(Locale.ROOT, "%s occurred during the analysis of file %s.", ex.getClass().getSimpleName(), text.getFile().getPath());
        throw new CheckstyleException(exceptionMsg, ex);
    }
    return result;
}
Also used : TokenStreamException(antlr.TokenStreamException) FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) RecognitionException(antlr.RecognitionException)

Example 98 with RecognitionException

use of antlr.RecognitionException in project querydsl by querydsl.

the class IntegrationBase method query.

@Override
protected QueryHelper<?> query() {
    return new QueryHelper<Void>(HQLTemplates.DEFAULT) {

        @Override
        public void parse() throws RecognitionException, TokenStreamException {
            try {
                System.out.println("query : " + toString().replace('\n', ' '));
                JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
                serializer.serialize(getMetadata(), false, null);
                Query query = session.createQuery(serializer.toString());
                HibernateUtil.setConstants(query, serializer.getConstantToLabel(), getMetadata().getParams());
                query.list();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            } finally {
                System.out.println();
            }
        }
    };
}
Also used : HibernateQuery(com.querydsl.jpa.hibernate.HibernateQuery) Query(org.hibernate.Query) RecognitionException(antlr.RecognitionException) TokenStreamException(antlr.TokenStreamException)

Example 99 with RecognitionException

use of antlr.RecognitionException in project cxf by apache.

the class IDLParser method attr_spec.

public final void attr_spec() throws RecognitionException, TokenStreamException {
    returnAST = null;
    ASTPair currentAST = new ASTPair();
    AST attr_spec_AST = null;
    try {
        // for error handling
        AST tmp165_AST = null;
        tmp165_AST = astFactory.create(LT(1));
        astFactory.makeASTRoot(currentAST, tmp165_AST);
        match(LITERAL_attribute);
        param_type_spec();
        astFactory.addASTChild(currentAST, returnAST);
        attr_declarator();
        astFactory.addASTChild(currentAST, returnAST);
        attr_spec_AST = (AST) currentAST.root;
    } catch (RecognitionException ex) {
        if (inputState.guessing == 0) {
            reportError(ex);
            consume();
            consumeUntil(_tokenSet_10);
        } else {
            throw ex;
        }
    }
    returnAST = attr_spec_AST;
}
Also used : ASTPair(antlr.ASTPair) AST(antlr.collections.AST) RecognitionException(antlr.RecognitionException)

Example 100 with RecognitionException

use of antlr.RecognitionException in project cxf by apache.

the class IDLParser method base_type_spec.

public final void base_type_spec() throws RecognitionException, TokenStreamException {
    returnAST = null;
    ASTPair currentAST = new ASTPair();
    AST base_type_spec_AST = null;
    try {
        // for error handling
        switch(LA(1)) {
            case LITERAL_char:
                {
                    char_type();
                    astFactory.addASTChild(currentAST, returnAST);
                    base_type_spec_AST = (AST) currentAST.root;
                    break;
                }
            case LITERAL_wchar:
                {
                    wide_char_type();
                    astFactory.addASTChild(currentAST, returnAST);
                    base_type_spec_AST = (AST) currentAST.root;
                    break;
                }
            case LITERAL_boolean:
                {
                    boolean_type();
                    astFactory.addASTChild(currentAST, returnAST);
                    base_type_spec_AST = (AST) currentAST.root;
                    break;
                }
            case LITERAL_octet:
                {
                    octet_type();
                    astFactory.addASTChild(currentAST, returnAST);
                    base_type_spec_AST = (AST) currentAST.root;
                    break;
                }
            case LITERAL_any:
                {
                    any_type();
                    astFactory.addASTChild(currentAST, returnAST);
                    base_type_spec_AST = (AST) currentAST.root;
                    break;
                }
            case LITERAL_Object:
                {
                    object_type();
                    astFactory.addASTChild(currentAST, returnAST);
                    base_type_spec_AST = (AST) currentAST.root;
                    break;
                }
            case LITERAL_ValueBase:
                {
                    value_base_type();
                    astFactory.addASTChild(currentAST, returnAST);
                    base_type_spec_AST = (AST) currentAST.root;
                    break;
                }
            default:
                boolean synPredMatched122 = false;
                if ((((LA(1) >= LITERAL_float && LA(1) <= LITERAL_long)) && (_tokenSet_45.member(LA(2))) && (_tokenSet_46.member(LA(3))) && (_tokenSet_47.member(LA(4))))) {
                    int _m122 = mark();
                    synPredMatched122 = true;
                    inputState.guessing++;
                    try {
                        {
                            floating_pt_type();
                        }
                    } catch (RecognitionException pe) {
                        synPredMatched122 = false;
                    }
                    rewind(_m122);
                    inputState.guessing--;
                }
                if (synPredMatched122) {
                    floating_pt_type();
                    astFactory.addASTChild(currentAST, returnAST);
                    base_type_spec_AST = (AST) currentAST.root;
                } else if (((LA(1) >= LITERAL_long && LA(1) <= LITERAL_unsigned)) && (_tokenSet_48.member(LA(2))) && (_tokenSet_49.member(LA(3))) && (_tokenSet_47.member(LA(4)))) {
                    integer_type();
                    astFactory.addASTChild(currentAST, returnAST);
                    base_type_spec_AST = (AST) currentAST.root;
                } else {
                    throw new NoViableAltException(LT(1), getFilename());
                }
        }
    } catch (RecognitionException ex) {
        if (inputState.guessing == 0) {
            reportError(ex);
            consume();
            consumeUntil(_tokenSet_36);
        } else {
            throw ex;
        }
    }
    returnAST = base_type_spec_AST;
}
Also used : ASTPair(antlr.ASTPair) AST(antlr.collections.AST) NoViableAltException(antlr.NoViableAltException) RecognitionException(antlr.RecognitionException)

Aggregations

RecognitionException (antlr.RecognitionException)170 AST (antlr.collections.AST)155 ASTPair (antlr.ASTPair)154 NoViableAltException (antlr.NoViableAltException)68 TokenStreamException (antlr.TokenStreamException)10 GroovyRecognizer (org.codehaus.groovy.antlr.parser.GroovyRecognizer)6 TokenStreamRecognitionException (antlr.TokenStreamRecognitionException)5 StringReader (java.io.StringReader)4 GroovyLexer (org.codehaus.groovy.antlr.parser.GroovyLexer)4 Token (antlr.Token)3 CharStreamException (antlr.CharStreamException)2 CharStreamIOException (antlr.CharStreamIOException)2 CommonToken (antlr.CommonToken)2 NoViableAltForCharException (antlr.NoViableAltForCharException)2 TokenStreamIOException (antlr.TokenStreamIOException)2 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)2 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)2 FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)2 IncorrectTypeHintException (groovy.transform.stc.IncorrectTypeHintException)2 BufferedReader (java.io.BufferedReader)2