Class CSTTransformer<T extends JobParameters>
java.lang.Object
io.github.douira.glsl_transformer.cst.transform.ExecutionPlanner<T>
io.github.douira.glsl_transformer.cst.transform.CSTTransformer<T>
- Type Parameters:
T- The job parameters type
- All Implemented Interfaces:
ParserInterface,Transformer<String>,ParameterHolder<T>,ParameterizedTransformer<T,String>
public class CSTTransformer<T extends JobParameters>
extends ExecutionPlanner<T>
implements ParameterizedTransformer<T,String>, ParserInterface
Implements the execution planner by providing the boilerplate code for
setting
up an input, a lexer and a parser.
The CST transformer (formerly called the transformation manager) is meant to
be used to transform many strings and be re-used for many transformation jobs
of the same kind. For entirely different jobs a new manager should be
created. Common transformations can be shared between them.
For printing a tree without transforming it, a manager without and
transformations can be used.
Creating manager instances isn't costly as ANTLR's parser and lexer
instantiation is efficient.
The transformation manager also manages job parameters. It has a private
field that it stores the job parameters, that are passed to it along with the
string to be transformed, during transformation. This means that the entire
chain of objects that are involved in the transformation have to be generic
in order to be able to make use of job parameters. If no job parameter is
used the
Void type can be used and object constructors can
use the default parameter <> which assigns an
Object. This is fine as long as the anonymous class being
constructed doesn't need to use the job parameters. If it does need to use
them, the whole chain of participating objects needs to be properly
parameterized. (transformation manager -> transformation -> transformation
phase)-
Constructor Summary
ConstructorsConstructorDescriptionCSTTransformer(Transformation<T> rootTransformation) Creates a new transformation manager with a given root transformation. -
Method Summary
Modifier and TypeMethodDescriptionio.github.douira.glsl_transformer.GLSLLexergetLexer()Returns the execution planner's lexer.io.github.douira.glsl_transformer.GLSLParserReturns this execution planner's parser.TokenFilter<?>protected BufferedTokenStreamprotected io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContextvoidvoidsetParseTokenFilter(TokenFilter<?> parseTokenFilter) voidsetParsingStrategy(EnhancedParser.ParsingStrategy parsingStrategy) voidsetPrintTokenFilter(TokenFilter<T> printTokenFilter) Sets the token filter to use before printing.voidvoidsetThrowParseErrors(boolean throwParseErrors) Methods inherited from class io.github.douira.glsl_transformer.cst.transform.ExecutionPlanner
addConcurrent, getJobParameters, getRootNode, getRootTransformation, planExecutionFor, setJobParameters, setRootTransformation, transformTree, withJobParametersMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.douira.glsl_transformer.job_parameter.ParameterHolder
getJobParameters, setJobParameters, withJobParametersMethods inherited from interface io.github.douira.glsl_transformer.job_parameter.ParameterizedTransformer
transform
-
Constructor Details
-
CSTTransformer
Creates a new transformation manager with a given root transformation. Throws parse errors by default.- Parameters:
rootTransformation- The root transformation to use
-
CSTTransformer
public CSTTransformer()
-
-
Method Details
-
getLexer
public io.github.douira.glsl_transformer.GLSLLexer getLexer()Description copied from class:ExecutionPlannerReturns the execution planner's lexer.- Specified by:
getLexerin interfaceParserInterface- Specified by:
getLexerin classExecutionPlanner<T extends JobParameters>- Returns:
- The lexer
-
getParser
public io.github.douira.glsl_transformer.GLSLParser getParser()Description copied from class:ExecutionPlannerReturns this execution planner's parser. How the parser is stored is up to the implementing class.- Specified by:
getParserin interfaceParserInterface- Specified by:
getParserin classExecutionPlanner<T extends JobParameters>- Returns:
- The parser
-
setThrowParseErrors
public void setThrowParseErrors(boolean throwParseErrors) - Specified by:
setThrowParseErrorsin interfaceParserInterface
-
setParsingStrategy
- Specified by:
setParsingStrategyin interfaceParserInterface
-
setSLLOnly
public void setSLLOnly()- Specified by:
setSLLOnlyin interfaceParserInterface
-
setLLOnly
public void setLLOnly()- Specified by:
setLLOnlyin interfaceParserInterface
-
setPrintTokenFilter
Sets the token filter to use before printing.- Parameters:
printTokenFilter- The new print token filter
-
setParseTokenFilter
- Specified by:
setParseTokenFilterin interfaceParserInterface
-
getParseTokenFilter
- Specified by:
getParseTokenFilterin interfaceParserInterface
-
parseTranslationUnit
protected io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContext parseTranslationUnit(String str) -
getTokenStream
-
transform
- Specified by:
transformin interfaceTransformer<T extends JobParameters>- Throws:
RecognitionException
-