parser

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiceRoll

type DiceRoll struct {
	Count int // The 'X' part. Defaults to 1 if not present.
	Sides int // The 'Y' part.
}

func (DiceRoll) String

func (dr DiceRoll) String() string

String creates a canonical string representation of a DiceRoll, e.g., "3D6".

func (DiceRoll) Type

func (dr DiceRoll) Type() TermType

type Modifier

type Modifier struct {
	Value int
}

func (Modifier) String

func (m Modifier) String() string

String creates a string representation of a Modifier.

func (Modifier) Type

func (m Modifier) Type() TermType

type Operation

type Operation struct {
	Operator rune // '+' or '-'
	Term     Term
}

type ParsedExpression

type ParsedExpression struct {
	// The first term in the expression (e.g., "1D20" in "1D20+5").
	InitialTerm Term
	// A list of subsequent operations (e.g., "+5").
	Operations []Operation
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser holds the state of the parsing process.

func NewParser

func NewParser(input string) *Parser

NewParser creates a new parser without parsing (yet)

func (*Parser) Parse

func (p *Parser) Parse() (*ParsedExpression, error)

Parse main entry point to parsing

type Term

type Term interface {
	Type() TermType
	String() string
}

type TermType

type TermType int
const (
	DiceRollType TermType = iota
	ModifierType
)

Jump to

Keyboard shortcuts

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