Documentation
¶
Index ¶
- Constants
- Variables
- func RunPass[T AST](ctx *Context, asts []T, pass Pass)
- type AST
- type Action
- type ActionDiscard
- type ActionEmit
- type ActionPopMode
- type ActionPushMode
- type Associativity
- type Bounds
- type Card
- type CharClass
- type CharClassBinaryExpr
- type CharClassBinaryExprOp
- type CharClassExpr
- type CharClassItem
- type Context
- func (c *Context) Analyze(ast AST, untilPass Pass) bool
- func (c *Context) CreateAlias(name string, t *TokenRule)
- func (c *Context) CreateMode(name string) *mode.ModeBuilder
- func (c *Context) Lookup(name string) AST
- func (c *Context) LookupAlias(name string) *TokenRule
- func (c *Context) Mode() *mode.ModeBuilder
- func (c *Context) Position(ast AST) gotoken.Pos
- func (c *Context) Print(ast AST, out io.Writer)
- func (c *Context) RegisterName(name string, ast AST) bool
- type DiscardStatement
- type ExternalName
- type ExternalRule
- type FragRule
- type LexerExpr
- type LexerFactor
- type LexerTerm
- type LexerTermCard
- type LexerTermCharClass
- type LexerTermLiteral
- type LexerTermRef
- type MacroRule
- type Mode
- type ParserProd
- type ParserRule
- type ParserTerm
- type ParserTermType
- type Pass
- type Printer
- type ProdQualifier
- type Spec
- type Statement
- type TokenRule
- type Unit
Constants ¶
View Source
const DefaultModeName = "$default"
View Source
const Print = 1000
Variables ¶
View Source
var AmbiguousAlias = &TokenRule{}
View Source
var DiscardStatementSingleton = &DiscardStatement{}
DiscardStatementSingleton is a singleton for DiscardStatement. It works because DiscardStatement has no data and will be discarded by the parser.
Functions ¶
Types ¶
type Action ¶
type Action interface {
AST
// GetAction returns the mode.Action corresponding to the AST.
GetAction() mode.Action
}
Action is the interface implemented by ASTs that define actions for tokens and fragments.
type ActionDiscard ¶
type ActionDiscard struct {
// contains filtered or unexported fields
}
ActionDiscard is the AST for the action @discard.
E.g.
// Discard whitespaces. @frag [ \n\r\t]+ @discard;
func (*ActionDiscard) GetAction ¶
func (a *ActionDiscard) GetAction() mode.Action
func (*ActionDiscard) RunPass ¶
func (a *ActionDiscard) RunPass(ctx *Context, pass Pass)
type ActionEmit ¶
type ActionEmit struct {
Name string
Terminal *lr1.Terminal
// contains filtered or unexported fields
}
func (*ActionEmit) GetAction ¶
func (a *ActionEmit) GetAction() mode.Action
func (*ActionEmit) RunPass ¶
func (a *ActionEmit) RunPass(ctx *Context, pass Pass)
type ActionPopMode ¶
type ActionPopMode struct {
// contains filtered or unexported fields
}
ActionPopMode is the AST for the action @pop_mode.
Example:
@mode StringLiteral {
STRING = '"' @pop_mode ;
@frag [\u0020-\U0010FFFF]* ;
}
func (*ActionPopMode) GetAction ¶
func (a *ActionPopMode) GetAction() mode.Action
func (*ActionPopMode) RunPass ¶
func (a *ActionPopMode) RunPass(ctx *Context, pass Pass)
type ActionPushMode ¶
type ActionPushMode struct {
Mode string
// contains filtered or unexported fields
}
ActionPushMode is the AST for the action @push_mode.
Example:
@frag '"' @push_mode(StringLiteral) ;
func (*ActionPushMode) GetAction ¶
func (a *ActionPushMode) GetAction() mode.Action
func (*ActionPushMode) RunPass ¶
func (a *ActionPushMode) RunPass(ctx *Context, pass Pass)
type Associativity ¶
type Associativity int
const ( Left Associativity = 0 Right Associativity = 1 )
type CharClass ¶
type CharClass struct {
Neg bool
CharClassItems []*CharClassItem
// contains filtered or unexported fields
}
type CharClassBinaryExpr ¶
type CharClassBinaryExpr struct {
Op CharClassBinaryExprOp
Left CharClassExpr
Right CharClassExpr
// contains filtered or unexported fields
}
func (*CharClassBinaryExpr) GetRanges ¶
func (e *CharClassBinaryExpr) GetRanges() []rang3.Range
func (*CharClassBinaryExpr) RunPass ¶
func (e *CharClassBinaryExpr) RunPass(ctx *Context, pass Pass)
type CharClassBinaryExprOp ¶
type CharClassBinaryExprOp int
const ( CharClassBinaryExprAdd CharClassBinaryExprOp = 0 CharClassBinaryExprSub CharClassBinaryExprOp = 1 )
type CharClassExpr ¶
type CharClassItem ¶
func (*CharClassItem) RunPass ¶
func (i *CharClassItem) RunPass(ctx *Context, pass Pass)
type Context ¶
type Context struct {
FSet *gotoken.FileSet
Errs *errlogger.ErrLogger
StartParserRule *ParserRule
HasParserRules bool
CurrentUnit stack.Stack[*Unit]
CurrentParserRule stack.Stack[*ParserRule]
CurrentParserProd stack.Stack[*ParserProd]
CurrentPrinter stack.Stack[*Printer]
CurrentLexerMode stack.Stack[*mode.ModeBuilder]
Grammar *lr1.Grammar
LexerModes map[string]*mode.ModeBuilder
LexerDFAs map[string]*mode.Mode
// contains filtered or unexported fields
}
func (*Context) CreateAlias ¶
func (*Context) CreateMode ¶
func (c *Context) CreateMode(name string) *mode.ModeBuilder
func (*Context) LookupAlias ¶
func (*Context) Mode ¶
func (c *Context) Mode() *mode.ModeBuilder
type DiscardStatement ¶
type DiscardStatement struct{}
DiscardStatement is a dummy Statement that will be discarded by the parser. It is used with the *! cardinality which makes the parser call the Discard() method.
func (*DiscardStatement) Bounds ¶
func (s *DiscardStatement) Bounds() Bounds
func (*DiscardStatement) Discard ¶
func (n *DiscardStatement) Discard() bool
func (*DiscardStatement) RunPass ¶
func (n *DiscardStatement) RunPass(ctx *Context, pass Pass)
func (*DiscardStatement) SetBounds ¶
func (s *DiscardStatement) SetBounds(b Bounds)
type ExternalName ¶
type ExternalName struct {
Name string
// contains filtered or unexported fields
}
func (*ExternalName) RunPass ¶
func (n *ExternalName) RunPass(ctx *Context, pass Pass)
type ExternalRule ¶
type ExternalRule struct {
Names []*ExternalName
// contains filtered or unexported fields
}
func (*ExternalRule) RunPass ¶
func (r *ExternalRule) RunPass(ctx *Context, pass Pass)
type LexerExpr ¶
type LexerExpr struct {
Factors []*LexerFactor
// contains filtered or unexported fields
}
type LexerFactor ¶
type LexerFactor struct {
Terms []*LexerTermCard
// contains filtered or unexported fields
}
func (*LexerFactor) NFACons ¶
func (f *LexerFactor) NFACons(ctx *Context) *mode.NFAComposite
func (*LexerFactor) RunPass ¶
func (f *LexerFactor) RunPass(ctx *Context, pass Pass)
type LexerTermCard ¶
func (*LexerTermCard) NFACons ¶
func (t *LexerTermCard) NFACons(ctx *Context) *mode.NFAComposite
func (*LexerTermCard) RunPass ¶
func (t *LexerTermCard) RunPass(ctx *Context, pass Pass)
type LexerTermCharClass ¶
type LexerTermCharClass struct {
Expr CharClassExpr
// contains filtered or unexported fields
}
func (*LexerTermCharClass) NFACons ¶
func (t *LexerTermCharClass) NFACons(ctx *Context) *mode.NFAComposite
func (*LexerTermCharClass) RunPass ¶
func (t *LexerTermCharClass) RunPass(ctx *Context, pass Pass)
type LexerTermLiteral ¶
type LexerTermLiteral struct {
Literal string
// contains filtered or unexported fields
}
func (*LexerTermLiteral) NFACons ¶
func (t *LexerTermLiteral) NFACons(ctx *Context) *mode.NFAComposite
func (*LexerTermLiteral) RunPass ¶
func (t *LexerTermLiteral) RunPass(ctx *Context, pass Pass)
type LexerTermRef ¶
type LexerTermRef struct {
Ref string
// contains filtered or unexported fields
}
func (*LexerTermRef) NFACons ¶
func (t *LexerTermRef) NFACons(ctx *Context) *mode.NFAComposite
func (*LexerTermRef) RunPass ¶
func (t *LexerTermRef) RunPass(ctx *Context, pass Pass)
type Mode ¶
type Mode struct {
Name string
Rules []Statement
Mode *mode.ModeBuilder
// contains filtered or unexported fields
}
type ParserProd ¶
type ParserProd struct {
Terms []*ParserTerm
Qualifier *ProdQualifier
Prod *lr1.Prod
// contains filtered or unexported fields
}
func (*ParserProd) RunPass ¶
func (p *ParserProd) RunPass(ctx *Context, pass Pass)
type ParserRule ¶
type ParserRule struct {
IsStart bool
Name string
Prods []*ParserProd
Rule *lr1.Rule
// contains filtered or unexported fields
}
func (*ParserRule) RunPass ¶
func (r *ParserRule) RunPass(ctx *Context, pass Pass)
type ParserTerm ¶
type ParserTerm struct {
Type ParserTermType
Name string
Alias string
Child *ParserTerm
Sep *ParserTerm
Symbol lr1.Term
// contains filtered or unexported fields
}
func (*ParserTerm) RunPass ¶
func (t *ParserTerm) RunPass(ctx *Context, pass Pass)
type ParserTermType ¶
type ParserTermType int
const ( ParserTermSimple ParserTermType = iota ParserTermZeroOrMore // * ParserTermZeroOrMoreF // *! ParserTermOneOrMore // + ParserTermOneOrMoreF // +! ParserTermZeroOrOne // ? ParserTermList // @list ParserTermListOpt // @list? ParserTermError // @error )
func (ParserTermType) String ¶
func (t ParserTermType) String() string
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
func NewPrinter ¶
func (*Printer) WithIndent ¶
type ProdQualifier ¶
type ProdQualifier struct {
Precedence int
Associativity Associativity
// contains filtered or unexported fields
}
type Spec ¶
type Spec struct {
Units []*Unit
DefaultLexerMode *mode.ModeBuilder
// contains filtered or unexported fields
}
Source Files
¶
- action.go
- ast.go
- char_class.go
- char_class_expr.go
- context.go
- external_rule.go
- lexer_expr.go
- lexer_factor.go
- lexer_frag_rule.go
- lexer_mode.go
- lexer_term_card.go
- lexer_term_char_class.go
- lexer_term_literal.go
- lexer_term_ref.go
- lexer_token_rule.go
- macro_rule.go
- parser_prod.go
- parser_rule.go
- parser_term.go
- printer.go
- spec.go
- unit.go
Click to show internal directories.
Click to hide internal directories.