• Folds in old functional-fashion over the AST structure but allowing for a down function which can pass context to child nodes.

    Type Parameters

    • Info
    • Down
    • Up

    Parameters

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

        The otherwise argument is undefined if the else branch is missing

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

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

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

          folds named and unnamed function calls

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

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

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

    Returns Up