A class for transforming events from the Peggy grammar lexer into various formats.

Constructors

Properties

formula: string

The full formula.

Methods

  • Protected Internal

    Handle a base roll expression.

    Parameters

    • head: any

      The first operand.

    • tail: [string[], any][]

      Zero or more subsequent (operators, operand) tuples.

    • Optional leading: string

      A leading operator.

    • formula: string

      The original matched text.

    • error: Function

      The peggy error callback to invoke on a parse error.

    Returns any

  • Protected Internal

    Handle a dice term.

    Parameters

    • number: any

      The number of dice.

    • faces: any

      The number of die faces or a string denomination like "c" or "f".

    • modifiers: string

      The matched modifiers string.

    • flavor: string

      Associated flavor text.

    • formula: string

      The original matched text.

    Returns any

  • Protected Internal

    Handle a numeric term.

    Parameters

    • number: number

      The number.

    • flavor: string

      Associated flavor text.

    Returns any

  • Protected Internal

    Handle a math term.

    Parameters

    • fn: string

      The Math function.

    • head: any

      The first term.

    • tail: any[]

      Zero or more additional terms.

    • flavor: string

      Associated flavor text.

    • formula: string

      The original matched text.

    Returns any

  • Protected Internal

    Handle a pool term.

    Parameters

    • head: any

      The first term.

    • tail: any[]

      Zero or more additional terms.

    • modifiers: string

      The matched modifiers string.

    • flavor: string

      Associated flavor text.

    • formula: string

      The original matched text.

    Returns any

  • Protected Internal

    Handle a parenthetical.

    Parameters

    • term: any

      The inner term.

    • flavor: string

      Associated flavor text.

    • formula: string

      The original matched text.

    Returns any

  • Protected

    Handle some string that failed to be classified.

    Parameters

    • term: string

      The term.

    • Optional flavor: string

      Associated flavor text.

    Returns StringParseNode

  • Protected

    Collapse multiple additive operators into a single one.

    Parameters

    • operators: string[]

      A sequence of additive operators.

    Returns string

  • Protected

    Wrap a term with a leading minus.

    Parameters

    • term: any

      The term to wrap.

    Returns any

  • Flatten a tree structure (either a parse tree or AST) into an array with operators in infix notation.

    Parameters

    • root: any

      The root of the tree.

    Returns any[]

  • Use the Shunting Yard algorithm to convert a parse tree or list of terms into an AST with correct operator precedence. See https://en.wikipedia.org/wiki/Shunting_yard_algorithm for a description of the algorithm in detail.

    Parameters

    • root: any

      The root of the parse tree or a list of terms.

    Returns any

    The root of the AST.

  • Determine if a given node is an operator term.

    Parameters

    • node: any

    Returns boolean

  • Format a list argument.

    Parameters

    • list: any[]

      The list to format.

    Returns string

  • Format a parser argument.

    Parameters

    • arg: any

      The argument.

    Returns string

  • Format arguments for debugging.

    Parameters

    • method: string

      The method name.

    • Rest ...args: any[]

      The arguments.

    Returns string