Documentation
¶
Index ¶
- func ParseEscape(s string) (rune, int, error)
- type Grammar
- type Node
- func (n *Node) All(label string) []*Node
- func (n *Node) Child(label string) *Node
- func (n *Node) DeepDup() *Node
- func (n *Node) Dump() string
- func (n *Node) Dup() *Node
- func (n *Node) First(label string, start int) *Node
- func (n *Node) ReconstructContent() (string, error)
- func (n *Node) String() string
- type NodeStack
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Grammar ¶
type Node ¶
type Node struct { // Label determines the type of the node, usually corresponding // to the rule name (LHS of the parser rule). Label string // Text is a captured text, if a rule defines a capture region. Text string // Content is a complete text that was consumed during parsing of this // element. Maybe nil if the content was not recorded during parsing, or for // nodes that were programmatically generated. If not nil, len(Content) // should be len(Children) + 1 When present, concatenating node Content in // order with children content results in exactly the parser input. // NOTE: this is not computed during parsing, but at a later stage. Content []string // The byte posittion of the first character consumed by this node rule // during parsing in the buffer that was passed to parser. Pos int // The number of bytes consumed by this node rule. Len int // The line number of the first character consumed by this node. 1-based. Row int // The column number of the first character consumed by this node. 0-based. Col int // The children of this node. Children []*Node // Err caches the error that resulted from application of some parsing rule at some position. Err error // Annotations stores some string-form annotations. Annotations map[string]string // TreeAnnotations stores some tree-form annotations (aka labelled children). TreeAnnotations map[string]*Node // Private fields. // Start is used by the bootstrap parser to implement captures. Parser generator or main parser // do not need it, but they also set it for compatibility with node drop/keep heuristics. // TODO(salikh): Remove after deprecating the bootstrap parser. Start int }
func (*Node) First ¶
First returns the first child with index at least n that has the specified label. If ther is no matching child node, it returns nil.
func (*Node) ReconstructContent ¶
type Result ¶
type Result struct { G *grammar Source string Memo map[int]map[*rule]*Node Level int // Final AST. Tree *Node NodeStack }
Result encapsulates one parse result.
func (*Result) ComputeContent ¶
func (r *Result) ComputeContent()
ComputeContent annotates the parse tree with pieces of original content and line/column positions in the original parser input.
Directories
¶
Path | Synopsis |
---|---|
Package charclass provide functions for handling character class regular expressions.
|
Package charclass provide functions for handling character class regular expressions. |
cmd
Package example provides an example to parse source file according to grammar defined in includes.peg.
|
Package example provides an example to parse source file according to grammar defined in includes.peg. |
Click to show internal directories.
Click to hide internal directories.