Documentation
¶
Overview ¶
Package ast defines the abstract syntax tree for the PEG grammar.
The parser generator's PEG grammar generates a tree using this package that is then converted by the builder to the simplified AST used in the generated parser.
Index ¶
- type ActionExpr
- type AndCodeExpr
- type AndExpr
- type AnyMatcher
- type CharClassMatcher
- type ChoiceExpr
- type CodeBlock
- type Expression
- type Grammar
- type Identifier
- type LabeledExpr
- type LitMatcher
- type NotCodeExpr
- type NotExpr
- type OneOrMoreExpr
- type Pos
- type Rule
- type RuleRefExpr
- type SeqExpr
- type StringLit
- type ZeroOrMoreExpr
- type ZeroOrOneExpr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionExpr ¶
type ActionExpr struct { Expr Expression Code *CodeBlock FuncIx int // contains filtered or unexported fields }
ActionExpr is an expression that has an associated block of code to execute when the expression matches.
func NewActionExpr ¶
func NewActionExpr(p Pos) *ActionExpr
NewActionExpr creates a new action expression at the specified position.
func (*ActionExpr) Pos ¶
func (a *ActionExpr) Pos() Pos
Pos returns the starting position of the node.
func (*ActionExpr) String ¶
func (a *ActionExpr) String() string
String returns the textual representation of a node.
type AndCodeExpr ¶
AndCodeExpr is a zero-length matcher that is considered a match if the code block returns true.
func NewAndCodeExpr ¶
func NewAndCodeExpr(p Pos) *AndCodeExpr
NewAndCodeExpr creates a new and (&) code expression at the specified position.
func (*AndCodeExpr) Pos ¶
func (a *AndCodeExpr) Pos() Pos
Pos returns the starting position of the node.
func (*AndCodeExpr) String ¶
func (a *AndCodeExpr) String() string
String returns the textual representation of a node.
type AndExpr ¶
type AndExpr struct { Expr Expression // contains filtered or unexported fields }
AndExpr is a zero-length matcher that is considered a match if the expression it contains is a match.
func NewAndExpr ¶
NewAndExpr creates a new and (&) expression at the specified position.
type AnyMatcher ¶
type AnyMatcher struct {
// contains filtered or unexported fields
}
AnyMatcher is a matcher that matches any character except end-of-file.
func NewAnyMatcher ¶
func NewAnyMatcher(p Pos, v string) *AnyMatcher
NewAnyMatcher creates a new any matcher at the specified position. The value is provided for completeness' sake, but it is always the dot.
func (*AnyMatcher) Pos ¶
func (a *AnyMatcher) Pos() Pos
Pos returns the starting position of the node.
func (*AnyMatcher) String ¶
func (a *AnyMatcher) String() string
String returns the textual representation of a node.
type CharClassMatcher ¶
type CharClassMatcher struct { IgnoreCase bool Inverted bool Chars []rune Ranges []rune // pairs of low/high range UnicodeClasses []string // contains filtered or unexported fields }
CharClassMatcher is a character class matcher. The value to match must be one of the specified characters, in a range of characters, or in the Unicode classes of characters.
func NewCharClassMatcher ¶
func NewCharClassMatcher(p Pos, raw string) *CharClassMatcher
NewCharClassMatcher creates a new character class matcher at the specified position and with the specified raw value. It parses the raw value into the list of characters, ranges and Unicode classes.
func (*CharClassMatcher) Pos ¶
func (c *CharClassMatcher) Pos() Pos
Pos returns the starting position of the node.
func (*CharClassMatcher) String ¶
func (c *CharClassMatcher) String() string
String returns the textual representation of a node.
type ChoiceExpr ¶
type ChoiceExpr struct { Alternatives []Expression // contains filtered or unexported fields }
ChoiceExpr is an ordered sequence of expressions. The parser tries to match any of the alternatives in sequence and stops at the first one that matches.
func NewChoiceExpr ¶
func NewChoiceExpr(p Pos) *ChoiceExpr
NewChoiceExpr creates a choice expression at the specified position.
func (*ChoiceExpr) Pos ¶
func (c *ChoiceExpr) Pos() Pos
Pos returns the starting position of the node.
func (*ChoiceExpr) String ¶
func (c *ChoiceExpr) String() string
String returns the textual representation of a node.
type CodeBlock ¶
type CodeBlock struct {
// contains filtered or unexported fields
}
CodeBlock represents a code block.
func NewCodeBlock ¶
NewCodeBlock creates a new code block at the specified position and with the specified value. The value includes the outer braces.
type Expression ¶
type Expression interface {
Pos() Pos
}
Expression is the interface implemented by all expression types.
type Grammar ¶
Grammar is the top-level node of the AST for the PEG grammar.
func NewGrammar ¶
NewGrammar creates a new grammar at the specified position.
type Identifier ¶
type Identifier struct {
// contains filtered or unexported fields
}
Identifier represents an identifier.
func NewIdentifier ¶
func NewIdentifier(p Pos, name string) *Identifier
NewIdentifier creates a new identifier at the specified position and with the specified name.
func (*Identifier) Pos ¶
func (i *Identifier) Pos() Pos
Pos returns the starting position of the node.
func (*Identifier) String ¶
func (i *Identifier) String() string
String returns the textual representation of a node.
type LabeledExpr ¶
type LabeledExpr struct { Label *Identifier Expr Expression // contains filtered or unexported fields }
LabeledExpr is an expression that has an associated label. Code blocks can access the value of the expression using that label, that becomes a local variable in the code.
func NewLabeledExpr ¶
func NewLabeledExpr(p Pos) *LabeledExpr
NewLabeledExpr creates a new labeled expression at the specified position.
func (*LabeledExpr) Pos ¶
func (l *LabeledExpr) Pos() Pos
Pos returns the starting position of the node.
func (*LabeledExpr) String ¶
func (l *LabeledExpr) String() string
String returns the textual representation of a node.
type LitMatcher ¶
type LitMatcher struct { IgnoreCase bool // contains filtered or unexported fields }
LitMatcher is a string literal matcher. The value to match may be a double-quoted string, a single-quoted single character, or a back-tick quoted raw string.
func NewLitMatcher ¶
func NewLitMatcher(p Pos, v string) *LitMatcher
NewLitMatcher creates a new literal matcher at the specified position and with the specified value.
func (*LitMatcher) Pos ¶
func (l *LitMatcher) Pos() Pos
Pos returns the starting position of the node.
func (*LitMatcher) String ¶
func (l *LitMatcher) String() string
String returns the textual representation of a node.
type NotCodeExpr ¶
NotCodeExpr is a zero-length matcher that is considered a match if the code block returns false.
func NewNotCodeExpr ¶
func NewNotCodeExpr(p Pos) *NotCodeExpr
NewNotCodeExpr creates a new not (!) code expression at the specified position.
func (*NotCodeExpr) Pos ¶
func (n *NotCodeExpr) Pos() Pos
Pos returns the starting position of the node.
func (*NotCodeExpr) String ¶
func (n *NotCodeExpr) String() string
String returns the textual representation of a node.
type NotExpr ¶
type NotExpr struct { Expr Expression // contains filtered or unexported fields }
NotExpr is a zero-length matcher that is considered a match if the expression it contains is not a match.
func NewNotExpr ¶
NewNotExpr creates a new not (!) expression at the specified position.
type OneOrMoreExpr ¶
type OneOrMoreExpr struct { Expr Expression // contains filtered or unexported fields }
OneOrMoreExpr is an expression that can be matched one or more times.
func NewOneOrMoreExpr ¶
func NewOneOrMoreExpr(p Pos) *OneOrMoreExpr
NewOneOrMoreExpr creates a new one or more expression at the specified position.
func (*OneOrMoreExpr) Pos ¶
func (o *OneOrMoreExpr) Pos() Pos
Pos returns the starting position of the node.
func (*OneOrMoreExpr) String ¶
func (o *OneOrMoreExpr) String() string
String returns the textual representation of a node.
type Rule ¶
type Rule struct { Name *Identifier DisplayName *StringLit Expr Expression // contains filtered or unexported fields }
Rule represents a rule in the PEG grammar. It has a name, an optional display name to be used in error messages, and an expression.
func NewRule ¶
func NewRule(p Pos, name *Identifier) *Rule
NewRule creates a rule with at the specified position and with the specified name as identifier.
type RuleRefExpr ¶
type RuleRefExpr struct { Name *Identifier // contains filtered or unexported fields }
RuleRefExpr is an expression that references a rule by name.
func NewRuleRefExpr ¶
func NewRuleRefExpr(p Pos) *RuleRefExpr
NewRuleRefExpr creates a new rule reference expression at the specified position.
func (*RuleRefExpr) Pos ¶
func (r *RuleRefExpr) Pos() Pos
Pos returns the starting position of the node.
func (*RuleRefExpr) String ¶
func (r *RuleRefExpr) String() string
String returns the textual representation of a node.
type SeqExpr ¶
type SeqExpr struct { Exprs []Expression // contains filtered or unexported fields }
SeqExpr is an ordered sequence of expressions, all of which must match if the SeqExpr is to be a match itself.
func NewSeqExpr ¶
NewSeqExpr creates a new sequence expression at the specified position.
type StringLit ¶
type StringLit struct {
// contains filtered or unexported fields
}
StringLit represents a string literal.
func NewStringLit ¶
NewStringLit creates a new string literal at the specified position and with the specified value.
type ZeroOrMoreExpr ¶
type ZeroOrMoreExpr struct { Expr Expression // contains filtered or unexported fields }
ZeroOrMoreExpr is an expression that can be matched zero or more times.
func NewZeroOrMoreExpr ¶
func NewZeroOrMoreExpr(p Pos) *ZeroOrMoreExpr
NewZeroOrMoreExpr creates a new zero or more expression at the specified position.
func (*ZeroOrMoreExpr) Pos ¶
func (z *ZeroOrMoreExpr) Pos() Pos
Pos returns the starting position of the node.
func (*ZeroOrMoreExpr) String ¶
func (z *ZeroOrMoreExpr) String() string
String returns the textual representation of a node.
type ZeroOrOneExpr ¶
type ZeroOrOneExpr struct { Expr Expression // contains filtered or unexported fields }
ZeroOrOneExpr is an expression that can be matched zero or one time.
func NewZeroOrOneExpr ¶
func NewZeroOrOneExpr(p Pos) *ZeroOrOneExpr
NewZeroOrOneExpr creates a new zero or one expression at the specified position.
func (*ZeroOrOneExpr) Pos ¶
func (z *ZeroOrOneExpr) Pos() Pos
Pos returns the starting position of the node.
func (*ZeroOrOneExpr) String ¶
func (z *ZeroOrOneExpr) String() string
String returns the textual representation of a node.