parser

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package parser turns source files (Markdown, YAML, JSON) into a unified ContextNode tree.

Index

Constants

View Source
const (
	FormatPlain = "plain"
	FormatToon  = "toon"
)
View Source
const MaxInlineFields = 5

MaxInlineFields is the threshold for promoting a nested map or array to its own ContextNode. Smaller structures stay inlined in the parent's Content.

View Source
const ToonSavingsThreshold = 0.15

ToonSavingsThreshold is the minimum fraction of bytes TOON must save versus plain rendering before it is preferred.

Variables

View Source
var (
	ErrUnsupportedExt = errors.New("unsupported extension")
	ErrInvalidUTF8    = errors.New("invalid UTF-8")
)

Functions

func FlattenMap

func FlattenMap(roots []*ContextNode) map[string]*ContextNode

Types

type ContextNode

type ContextNode struct {
	Children    []*ContextNode
	ID          string
	ParentID    string
	SourceFile  string
	Label       string
	Content     string
	ContentHash string
	Format      string
	Temperature *float64
	Depth       int
	TokenCount  int
	NodeType
}

func Flatten

func Flatten(roots []*ContextNode) []*ContextNode

func Parse

func Parse(path string, r io.Reader) ([]*ContextNode, error)

Read r and route it to a format-specific parser based on path's extension.

func ParseBytes

func ParseBytes(path string, data []byte) ([]*ContextNode, error)

func ParseFile

func ParseFile(path string) ([]*ContextNode, error)

type JsonParser

type JsonParser struct{}

type NodeType

type NodeType string
const (
	NodeHeading  NodeType = "heading"
	NodeList     NodeType = "list"
	NodeTable    NodeType = "table"
	NodeCode     NodeType = "code"
	NodeText     NodeType = "text"
	NodeKV       NodeType = "kv"
	NodePreamble NodeType = "preamble"
)

type ToonParser

type ToonParser struct{}

type YamlParser

type YamlParser struct{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL