lrparser

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PNodeBytes

func PNodeBytes(node PNode, src []byte) []byte

func PNodePosStr

func PNodePosStr(node PNode) string

func PNodeString

func PNodeString(node PNode, src []byte) string

func SprintNodeTree

func SprintNodeTree(src []byte, node PNode, maxDepth int) string

maxdepth=-1 will print all

Types

type Action

type Action any

type ActionAccept

type ActionAccept struct {
}

func (*ActionAccept) String

func (a *ActionAccept) String() string

type ActionReduce

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

func (*ActionReduce) String

func (a *ActionReduce) String() string

type ActionShift

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

func (*ActionShift) String

func (a *ActionShift) String() string

type AndRule

type AndRule struct {
	BasicPNode
	CmnRule
}

(n childs as a sequence, not productions)

func (*AndRule) String

func (r *AndRule) String() string

type BasicPNode

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

basic parse node implementation

func (*BasicPNode) End

func (n *BasicPNode) End() int

func (*BasicPNode) Pos

func (n *BasicPNode) Pos() int

func (*BasicPNode) PosEmpty

func (n *BasicPNode) PosEmpty() bool

func (*BasicPNode) SetPos

func (n *BasicPNode) SetPos(pos, end int)

func (*BasicPNode) SrcString

func (n *BasicPNode) SrcString(src []byte) string

type BoolRule

type BoolRule struct {
	CmnRule
	// contains filtered or unexported fields
}

To be used in src code and then found by IfRule; the value is observed when building the contentparser, not at parse time (0 childs)

func (*BoolRule) String

func (r *BoolRule) String() string

type BuildNodeData

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

func (*BuildNodeData) Child

func (d *BuildNodeData) Child(i int) *BuildNodeData

func (*BuildNodeData) ChildInt

func (d *BuildNodeData) ChildInt(i int) (int, error)

func (*BuildNodeData) ChildLoop

func (d *BuildNodeData) ChildLoop(i int, fn BuildNodeFn) error

func (*BuildNodeData) ChildLoop2

func (d *BuildNodeData) ChildLoop2(i int, loopi int, pre, post BuildNodeFn) error

func (*BuildNodeData) ChildOptional

func (d *BuildNodeData) ChildOptional(i int) (*BuildNodeData, bool)

func (*BuildNodeData) ChildStr

func (d *BuildNodeData) ChildStr(i int) string

func (*BuildNodeData) ChildsLen

func (d *BuildNodeData) ChildsLen() int

func (*BuildNodeData) Data

func (d *BuildNodeData) Data() any

func (*BuildNodeData) End

func (d *BuildNodeData) End() int

func (*BuildNodeData) ExternalData

func (d *BuildNodeData) ExternalData() any

func (*BuildNodeData) FullSrc

func (d *BuildNodeData) FullSrc() []byte

func (*BuildNodeData) IsEmpty

func (d *BuildNodeData) IsEmpty() bool

func (*BuildNodeData) IsOr

func (d *BuildNodeData) IsOr(i int) bool

func (*BuildNodeData) NodeSrc

func (d *BuildNodeData) NodeSrc() string

func (*BuildNodeData) Pos

func (d *BuildNodeData) Pos() int

func (*BuildNodeData) PrintRuleTree

func (d *BuildNodeData) PrintRuleTree(maxDepth int)

func (*BuildNodeData) SetData

func (d *BuildNodeData) SetData(v any)

func (*BuildNodeData) SprintRuleTree

func (d *BuildNodeData) SprintRuleTree(maxDepth int) string

type BuildNodeFn

type BuildNodeFn func(*BuildNodeData) error

type CPNode

type CPNode struct {
	BasicPNode
	// contains filtered or unexported fields
}

content parser node

type CmnRule

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

common rule

type ContentParser

type ContentParser struct {
	Opt *CpOpt
	// contains filtered or unexported fields
}

func (*ContentParser) Parse

func (cp *ContentParser) Parse(src []byte, index int) (*BuildNodeData, *cpRun, error)

func (*ContentParser) ParseFileSet

func (cp *ContentParser) ParseFileSet(fset *FileSet, index int, extData any) (*BuildNodeData, *cpRun, error)

func (*ContentParser) SetBuildNodeFn

func (cp *ContentParser) SetBuildNodeFn(name string, buildFn BuildNodeFn) error

type CpOpt

type CpOpt struct {
	StartRule         string // can be empty, will try to get it from grammar
	VerboseError      bool
	EarlyStop         bool // artificially parses an endrule when nextparsedrule fails. Allows parsing to stop successfully when no more input is recognized (although there is still input), while the rules are still able to reduce correctly.
	ShiftOnSRConflict bool
	Reverse           bool // runs input/rules in reverse (useful to backtrack in the middle of big inputs to then parse normally)
}

content parser options

type DefRule

type DefRule struct {
	BasicPNode
	CmnRule
	// contains filtered or unexported fields
}

definition rule (1 child)

func (*DefRule) String

func (r *DefRule) String() string

type FileSet

type FileSet struct {
	Src      []byte // currently, just a single src
	Filename string // for errors only
}

TODO: multiple files (working for single file only)

func NewFileSetFromBytes

func NewFileSetFromBytes(src []byte) *FileSet

func (*FileSet) Error

func (fset *FileSet) Error(err error) error

func (*FileSet) Error2

func (fset *FileSet) Error2(err error, index int) error

func (*FileSet) NodeBytes

func (fset *FileSet) NodeBytes(node PNode) []byte

func (*FileSet) NodeInt

func (fset *FileSet) NodeInt(node PNode) (int, error)

func (*FileSet) NodeString

func (fset *FileSet) NodeString(node PNode) string

type FuncRule

type FuncRule struct {
	CmnRule
	// contains filtered or unexported fields
}

(0 childs)

func (*FuncRule) String

func (r *FuncRule) String() string

type IfRule

type IfRule struct {
	BasicPNode
	CmnRule
}

replaced in dereference phase (3 childs: [conditional,then,else])

func (*IfRule) String

func (r *IfRule) String() string

type Lrparser

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

func NewLrparser

func NewLrparser(fset *FileSet) (*Lrparser, error)

func NewLrparserFromBytes

func NewLrparserFromBytes(src []byte) (*Lrparser, error)

func NewLrparserFromString

func NewLrparserFromString(src string) (*Lrparser, error)

func (*Lrparser) ContentParser

func (lrp *Lrparser) ContentParser(opt *CpOpt) (*ContentParser, error)

func (*Lrparser) GetStringRule

func (lrp *Lrparser) GetStringRule(name string) (string, error)

func (*Lrparser) MustGetStringRule

func (lrp *Lrparser) MustGetStringRule(name string) string

func (*Lrparser) SetBoolRule

func (lrp *Lrparser) SetBoolRule(name string, v bool) error

func (*Lrparser) SetFuncRule

func (lrp *Lrparser) SetFuncRule(name string, parseOrder int, fn PStateParseFn) error

func (*Lrparser) SetStringRule

func (lrp *Lrparser) SetStringRule(name string, s string) error

type OrRule

type OrRule struct {
	BasicPNode
	CmnRule
}

(n childs)

func (*OrRule) String

func (r *OrRule) String() string

type PNode

type PNode interface {
	Pos() int
	End() int
}

parse node

type PState

type PState struct {
	Sc   *pscan.Scanner
	Pos  int
	Node PNode
}

func NewPState

func NewPState(src []byte) *PState

type PStateParseFn

type PStateParseFn func(ps *PState) error

TODO: rename

type ParenRule

type ParenRule struct {
	BasicPNode
	CmnRule
	// contains filtered or unexported fields
}

parenthesis, ex: (aaa (bbb|ccc)) replaced by defrules at ruleindex (1 childs)

func (*ParenRule) String

func (r *ParenRule) String() string

type PosError

type PosError struct {
	Err error
	Pos int
	//Callstack string
	Fatal bool
}

func (*PosError) Error

func (e *PosError) Error() string

type ProcRule

type ProcRule struct {
	BasicPNode
	CmnRule
	// contains filtered or unexported fields
}

processor function call rule: allows processing rules at compile time. Ex: string operations. (0 childs)

func (*ProcRule) String

func (r *ProcRule) String() string

type ProcRuleArg

type ProcRuleArg any

type ProcRuleArgs

type ProcRuleArgs []ProcRuleArg

func (ProcRuleArgs) Int

func (args ProcRuleArgs) Int(i int) (int, error)

func (ProcRuleArgs) MergedStringRule

func (args ProcRuleArgs) MergedStringRule(i int) (*StringRule, error)

func (ProcRuleArgs) Rule

func (args ProcRuleArgs) Rule(i int) (Rule, error)

type ProcRuleFn

type ProcRuleFn func(args ProcRuleArgs) (Rule, error)

type RefRule

type RefRule struct {
	BasicPNode
	CmnRule
	// contains filtered or unexported fields
}

reference to a rule // replaced in dereference phase (0 childs)

func (*RefRule) String

func (r *RefRule) String() string

type Rule

type Rule interface {
	String() string
	// contains filtered or unexported methods
}

type RuleDot

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

func (*RuleDot) String

func (rd *RuleDot) String() string

type RuleDots

type RuleDots []*RuleDot

func (RuleDots) String

func (rds RuleDots) String() string

type RuleDotsLaSet

type RuleDotsLaSet map[RuleDot]RuleSet // lookahead set

aka "set of items"

func (RuleDotsLaSet) String

func (rdslas RuleDotsLaSet) String() string

type RuleFirstT

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

rules first terminals

func (*RuleFirstT) String

func (rf *RuleFirstT) String() string

type RuleIndex

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

unique rule index

func (*RuleIndex) String

func (ri *RuleIndex) String() string

type RuleSet

type RuleSet map[Rule]struct{}

func (RuleSet) String

func (rs RuleSet) String() string

type RuneRange

type RuneRange = pscan.RuneRange

type SingletonRule

type SingletonRule struct {
	BasicPNode
	CmnRule
	// contains filtered or unexported fields
}

(0 childs)

func (*SingletonRule) String

func (r *SingletonRule) String() string

type State

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

func (*State) String

func (st *State) String() string

type StatesData

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

func (*StatesData) String

func (sd *StatesData) String() string

type StringRule

type StringRule struct {
	BasicPNode
	CmnRule
	// contains filtered or unexported fields
}

(0 childs)

func (*StringRule) String

func (r *StringRule) String() string

type Vertex

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

func (*Vertex) String

func (v *Vertex) String() string

type VertexId

type VertexId int

func (VertexId) String

func (vid VertexId) String() string

type VerticesData

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

passes rules (ruleindex) to vertices data

func (*VerticesData) String

func (vd *VerticesData) String() string

Jump to

Keyboard shortcuts

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