parser

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DNotationParser

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

func NewDNotationParser

func NewDNotationParser() (*DNotationParser, error)

func (*DNotationParser) DoParse

func (p *DNotationParser) DoParse(input string) (*DNotationResult, error)

func (*DNotationParser) GetEBNF

func (p *DNotationParser) GetEBNF() string

type DNotationResult

type DNotationResult struct {
	Value    int
	StrValue string
}

type Expression

type Expression struct {
	Left  *Term     `@@`
	Right []*OpTerm `@@*`
}

func (*Expression) Eval

func (e *Expression) Eval(baseRoller *roller.BaseRoller) (*DNotationResult, error)

type Factor

type Factor struct {
	Left  *Value      `@@`
	Right []*OpDValue `@@*`
}

func (*Factor) Eval

func (d *Factor) Eval(baseRoller *roller.BaseRoller) (*DNotationResult, error)

type OpDValue

type OpDValue struct {
	Operator Operator `"d"`
	Value    *Value   `@@`
}

type OpFactor

type OpFactor struct {
	Operator Operator `@("*" | "/")`
	Factor   *Factor  `@@`
}

type OpTerm

type OpTerm struct {
	Operator Operator `@("+" | "-")`
	Term     *Term    `@@`
}

type Operator

type Operator int
const (
	OpMul  Operator = iota // '*'
	OpDiv                  // '/'
	OpAdd                  // '+'
	OpSub                  // '-'
	OpRoll                 // 'd'
)

func (*Operator) Capture

func (o *Operator) Capture(s []string) error

func (Operator) Eval

func (o Operator) Eval(l, r int) (*DNotationResult, error)

type RollParser added in v1.3.0

type RollParser interface {
	DoParse(string) (*DNotationResult, error)
}

RollParser interface to support parsing a d-notation roll & getting a result

type Term

type Term struct {
	Left  *Factor     `@@`
	Right []*OpFactor `@@*`
}

func (*Term) Eval

func (t *Term) Eval(baseRoller *roller.BaseRoller) (*DNotationResult, error)

type Value

type Value struct {
	Number        int         `  @(Number)`
	SubExpression *Expression `| "(" @@ ")"`
}

func (*Value) Eval

func (v *Value) Eval(roller *roller.BaseRoller) (*DNotationResult, error)

Jump to

Keyboard shortcuts

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