@cooklang Hey, playing around with creating a cooklang parser, I was curious about certain underdefined aspects of the spec. e.g.

• Can ingredients/times appear in section-headings or notes like "== Cook @potatoes{3} ==" or "> I prefer to bake for ~{25%minutes}" (playground says no)

• Is there an expected/controlled vocabulary of YAML front-matter?

• Should step-count reset across section headings? (playground says yes)

• should [- … -] comments be greedy or nestable? (e.g. various parsings for things like "this [- is [- a test -] comment -]" (playground interprets this as "this comment -]", not nesting)

• when comments are stripped, should the leading/trailing whitespace be preserved or collapsed? E.g. "this [- has space before & after -] here" → "this␣␣here" or "this␣here"

• when doing an inclusion, what should happen with included front-matter in that context? similarly, should counters be preserved/pushed and then popped after emitting the included sub-recipe?

So here's my contribution to @cooklang fun: a rough parser/formatter written in about 330 lines of awk(1) code (plus some bloaty template-variable constants that push the actual line-count to more like 540):

https://github.com/Gumnos/awkcook

It provides plaintext, ANSI, and HTML-fragment output, and should run in One True Awk, GNU awk, and other variants.

$ ./cook.awk -- --ansi guacamole.cook | less -R

GitHub - Gumnos/awkcook: a cooklang formatter written in awk

a cooklang formatter written in awk. Contribute to Gumnos/awkcook development by creating an account on GitHub.

GitHub
@gumnos that’s the spirit!

@cooklang I wasn't quite sure what the appropriate output should be if a single ingredient/cookware was provided more than once such as

"Turn the #skillet on Medium heat. Once hot, crack the @eggs into the #skillet. After ~{2%min} flip the @eggs over."

The Playground puts "eggs" and "skillet" in the output twice, but I had mine deduplicate them instead:

https://github.com/Gumnos/awkcook/blob/main/cook.awk#L69-L73

which looked less confusing to me. Thoughts?

awkcook/cook.awk at main · Gumnos/awkcook

a cooklang formatter written in awk. Contribute to Gumnos/awkcook development by creating an account on GitHub.

GitHub