Documentation
¶
Overview ¶
Package parse provides tony parsing support.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func GetPositions ¶ added in v0.0.6
func GetPositions(opts ...ParseOption) map[*ir.Node]*token.Pos
GetPositions extracts the positions map from the provided options. This allows consumers (like FromTony methods) to access position information.
func ParseMulti ¶ added in v0.0.6
func ParseMulti(d []byte, opts ...ParseOption) ([]*ir.Node, error)
ParseMulti parses multiple Tony documents separated by '---' from a single byte slice. It preserves global positions for all documents.
Types ¶
type NodeParser ¶ added in v0.0.10
type NodeParser struct {
// contains filtered or unexported fields
}
NodeParser provides incremental parsing of ir.Node from a token source. It uses the existing TokenSource (from token package) for streaming tokenization.
Note: Currently only supports bracketed structures ({...} or [...]). Non-bracketed structures will return an error.
Example usage:
reader := bytes.NewReader([]byte("{key: value}{other: node}"))
source := token.NewTokenSource(reader)
parser := NewNodeParser(source)
for {
node, err := parser.ParseNext()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}
// Process node incrementally
processNode(node)
}
func NewNodeParser ¶ added in v0.0.10
func NewNodeParser(source *token.TokenSource, opts ...ParseOption) *NodeParser
NewNodeParser creates a new NodeParser reading from the given TokenSource.
func (*NodeParser) ParseNext ¶ added in v0.0.10
func (p *NodeParser) ParseNext() (*ir.Node, error)
ParseNext parses the next complete ir.Node from the token source. Returns:
- node: The parsed node, or nil if no more nodes available
- err: Error if parsing fails, or io.EOF if source is exhausted
Supports both bracketed structures ({...} or [...]) and simple values (strings, numbers, booleans, null).
type ParseOption ¶
type ParseOption func(*parseOpts)
func NoBrackets ¶
func NoBrackets() ParseOption
func ParseComments ¶
func ParseComments(v bool) ParseOption
func ParseFormat ¶
func ParseFormat(f format.Format) ParseOption
func ParseJSON ¶
func ParseJSON() ParseOption
func ParsePositions ¶
func ParsePositions(m map[*ir.Node]*token.Pos) ParseOption
func ParseTony ¶
func ParseTony() ParseOption
func ParseYAML ¶
func ParseYAML() ParseOption