Share variable scope and the walk over a document's nodes

Flatten and Validate read nodes through one walk, and the parser, flattener,
validator and writer set variables through one type.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 18:20:35 +00:00
co-authored by Claude Sonnet 5.5
parent cc484ac3ef
commit 1bb842589e
5 changed files with 129 additions and 104 deletions
+3 -3
View File
@@ -123,7 +123,7 @@ func Includes(text []byte) []string {
// parser reads a document's files, keeping the variables defined so far.
type parser struct {
parseConfig
defines map[string]string
defines defines
// including holds the files being read, to refuse an include loop.
including []string
bytes int
@@ -131,7 +131,7 @@ type parser struct {
}
func newParser(opts []ParseOption) *parser {
p := &parser{parseConfig: parseConfig{limits: DefaultLimits}, defines: map[string]string{}}
p := &parser{parseConfig: parseConfig{limits: DefaultLimits}, defines: defines{}}
for _, o := range opts {
o(&p.parseConfig)
}
@@ -201,7 +201,7 @@ func (p *parser) file(name string, data []byte, depth int) (*File, error) {
if err != nil {
return nil, err
}
p.defines[n.Name] = strings.TrimSpace(value)
p.defines.set(n.Name, value)
case KindOpcode, KindText:
// Flattening and writing expand these again, so what they make counts.
if strings.Contains(n.Raw, "$") {