formula

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiceParserListener

type DiceParserListener struct {
	fp.BaseDiceListener
	// contains filtered or unexported fields
}

DiceParserListener implements the BaseDiceListener

func (*DiceParserListener) EnterCount

func (s *DiceParserListener) EnterCount(ctx *fp.CountContext)

EnterCount is called when production count is entered.

func (*DiceParserListener) EnterFormula

func (s *DiceParserListener) EnterFormula(ctx *fp.FormulaContext)

EnterFormula is called when production formula is entered.

func (*DiceParserListener) EnterFunccall

func (s *DiceParserListener) EnterFunccall(ctx *fp.FunccallContext)

EnterFunc_call is called when production func_call is entered.

func (*DiceParserListener) EnterFuncname

func (s *DiceParserListener) EnterFuncname(ctx *fp.FuncnameContext)

EnterFunc_name is called when production func_name is entered.

func (*DiceParserListener) EnterModifier

func (s *DiceParserListener) EnterModifier(ctx *fp.ModifierContext)

EnterModifier is called when production modifier is entered.

func (*DiceParserListener) EnterParameter

func (s *DiceParserListener) EnterParameter(ctx *fp.ParameterContext)

EnterParameter is called when production parameter is entered.

func (*DiceParserListener) EnterSides

func (s *DiceParserListener) EnterSides(ctx *fp.SidesContext)

EnterSides is called when production sides is entered.

func (*DiceParserListener) ExitFunccall

func (s *DiceParserListener) ExitFunccall(ctx *fp.FunccallContext)

ExitFunc_call is called when production func_call is exited.

func (*DiceParserListener) Roll

func (s *DiceParserListener) Roll() Roll

Roll returns the parsed dice

type Formula

type Formula string

*

  • Formula
  • A dice formula is a string that breaks down the concept of rolling a number of dice
  • with a number of sides into an algebraic like form. The idea is to quickly be able
  • to describe a role in a more human friendly way. *
  • count := uint
  • sides := uint
  • modifer := integer
  • expr := count? 'd' sides modifier? *
  • EXAMPLES:
  • - d10 - Basic
  • - 3d10 - With count
  • - d10+10 - With modifier
  • - 3d10+10 - With count and modifier
  • - 3d10-2 - With negative modifier

func FromRoll

func FromRoll(r Roll) (f Formula)

FromRoll accepts a Roll and attempts to transform it into the formula version.

type ListenerError

type ListenerError struct {
	antlr.ErrorListener
}

ListenerError Captures errors

type Parser

type Parser interface {
	// Parse accepts a string that represents a dice rolling formula
	Parse(f Formula) (Roll, error)
}

Parser provides a function for consuming a Formula and transforming it into a Roll

func New

func New() Parser

type Roll

type Roll struct {
	Count      int
	Sides      int
	Modifier   int
	Extensions map[string][]string
}

Roll represents the component parts of a dice formula that can be used to actually perform a rolling of dice.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL