Java Code Examples for org.antlr.v4.Tool#addListener()
The following examples show how to use
org.antlr.v4.Tool#addListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParsingUtils.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Tool createANTLRToolForLoadingGrammars() { Tool antlr = new Tool(); antlr.errMgr = new PluginIgnoreMissingTokensFileErrorManager(antlr); antlr.errMgr.setFormat("antlr"); LoadGrammarsToolListener listener = new LoadGrammarsToolListener(antlr); antlr.removeListeners(); antlr.addListener(listener); return antlr; }
Example 2
Source File: Antlr4ToolFacade.java From openCypher with Apache License 2.0 | 4 votes |
public static void assertGeneratesValidParser( String resource ) throws Exception { Output.Readable buffer = stringBuilder(); Tool antlr = new Tool(); Antlr4ToolFacade facade = new Antlr4ToolFacade( antlr, buffer ); try { Antlr4.write( Fixture.grammarResource( Antlr4.class, resource ), buffer ); } catch ( Throwable e ) { try { facade.reportFailureIn( "generating grammar" ); } catch ( AssertionError x ) { throw e; } } antlr.addListener( facade ); GrammarRootAST ast = antlr.parse( resource, new ANTLRReaderStream( buffer.reader() ) ); if ( ast.hasErrors ) { RuleAST lastGood = lastGoodRule( ast ); if ( lastGood == null ) { facade.reportFailureIn( "parsing grammar" ); } else { facade.reportFailureIn( "parsing grammar, after " + lastGood.getRuleName() + " on line " + lastGood.getLine() ); } } antlr.process( antlr.createGrammar( ast ), false ); if ( facade.hasErrors() ) { facade.reportFailureIn( "processing grammar" ); } }