Documentation
¶
Index ¶
Constants ¶
const ( // EOT represents "end of file" token name. Its value corresponds to "End Of Text" // control character of ASCII standard. EOT = "\x03" // Literal is pseudo--name for a token indicating that its name should be the actual value of token. Literal = "__literal__" // Skip is pseudo--name for token that lexer should ignore. Skip = "Skip" )
const MaxTokenSize = 128
MaxTokenSize is the maximum number of character of a token
Variables ¶
This section is empty.
Functions ¶
func SortPatternOptionsByLength ¶
SortPatternOptionsByLength sort pattern alternatives like `<a1>|<a2>|<a3>` in such a way that ensures longest--matching by regex package.
Types ¶
type Grammar ¶
type Grammar struct {
Term utils.Set[string]
NonTerm utils.Set[string]
Start string
Prod map[string][][]string
}
func NewGrammarFromProd ¶
func (*Grammar) FirstTable ¶
func (g *Grammar) FirstTable() table
func (*Grammar) FollowTable ¶
func (*Grammar) ParseTable ¶
func (g *Grammar) ParseTable(start string) (ParseTable, error)
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer represent an object that can provide a sequence of Token
func (*Lexer) Current ¶
Current returns last token consumed. If lexer reached EOF, Current returns a token with name that equals EOT.
type ParseTable ¶
type ParseTable map[string]map[string]ParseTableCell
ParseTable maps a (non-term, term) to a sentential form
type ParseTableCell ¶
type ParseTree ¶
func (ParseTree) LeveledChildren ¶
LeveledChildren returns a flat view of annidated (under named target nodes) children
Example with target:
a ├ b │ ├ c │ └ b │ ├ d │ └ e └ f └ h = [c, d, e, f]
func (ParseTree) RootString ¶
func (ParseTree) VisitChildren ¶
func (pt ParseTree) VisitChildren(v utils.TreeVisitor)
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is an object capable of constructing a parse tree from a grammar and a reader. After initialization is secure for multiple go ruotine to use same object.
func New ¶
func New(parseTable ParseTable, terminal utils.Set[string], start string, tokenDefs TokenDefs) *Parser
parseTable and tokenDefs should not be modified after
func NewFromGrammar ¶
parseTable and tokenDefs should not be modified after
type ProductionNode ¶
type ProductionNode struct {
// contains filtered or unexported fields
}
func (ProductionNode) Alternative ¶
func (p ProductionNode) Alternative() int
func (ProductionNode) String ¶
func (p ProductionNode) String() string