Documentation
¶
Index ¶
- Constants
- Variables
- type AOPParser
- type COPPStack
- func (s *COPPStack) AppendStateToken(token *Token)
- func (s *COPPStack) Combine() *COPPStack
- func (s *COPPStack) CombineLOS(pool *Pool[stack[Token]]) (*LOS[Token], map[*Token]*Token)
- func (s *COPPStack) Current() []*Token
- func (s COPPStack) FirstTerminal() *Token
- func (s *COPPStack) IsCurrentSingleNonterminal() bool
- func (s *COPPStack) Iterator() *CyclicParserStackIterator
- func (s *COPPStack) LastNonterminal() (*Token, error)
- func (s *COPPStack) Pop() *Token
- func (s *COPPStack) Pop2() (*Token, *CyclicAutomataState)
- func (s *COPPStack) Previous() []*Token
- func (s *COPPStack) Push(token *Token) *Token
- func (s *COPPStack) PushWithState(token *Token, state CyclicAutomataState) *Token
- func (s *COPPStack) SwapState()
- func (s COPPStack) UpdateFirstTerminal()
- func (s *COPPStack) YieldingPrecedence() int
- type COPParser
- type Constructor
- type CyclicAutomataState
- type CyclicParserStackIterator
- type Grammar
- type LOPS
- type LOPSIt
- type LOS
- func (l *LOS[T]) Clear()
- func (l *LOS[T]) Get() *T
- func (l *LOS[T]) GetNext() *T
- func (l *LOS[T]) HeadIterator() *LOSIt[T]
- func (l *LOS[T]) Length() int
- func (l *LOS[T]) Merge(other *LOS[T])
- func (l *LOS[T]) NumStacks() int
- func (l *LOS[T]) Pop() *T
- func (l *LOS[T]) Push(t T) *T
- func (l *LOS[T]) Split(n int) ([]*LOS[T], error)
- type LOSIt
- type LexResult
- type Lexer
- type LexerDFA
- type LexerDFAState
- type LexerFunc
- type OPPStack
- func (s *OPPStack) Combine() *OPPStack
- func (s *OPPStack) CombineLOS(pool *Pool[stack[Token]]) *LOS[Token]
- func (s OPPStack) FirstTerminal() *Token
- func (s *OPPStack) LastNonterminal() (*Token, error)
- func (s *OPPStack) Pop() *Token
- func (s *OPPStack) Push(token *Token) *Token
- func (s OPPStack) UpdateFirstTerminal()
- func (s *OPPStack) YieldingPrecedence() int
- type OPParser
- type Parser
- type ParserFunc
- type ParsingStrategy
- type Pool
- type PoolOpt
- type PreambleFunc
- type Precedence
- type ReductionStrategy
- type Rule
- type RuleFlags
- type RunOptions
- type Runner
- type RunnerOpt
- func WithAverageTokenLength(length int) RunnerOpt
- func WithCPUProfiling(w io.Writer) RunnerOpt
- func WithConcurrency(n int) RunnerOpt
- func WithGarbageCollection(on bool) RunnerOpt
- func WithLogging(logger *log.Logger) RunnerOpt
- func WithMemoryProfiling(w io.Writer) RunnerOpt
- func WithParallelFactor(factor float64) RunnerOpt
- func WithReductionStrategy(strat ReductionStrategy) RunnerOpt
- type Scanner
- type Token
- type TokenType
Constants ¶
const DefaultAverageTokenLength int = 4
const DefaultParallelFactor float64 = 0.5
Variables ¶
var (
ErrInvalid = errors.New("invalid character")
)
Functions ¶
This section is empty.
Types ¶
type AOPParser ¶
type AOPParser struct {
*OPParser
}
func NewAOPParser ¶
func NewAOPParser(g *Grammar, src []byte, opts *RunOptions) *AOPParser
type COPPStack ¶
type COPPStack struct { StatesLOS *LOS[CyclicAutomataState] StateTokenStack *stack[*Token] State CyclicAutomataState ProducedTokens map[*Token]*Token // contains filtered or unexported fields }
func NewCOPPStack ¶
func NewCOPPStack(tokenStackPool *Pool[stack[*Token]], stateStackPool *Pool[stack[CyclicAutomataState]], producedTokens map[*Token]*Token) *COPPStack
NewCOPPStack creates a new COPPStack initialized with one empty stack.
func (*COPPStack) AppendStateToken ¶
func (*COPPStack) CombineLOS ¶
func (COPPStack) FirstTerminal ¶
func (s COPPStack) FirstTerminal() *Token
FirstTerminal returns a pointer to the first terminal token on the stack.
func (*COPPStack) IsCurrentSingleNonterminal ¶
func (*COPPStack) Iterator ¶
func (s *COPPStack) Iterator() *CyclicParserStackIterator
func (*COPPStack) LastNonterminal ¶
func (*COPPStack) Pop2 ¶
func (s *COPPStack) Pop2() (*Token, *CyclicAutomataState)
func (*COPPStack) PushWithState ¶
func (s *COPPStack) PushWithState(token *Token, state CyclicAutomataState) *Token
func (COPPStack) UpdateFirstTerminal ¶
func (s COPPStack) UpdateFirstTerminal()
UpdateFirstTerminal should be used after a reduction in order to update the first terminal counter. In fact, in order to save some time, only the Push operation automatically updates the first terminal pointer, while the Pop operation does not.
func (*COPPStack) YieldingPrecedence ¶
type COPParser ¶
type COPParser struct {
// contains filtered or unexported fields
}
COPParser implements parsing using a simplified approach to C-OPGs.
func NewCOPParser ¶
func NewCOPParser(g *Grammar, src []byte, opts *RunOptions) *COPParser
NewCOPParser allocates all required resources for a COPParser to be usable.
func (*COPParser) CombineSweepLOS ¶
type Constructor ¶
type Constructor[T any] func() *T
type CyclicAutomataState ¶
type CyclicParserStackIterator ¶
type CyclicParserStackIterator struct { TokensIt *LOPSIt[Token] StatesIt *LOSIt[CyclicAutomataState] }
func (*CyclicParserStackIterator) Cur ¶
func (i *CyclicParserStackIterator) Cur() (*Token, *CyclicAutomataState)
func (*CyclicParserStackIterator) IsLast ¶
func (i *CyclicParserStackIterator) IsLast() bool
func (*CyclicParserStackIterator) Next ¶
func (i *CyclicParserStackIterator) Next() (*Token, *CyclicAutomataState)
type Grammar ¶
type Grammar struct { NumTerminals uint16 NumNonterminals uint16 MaxRHSLength int Rules []Rule CompressedRules []uint16 MaxPrefixLength int Prefixes [][]TokenType CompressedPrefixes []uint16 PrecedenceMatrix [][]Precedence BitPackedPrecedenceMatrix []uint64 Func ParserFunc PreambleFunc PreambleFunc ParsingStrategy ParsingStrategy }
type LOPS ¶
type LOPS[T any] struct { // contains filtered or unexported fields }
LOPS is a list of pointer stacks.
func (*LOPS[T]) Capacity ¶
Capacity returns the maximum capacity of the current allocated structure.
func (*LOPS[T]) HeadIterator ¶
HeadIterator returns an iterator initialized to point before the first element of the list.
func (*LOPS[T]) Length ¶
Length returns the number of items contained in the LOPS. It takes constant time to execute.
func (*LOPS[T]) MaxLength ¶
MaxLength returns the maximum occupancy of the data structure so far, i.e. what is the maximum amount of items in use at any given time.
func (*LOPS[T]) NumStacks ¶
NumStacks returns the number of stacks contained in the LOPS. It takes linear time (in the number of stacks) to execute.
type LOPSIt ¶
type LOPSIt[T any] struct { // contains filtered or unexported fields }
LOPSIt allows to iterate over a LOPS, either forward or backwards.
func (*LOPSIt[T]) Cur ¶
func (i *LOPSIt[T]) Cur() *T
Cur returns a pointer to the current element. It returns nil if it points before the first element or after the last element of the list.
type LOS ¶
type LOS[T any] struct { // contains filtered or unexported fields }
LOS is a list of stacks.
func (*LOS[T]) GetNext ¶
func (l *LOS[T]) GetNext() *T
GetNext returns the first empty element from the LOS.
func (*LOS[T]) HeadIterator ¶
HeadIterator returns an iterator initialized to point before the first element of the list.
func (*LOS[T]) Length ¶
Length returns the number of items contained in the LOS. It takes constant time to execute.
func (*LOS[T]) NumStacks ¶
NumStacks returns the number of stacks contained in the LOS. It takes linear time (in the number of stacks) to execute.
func (*LOS[T]) Pop ¶
func (l *LOS[T]) Pop() *T
Pop removes the topmost element from the LOS and returns it.
type LOSIt ¶
type LOSIt[T any] struct { // contains filtered or unexported fields }
LOSIt allows to iterate over a LOS, either forward or backwards.
type Lexer ¶
type Lexer struct { Automaton LexerDFA CutPointsAutomaton LexerDFA Func LexerFunc PreambleFunc PreambleFunc }
type LexerDFA ¶
type LexerDFA []LexerDFAState
type LexerDFAState ¶
type OPPStack ¶
type OPPStack struct {
// contains filtered or unexported fields
}
OPPStack is the data structure used by OPP and AOPP workers during parsing.
func NewOPPStack ¶
func (OPPStack) FirstTerminal ¶
func (s OPPStack) FirstTerminal() *Token
FirstTerminal returns a pointer to the first terminal token on the stack.
func (*OPPStack) LastNonterminal ¶
func (*OPPStack) Push ¶
Push pushes a token pointer in the parserStack. It returns the pointer itself.
func (OPPStack) UpdateFirstTerminal ¶
func (s OPPStack) UpdateFirstTerminal()
UpdateFirstTerminal should be used after a reduction in order to update the first terminal counter. In fact, in order to save some time, only the Push operation automatically updates the first terminal pointer, while the Pop operation does not.
func (*OPPStack) YieldingPrecedence ¶
type OPParser ¶
type OPParser struct {
// contains filtered or unexported fields
}
func NewOPParser ¶
func NewOPParser(g *Grammar, src []byte, opts *RunOptions) *OPParser
func (*OPParser) CombineSweepLOS ¶
type ParserFunc ¶
type ParsingStrategy ¶
type ParsingStrategy uint8
const ( // OPP is Operator-Precedence Parsing. It is the original parsing ReductionStrategy. OPP ParsingStrategy = iota // AOPP is Associative Operator Precedence Parsing. AOPP // COPP is Cyclic Operator Precedence Parsing. COPP )
func (ParsingStrategy) String ¶
func (s ParsingStrategy) String() string
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
A Pool can be used to preallocate a number of items of type T. It is not thread-safe.
func (*Pool[T]) Get ¶
func (p *Pool[T]) Get() *T
Get returns an item from the pool if available. Otherwise, it initializes a new one. It is not thread-safe.
func (*Pool[T]) NumAllocated ¶
NumAllocated returns the number of items allocated so far.
type PoolOpt ¶
func WithConstructor ¶
func WithConstructor[T any](constructor Constructor[T]) PoolOpt[T]
type PreambleFunc ¶
type PreambleFunc func(sourceLen, concurrency int)
type Precedence ¶
type Precedence uint8
const ( PrecEquals Precedence = iota PrecYields PrecTakes PrecAssociative PrecEmpty )
func (Precedence) String ¶
func (p Precedence) String() string
type ReductionStrategy ¶
type ReductionStrategy uint8
A ReductionStrategy defines which kind of algorithm should be executed when collecting and running multiple parsing passes.
const ( // ReductionSweep will run a single serial pass after combining data from the first `n` parallel runs. ReductionSweep ReductionStrategy = iota // ReductionParallel will combine adjacent parsing results and recursively run `n-1` parallel runs until one stack remains. ReductionParallel // ReductionMixed will run a limited number of parallel passes, then combine the remaining inputs to perform a final serial pass. ReductionMixed )
func (ReductionStrategy) String ¶
func (s ReductionStrategy) String() string
type RunOptions ¶
type RunOptions struct { Concurrency int InitialConcurrency int ReductionStrategy ReductionStrategy AvgTokenLength int ParallelFactor float64 // contains filtered or unexported fields }
type Runner ¶
type Runner struct { Lexer *Lexer Parser *Grammar Options RunOptions }
type RunnerOpt ¶
type RunnerOpt func(p *Runner)
func WithAverageTokenLength ¶
func WithCPUProfiling ¶
func WithConcurrency ¶
func WithGarbageCollection ¶
func WithLogging ¶
func WithMemoryProfiling ¶
func WithParallelFactor ¶
func WithReductionStrategy ¶
func WithReductionStrategy(strat ReductionStrategy) RunnerOpt
type Scanner ¶
type Scanner struct { Lexer *Lexer // contains filtered or unexported fields }
Scanner implements reading and tokenization.
type Token ¶
type Token struct { Type TokenType Precedence Precedence Value any Next *Token Child *Token LastChild *Token }
func (*Token) Height ¶
Height computes the height of the AST rooted in `t`. It can be used as an evaluation metric for tree-balance, as left/right-skewed trees will have a bigger height compared to balanced trees.
func (*Token) IsTerminal ¶
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
examples
|
|
adder/aopp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
adder/copp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
adder/opp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
expr/aopp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
expr/copp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
expr/opp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
json/aopp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
json/copp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
json/opp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
nested
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
xml/opp
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
xpath
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |
ext
|
|
regex/refactored
Code generated by Gopapageno; DO NOT EDIT.
|
Code generated by Gopapageno; DO NOT EDIT. |