24 package org.lightjason.agentspeak.grammar;
26 import org.antlr.v4.runtime.ANTLRErrorListener;
27 import org.antlr.v4.runtime.CharStream;
28 import org.antlr.v4.runtime.CharStreams;
29 import org.antlr.v4.runtime.CommonTokenStream;
30 import org.antlr.v4.runtime.Lexer;
31 import org.antlr.v4.runtime.Parser;
32 import org.antlr.v4.runtime.TokenStream;
34 import javax.annotation.Nonnull;
35 import java.io.IOException;
36 import java.io.InputStream;
37 import java.lang.reflect.Constructor;
38 import java.lang.reflect.InvocationTargetException;
66 protected IBaseParser( @Nonnull
final ANTLRErrorListener p_errorlistener )
throws NoSuchMethodException
68 m_errorlistener = p_errorlistener;
69 m_ctorlexer = this.
lexerclass().getConstructor( CharStream.class );
70 m_ctorparser = this.
parserclass().getConstructor( TokenStream.class );
84 protected final P
parser( @Nonnull
final InputStream p_stream )
throws IOException, IllegalAccessException, InvocationTargetException, InstantiationException
86 final L l_lexer = m_ctorlexer.newInstance( CharStreams.fromStream( p_stream ) );
87 l_lexer.removeErrorListeners();
88 l_lexer.addErrorListener( m_errorlistener );
90 final P l_parser = m_ctorparser.newInstance(
new CommonTokenStream( l_lexer ) );
91 l_parser.removeErrorListeners();
92 l_parser.addErrorListener( m_errorlistener );
abstract Class< P > parserclass()
returns the parser class reference
interface for any AST visitor
final Constructor< L > m_ctorlexer
ctor lexer reference
final Constructor< P > m_ctorparser
ctor parser reference
IBaseParser( @Nonnull final ANTLRErrorListener p_errorlistener)
ctor
final P parser( @Nonnull final InputStream p_stream)
returns a parser component
final ANTLRErrorListener m_errorlistener
error listener
abstract Class< L > lexerclass()
returns the lexer class reference