Building a YAML Frontmatter Parser From Scratch in Go

How GAX parses nested lists like amaterasu.files and seals[].body without yaml.v3 library.

# golang # parser # tutorial

Building a YAML Frontmatter Parser From Scratch in Go

12 Aug 2026

Most SSG use yaml.v3. I didn't. I built my own.

Problem: nested list like this:


amaterasu:
  seals:
    - id: I
      body:
        - text: "Itachi summons"

Old code used regex {% for %}.*?{% endfor %} - it matched first endfor, so inner loop ate outer loop.

Fix: depth counting.


depth := 1
for depth > 0 {
  nextFor := Index("{% for")
  nextEnd := Index("{% endfor %}")
  if nextFor < nextEnd { depth++ } else { depth-- }
}

Now nested 10 levels also works. Same trick used by real compilers.


GAX GO Static Site Generator Built with GAX