• Folds in old functional-fashion over the AST structure.

    Internally implemented as a special case of a two-way fold (with the down part as an essential no-op)

    Type Parameters

    • Info
    • T

    Parameters

    • ast: RNode<Info>
    • folds: {
          foldAccess: (
              node: RAccess<Info>,
              name: T,
              access: readonly ("<>" | T)[],
              down: undefined,
          ) => T;
          foldBinaryOp: (op: RBinaryOp<Info>, lhs: T, rhs: T, down: undefined) => T;
          foldExprList: (
              exprList: RExpressionList<Info>,
              grouping: undefined | [start: T, end: T],
              expressions: T[],
              down: undefined,
          ) => T;
          foldIfThenElse: (
              ifThenExpr: RIfThenElse<Info>,
              cond: T,
              then: T,
              otherwise: undefined | T,
              down: undefined,
          ) => T;
          foldLogical: (logical: RLogical<Info>, down: undefined) => T;
          foldNumber: (num: RNumber<Info>, down: undefined) => T;
          foldPipe: (op: RPipe<Info>, lhs: T, rhs: T, down: undefined) => T;
          foldString: (str: RString<Info>, down: undefined) => T;
          foldSymbol: (symbol: RSymbol<Info>, down: undefined) => T;
          foldUnaryOp: (op: RUnaryOp<Info>, operand: T, down: undefined) => T;
          functions: {
              foldArgument: (
                  argument: RArgument<Info>,
                  name: undefined | T,
                  value: undefined | T,
                  down: undefined,
              ) => T;
              foldFunctionCall: (
                  call: RFunctionCall<Info>,
                  functionNameOrExpression: T,
                  args: ("<>" | T)[],
                  down: undefined,
              ) => T;
              foldFunctionDefinition: (
                  definition: RFunctionDefinition<Info>,
                  params: T[],
                  body: T,
                  down: undefined,
              ) => T;
              foldParameter: (
                  parameter: RParameter<Info>,
                  name: T,
                  defaultValue: undefined | T,
                  down: undefined,
              ) => T;
          };
          loop: {
              foldBreak: (next: RBreak<Info>, down: undefined) => T;
              foldFor: (
                  loop: RForLoop<Info>,
                  variable: T,
                  vector: T,
                  body: T,
                  down: undefined,
              ) => T;
              foldNext: (next: RNext<Info>, down: undefined) => T;
              foldRepeat: (loop: RRepeatLoop<Info>, body: T, down: undefined) => T;
              foldWhile: (
                  loop: RWhileLoop<Info>,
                  condition: T,
                  body: T,
                  down: undefined,
              ) => T;
          };
          other: {
              foldComment: (comment: RComment<Info>, down: undefined) => T;
              foldLineDirective: (comment: RLineDirective<Info>, down: undefined) => T;
          };
      }
      • ReadonlyfoldAccess: (
            node: RAccess<Info>,
            name: T,
            access: readonly ("<>" | T)[],
            down: undefined,
        ) => T
      • ReadonlyfoldBinaryOp: (op: RBinaryOp<Info>, lhs: T, rhs: T, down: undefined) => T
      • ReadonlyfoldExprList: (
            exprList: RExpressionList<Info>,
            grouping: undefined | [start: T, end: T],
            expressions: T[],
            down: undefined,
        ) => T
      • ReadonlyfoldIfThenElse: (
            ifThenExpr: RIfThenElse<Info>,
            cond: T,
            then: T,
            otherwise: undefined | T,
            down: undefined,
        ) => T

        The otherwise argument is undefined if the else branch is missing

      • ReadonlyfoldLogical: (logical: RLogical<Info>, down: undefined) => T
      • ReadonlyfoldNumber: (num: RNumber<Info>, down: undefined) => T
      • ReadonlyfoldPipe: (op: RPipe<Info>, lhs: T, rhs: T, down: undefined) => T
      • ReadonlyfoldString: (str: RString<Info>, down: undefined) => T
      • ReadonlyfoldSymbol: (symbol: RSymbol<Info>, down: undefined) => T
      • ReadonlyfoldUnaryOp: (op: RUnaryOp<Info>, operand: T, down: undefined) => T
      • Readonlyfunctions: {
            foldArgument: (
                argument: RArgument<Info>,
                name: undefined | T,
                value: undefined | T,
                down: undefined,
            ) => T;
            foldFunctionCall: (
                call: RFunctionCall<Info>,
                functionNameOrExpression: T,
                args: ("<>" | T)[],
                down: undefined,
            ) => T;
            foldFunctionDefinition: (
                definition: RFunctionDefinition<Info>,
                params: T[],
                body: T,
                down: undefined,
            ) => T;
            foldParameter: (
                parameter: RParameter<Info>,
                name: T,
                defaultValue: undefined | T,
                down: undefined,
            ) => T;
        }
        • ReadonlyfoldArgument: (
              argument: RArgument<Info>,
              name: undefined | T,
              value: undefined | T,
              down: undefined,
          ) => T

          The name is undefined if the argument is unnamed, the value, if we have something like x=,...

        • ReadonlyfoldFunctionCall: (
              call: RFunctionCall<Info>,
              functionNameOrExpression: T,
              args: ("<>" | T)[],
              down: undefined,
          ) => T

          folds named and unnamed function calls

        • ReadonlyfoldFunctionDefinition: (
              definition: RFunctionDefinition<Info>,
              params: T[],
              body: T,
              down: undefined,
          ) => T
        • ReadonlyfoldParameter: (
              parameter: RParameter<Info>,
              name: T,
              defaultValue: undefined | T,
              down: undefined,
          ) => T

          The defaultValue is undefined if the argument was not initialized with a default value

      • Readonlyloop: {
            foldBreak: (next: RBreak<Info>, down: undefined) => T;
            foldFor: (
                loop: RForLoop<Info>,
                variable: T,
                vector: T,
                body: T,
                down: undefined,
            ) => T;
            foldNext: (next: RNext<Info>, down: undefined) => T;
            foldRepeat: (loop: RRepeatLoop<Info>, body: T, down: undefined) => T;
            foldWhile: (
                loop: RWhileLoop<Info>,
                condition: T,
                body: T,
                down: undefined,
            ) => T;
        }
      • Readonlyother: {
            foldComment: (comment: RComment<Info>, down: undefined) => T;
            foldLineDirective: (comment: RLineDirective<Info>, down: undefined) => T;
        }

    Returns T