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

Constructors

  • Parameters

    • formula: string

      The full formula.

    Returns RollParser

Properties

formula: string

The full formula.

Methods

  • Protected

    Collapse multiple additive operators into a single one.

    Parameters

    • operators: string[]

      A sequence of additive operators.

    Returns string

  • Protected

    Handle a dice term.

    Parameters

    • number: null | RollParseNode

      The number of dice.

    • faces: null | string | RollParseNode

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

    • modifiers: null | string

      The matched modifiers string.

    • flavor: null | string

      Associated flavor text.

    • formula: string

      The original matched text.

    Returns RollParseNode

  • Protected

    Handle a base roll expression.

    Parameters

    • head: RollParseNode

      The first operand.

    • tail: [string[], RollParseNode][]

      Zero or more subsequent (operators, operand) tuples.

    • Optionalleading: string

      A leading operator.

    • formula: string

      The original matched text.

    • error: Function

      The peggy error callback to invoke on a parse error.

    Returns RollParseNode

  • Protected

    Handle a math term.

    Parameters

    • fn: string

      The Math function.

    • head: RollParseNode

      The first term.

    • tail: RollParseNode[]

      Zero or more additional terms.

    • flavor: string

      Associated flavor text.

    • formula: string

      The original matched text.

    Returns RollParseNode

  • Protected

    Handle a numeric term.

    Parameters

    • number: number

      The number.

    • flavor: string

      Associated flavor text.

    Returns RollParseNode

  • Protected

    Handle a parenthetical.

    Parameters

    • term: RollParseNode

      The inner term.

    • flavor: null | string

      Associated flavor text.

    • formula: string

      The original matched text.

    Returns RollParseNode

  • Protected

    Handle a pool term.

    Parameters

    • head: RollParseNode

      The first term.

    • tail: RollParseNode[]

      Zero or more additional terms.

    • modifiers: null | string

      The matched modifiers string.

    • flavor: null | string

      Associated flavor text.

    • formula: string

      The original matched text.

    Returns RollParseNode

  • Protected

    Handle some string that failed to be classified.

    Parameters

    • term: string

      The term.

    • Optionalflavor: null | string

      Associated flavor text.

    Returns StringParseNode

  • Format a parser argument.

    Parameters

    • arg: any

      The argument.

    Returns string

  • Format arguments for debugging.

    Parameters

    • method: string

      The method name.

    • ...args: any[]

      The arguments.

    Returns string

  • Format a list argument.

    Parameters

    • list: any[]

      The list to format.

    Returns string

  • Determine if a given node is an operator term.

    Parameters

    • node: any

    Returns boolean