< Dice
Revision as of 18:50, 20 April 2017 by Skizzerz (talk | contribs) (add)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Dice.AST Namespace

From DiceRoller Documentation

The Dice.AST namespace contains the internal nodes which constitute a dice expression in a tree form (abstract syntax tree). This tree is then evaluated in a visitor pattern to perform the roll.

Classes

Class Description
ComparisonNode Represents one or more comparisons.
CritNode Represents marking a die as a critical or fumble, for display purposes.
DiceAST Represents a node in the dice expression Abstract Syntax Tree.
ExplodeNode Represents dice that reroll when certain conditions are met.
FunctionNode Represents a function call, either a global function or one attached to a roll.
GroupNode Represents one or more dice expressions that can be rolled multiple times as a set.
GroupPartialNode An ephemeral node used in construction of the AST.
KeepNode A node representing that only some of the rolled dice should be kept.
LiteralNode Represents a node which contains a literal value.
MacroNode Represents a macro whose exact functionality is not specified by this library.
MathNode Represents a math expression on two nodes.
RerollNode Represents a node in which we reroll the underlying expression should a comparison match.
RollNode Represents rolling one or more dice of the same type.
RollPartialNode An ephemeral node used in construction of the AST.
SortNode Represents sorting the dice rolled into a specific order.
SuccessNode Represents a roll where we count the number of successes and failures in a dice pool rather than accumulating the die rolls.

Structures

Class Description
Comparison Holds information about a comparison, which checks a CompareOp against an expression.

Enumerations

Class Description
CompareOp The type of comparison to perform.
ExplodeType The type of exploding dice.
KeepType The type of a keep node.
MathOp Represents the operation performed on each side of a math expression.
RollType How rolled values are calculated.
SortDirection Which way the dice are sorted.

Remarks

This namespace is mainly for internal use, however there are some public properties on each node which (once cast from their base class to the appropriate subclass) allow one to walk the tree and view each individual die roll, should such be necessary. Typically, the RollResult class contains everything you need to know about a die roll, so walking the tree isn't necessary in general.

When deserializing a RollResult, the AST is no longer accessible (it does not get serialized along with the RollResult in order to save space, as the AST is quite large memory-wise). The AST can be reconstructed by making use of the AllRolls and AllMacros fields of a RollResult (as these fields are private, Reflection will be needed to access them, and there is no guarantee that they will not change in incompatible ways across point releases as private and internal fields are not part of the public API for semver considerations). A method to reconstruct the AST does not currently exist in the library, but if such is needed, open an issue on GitHub requesting it along with your use-case.