Class SearchTerminals<T>
java.lang.Object
io.github.douira.glsl_transformer.GLSLParserBaseListener
io.github.douira.glsl_transformer.transform.TransformationPhase<T>
io.github.douira.glsl_transformer.transform.WalkPhase<T>
io.github.douira.glsl_transformer.core.SearchTerminals<T>
- All Implemented Interfaces:
io.github.douira.glsl_transformer.GLSLParserListener,CollectorChild<T>,ParseTreeListener
This phase finds targets in specified target token types (usually
identifiers) and triggers their handlers. The behavior of the targets can be
customized with the various available classes.
By default, an exact string match of the text in the terminal node and the
needle search string is required. However, this behavior can be configured.
If something other than terminals should be searched, simply extend the walk
phase yourself and do something when it visits the parse context of
interest.
-
Nested Class Summary
Nested classes/interfaces inherited from class io.github.douira.glsl_transformer.transform.TransformationPhase
TransformationPhase.InjectionPoint -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA constant for easy access to the identifier token type.protected final Collection<HandlerTarget<T>>The list of targets to process for each targeted context. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty identifier search with a hash set.SearchTerminals(int terminalTokenType, HandlerTarget<T> target) Creates a new target search phase with only a single target.SearchTerminals(int terminalTokenType, Collection<HandlerTarget<T>> targets) Creates a new target search phase with the given targets.SearchTerminals(HandlerTarget<T> target) Creates a new identifier search phase with only a single target.SearchTerminals(Collection<HandlerTarget<T>> targets) Creates a new identifier search phase with with given targets. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddReplacement(String needle, String newContent, Function<io.github.douira.glsl_transformer.GLSLParser, ExtendedContext> parseMethod) Adds a replacement target that replaces matching terminal nodes with new nodes parsed from the given string using a specified parser method.voidaddReplacementExpression(String needle, String expressionContent) Adds a replacement target that replaces matching terminal nodes with new expression nodes parsed from the given string.voidaddReplacementTerminal(String needle, String terminalContent) Adds a replacement target that replaces matching terminal nodes with new unparsed string nodes.voidaddTarget(HandlerTarget<T> target) Adds a target for processing.voidMakes this search phase not use exact matching.protected booleanfindNeedle(String content, HandlerTarget<T> target) Checks if the given content contains a needle.voidsetTerminalTokenType(int terminalTokenType) Sets the terminal token type.voidvisitTerminal(TerminalNode node) static <T> SearchTerminals<T>withReplacement(String needle, String newContent, Function<io.github.douira.glsl_transformer.GLSLParser, ExtendedContext> parseMethod) Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new nodes parsed from the given string using a specified parser method.static <T> SearchTerminals<T>withReplacementExpression(String needle, String expressionContent) Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new expression nodes parsed from the given string.static <T> SearchTerminals<T>withReplacementTerminal(String needle, String terminalContent) Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new unparsed string nodes.Methods inherited from class io.github.douira.glsl_transformer.transform.WalkPhase
afterWalk, beforeWalk, checkBeforeWalk, isActiveAfterWalk, isActiveAtWalk, isActiveBeforeWalk, runAfterWalkMethods inherited from class io.github.douira.glsl_transformer.transform.TransformationPhase
compilePath, compilePattern, createLocalRoot, findAndMatch, getCollector, getSiblings, init, injectDefine, injectExternalDeclaration, injectExternalDeclarations, injectNode, injectNodes, injectNodes, isActive, lazyInit, removeNode, replaceNode, replaceNode, setCollectorMethods inherited from class io.github.douira.glsl_transformer.GLSLParserBaseListener
enterAdditiveExpression, enterAndExpression, enterArraySpecifier, enterAssignmentExpression, enterAssignmentOperator, enterAttribute, enterBuiltinTypeSpecifierFixed, enterBuiltinTypeSpecifierParseable, enterCallParameterList, enterCaseLabel, enterCompoundStatement, enterCondition, enterConditionalExpression, enterConstantExpression, enterDeclaration, enterDeclarationMember, enterDeclarationMemberList, enterDeclarationStatement, enterDemoteStatement, enterDoWhileStatement, enterEmptyStatement, enterEqualityExpression, enterEveryRule, enterExclusiveOrExpression, enterExpression, enterExpressionStatement, enterExtensionState, enterExtensionStatement, enterExternalDeclaration, enterForStatement, enterFullySpecifiedType, enterFunctionCall, enterFunctionDefinition, enterFunctionHeader, enterFunctionIdentifier, enterFunctionParameterList, enterFunctionPrototype, enterInclusiveOrExpression, enterInitDeclaratorList, enterInitializer, enterInterpolationQualifier, enterInvariantQualifier, enterJumpStatement, enterLayoutDefaults, enterLayoutModes, enterLayoutQualifier, enterLayoutQualifierId, enterLogicalAndExpression, enterLogicalOrExpression, enterLogicalXorExpression, enterMethodCall, enterMultiplicativeExpression, enterParameterDeclaration, enterParameterDeclarator, enterPostfixExpression, enterPragmaStatement, enterPreciseQualifier, enterPrecisionQualifier, enterPrimaryExpression, enterRelationalExpression, enterSelectionStatement, enterShiftExpression, enterSimpleStatement, enterSingleAttribute, enterStatement, enterStorageQualifier, enterStructDeclaration, enterStructDeclarationList, enterStructDeclarator, enterStructDeclaratorList, enterStructSpecifier, enterSwitchStatement, enterTranslationUnit, enterTypeNameList, enterTypeQualifier, enterTypeSpecifier, enterTypeSpecifierNonarray, enterUnaryExpression, enterUnaryOperator, enterVariableIdentifier, enterVersionStatement, enterWhileStatement, exitAdditiveExpression, exitAndExpression, exitArraySpecifier, exitAssignmentExpression, exitAssignmentOperator, exitAttribute, exitBuiltinTypeSpecifierFixed, exitBuiltinTypeSpecifierParseable, exitCallParameterList, exitCaseLabel, exitCompoundStatement, exitCondition, exitConditionalExpression, exitConstantExpression, exitDeclaration, exitDeclarationMember, exitDeclarationMemberList, exitDeclarationStatement, exitDemoteStatement, exitDoWhileStatement, exitEmptyStatement, exitEqualityExpression, exitEveryRule, exitExclusiveOrExpression, exitExpression, exitExpressionStatement, exitExtensionState, exitExtensionStatement, exitExternalDeclaration, exitForStatement, exitFullySpecifiedType, exitFunctionCall, exitFunctionDefinition, exitFunctionHeader, exitFunctionIdentifier, exitFunctionParameterList, exitFunctionPrototype, exitInclusiveOrExpression, exitInitDeclaratorList, exitInitializer, exitInterpolationQualifier, exitInvariantQualifier, exitJumpStatement, exitLayoutDefaults, exitLayoutModes, exitLayoutQualifier, exitLayoutQualifierId, exitLogicalAndExpression, exitLogicalOrExpression, exitLogicalXorExpression, exitMethodCall, exitMultiplicativeExpression, exitParameterDeclaration, exitParameterDeclarator, exitPostfixExpression, exitPragmaStatement, exitPreciseQualifier, exitPrecisionQualifier, exitPrimaryExpression, exitRelationalExpression, exitSelectionStatement, exitShiftExpression, exitSimpleStatement, exitSingleAttribute, exitStatement, exitStorageQualifier, exitStructDeclaration, exitStructDeclarationList, exitStructDeclarator, exitStructDeclaratorList, exitStructSpecifier, exitSwitchStatement, exitTranslationUnit, exitTypeNameList, exitTypeQualifier, exitTypeSpecifier, exitTypeSpecifierNonarray, exitUnaryExpression, exitUnaryOperator, exitVariableIdentifier, exitVersionStatement, exitWhileStatement, visitErrorNodeMethods 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.transform.CollectorChild
getJobParameters, getLexer, getParser, getRootNode
-
Field Details
-
IDENTIFIER
public static final int IDENTIFIERA constant for easy access to the identifier token type.- See Also:
-
targets
The list of targets to process for each targeted context.
-
-
Constructor Details
-
SearchTerminals
Creates a new target search phase with the given targets.- Parameters:
terminalTokenType- The type of the tokens to search intargets- The targets to search for
-
SearchTerminals
Creates a new target search phase with only a single target.- Parameters:
terminalTokenType- The type of the token to search intarget- The target to search for
-
SearchTerminals
Creates a new identifier search phase with with given targets.- Parameters:
targets- The targets to search for in identifiers
-
SearchTerminals
Creates a new identifier search phase with only a single target.- Parameters:
target- The target to search for in identifiers
-
SearchTerminals
public SearchTerminals()Creates a new empty identifier search with a hash set.
-
-
Method Details
-
visitTerminal
- Specified by:
visitTerminalin interfaceParseTreeListener- Overrides:
visitTerminalin classio.github.douira.glsl_transformer.GLSLParserBaseListener
-
allowInexactMatches
public void allowInexactMatches()Makes this search phase not use exact matching. -
setTerminalTokenType
public void setTerminalTokenType(int terminalTokenType) Sets the terminal token type. UseIDENTIFIERto search for identifiers.- Parameters:
terminalTokenType- The terminal token type
-
addTarget
Adds a target for processing.- Parameters:
target- The target to add to the collection of targets
-
findNeedle
Checks if the given content contains a needle. This should be overwritten if the matching should be done differently, like using regex or case-insensitive matching.- Parameters:
content- The content to search intarget- The target being searched for- Returns:
- If the target was found in the content
-
addReplacement
public void addReplacement(String needle, String newContent, Function<io.github.douira.glsl_transformer.GLSLParser, ExtendedContext> parseMethod) Adds a replacement target that replaces matching terminal nodes with new nodes parsed from the given string using a specified parser method.- Parameters:
needle- The needle (search string)newContent- The new content to parse into a nodeparseMethod- The parser method to create the new node with
-
addReplacementExpression
Adds a replacement target that replaces matching terminal nodes with new expression nodes parsed from the given string.- Parameters:
needle- The needle (search string)expressionContent- The new content to parse into an expression
-
addReplacementTerminal
Adds a replacement target that replaces matching terminal nodes with new unparsed string nodes.- Parameters:
needle- The needle (search string)terminalContent- The new terminal content to insert as a string node
-
withReplacement
public static <T> SearchTerminals<T> withReplacement(String needle, String newContent, Function<io.github.douira.glsl_transformer.GLSLParser, ExtendedContext> parseMethod) Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new nodes parsed from the given string using a specified parser method.- Type Parameters:
T- The job parameter type- Parameters:
needle- The needle (search string)newContent- The new content to parse into a nodeparseMethod- The parser method to create the new node with- Returns:
- The configured identifier replacement transformation
- See Also:
-
withReplacementExpression
public static <T> SearchTerminals<T> withReplacementExpression(String needle, String expressionContent) Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new expression nodes parsed from the given string.- Type Parameters:
T- The job parameter type- Parameters:
needle- The needle (search string)expressionContent- The new content to parse into an expression- Returns:
- The configured identifier replacement transformation
-
withReplacementTerminal
Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new unparsed string nodes.- Type Parameters:
T- The job parameter type- Parameters:
needle- The needle (search string)terminalContent- The new terminal content to insert as a string node- Returns:
- The configured identifier replacement transformation
-