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 (Returns generic) by providing sensible Monoid behavior overwriting the DefaultNormalizedAstFold#concat|concat method and supplying the empty value in the constructor.

By providing entry and exit you 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 respective fold* methods).

let marker = false;
class MyNumberFold<Info> extends DefaultNormalizedAstFold<void, Info> {
override foldRNumber(node: RNumber<Info>) {
super.foldRNumber(node);
marker = true;
}
}

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 ast and want to check if the AST contains a number:

const result = new MyNumberFold().fold(ast);

Please take a look at the corresponding tests or the wiki pages for more information on how to use this fold.

Type Parameters

Implements

Constructors

Properties

empty: Returns
folds: Readonly<{
    RAccess: FoldOfType<Access, Returns, Info>;
    RArgument: FoldOfType<Argument, Returns, Info>;
    RBinaryOp: FoldOfType<BinaryOp, Returns, Info>;
    RBreak: FoldOfType<Break, Returns, Info>;
    RComment: FoldOfType<Comment, Returns, Info>;
    RExpressionList: FoldOfType<ExpressionList, Returns, Info>;
    RForLoop: FoldOfType<ForLoop, Returns, Info>;
    RFunctionCall: FoldOfType<FunctionCall, Returns, Info>;
    RFunctionDefinition: FoldOfType<FunctionDefinition, Returns, Info>;
    RIfThenElse: FoldOfType<IfThenElse, Returns, Info>;
    RLineDirective: FoldOfType<LineDirective, Returns, Info>;
    RLogical: FoldOfType<Logical, Returns, Info>;
    RNext: FoldOfType<Next, Returns, Info>;
    RNumber: FoldOfType<Number, Returns, Info>;
    RParameter: FoldOfType<Parameter, Returns, Info>;
    RPipe: FoldOfType<Pipe, Returns, Info>;
    RRepeatLoop: FoldOfType<RepeatLoop, Returns, Info>;
    RString: FoldOfType<String, Returns, Info>;
    RSymbol: FoldOfType<Symbol, Returns, Info>;
    RUnaryOp: FoldOfType<UnaryOp, Returns, Info>;
    RWhileLoop: FoldOfType<WhileLoop, Returns, Info>;
}> = ...

Methods