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("-------------------------------");
}
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;
}
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();
}
}
};
}
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;
}
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;
}
Aggregations