Empty must provide a sensible default whenever you want to have Returns as non-void
(e.g., whenever you want your visitors to be able to return a value).
Optionalenter: EntryExitVisitor<Info>Optionalexit: EntryExitVisitor<Info>Protected ReadonlyemptyProtected ReadonlyenterProtected ReadonlyexitProtected ReadonlyfoldsProtectedconcatMonoid::concat
ProtectedconcatProtectedfold
Default implementation of a fold over the normalized AST (using the classic fold traversal). To modify the behavior, please extend this class and overwrite the methods of interest. You can control the value passing (
Returnsgeneric) by providing sensible Monoid behavior overwriting the DefaultNormalizedAstFold#concat|concat method and supplying the empty value in the constructor.Note
By providing
entryandexityou can use this as an extension to the simpler visitAst function but without the early termination within the visitors (for this, you can overwrite the respectivefold*methods).Example: First you want to create your own fold:
This one does explicitly not use the return functionality (and hence acts more as a conventional visitor). Now let us suppose we have a normalized AST as an RNode in the variable
astand want to check if the AST contains a number:Please take a look at the corresponding tests or the wiki pages for more information on how to use this fold.