GRAM { Recipe = Frontmatter? Content? Content = | (nl* Block)* (nl* Section)+ -- explicit | (nl* Block)+ -- implicit Frontmatter = "---" nl KeyValue* "---" (nl | end) emptyLine = sp* nl KeyValue = emptyLine* key ":" sp* value nl key = (alnum | "_" | "-")+ value = (~nl any)* Section = header Block* header = "##" sp+ title headerExtension? sp* nl+ headerExtension = | retroPlanning sp* intermediateDecl? -- retro | intermediateDecl sp* retroPlanning? -- decl titleStop = nl | "->&" | "~{" title = (~titleStop any)* retroPlanning = "~{" (~"}" any)+ "}" Block = | Comment nl* -- comment | (~header step) -- step step = startAction? line (nl line)* (nl+ | end) startAction = "[" (~"]" any)+ "]" sp* line = stepContent+ stepContent = | invalidComposite | invalidAlternativeBar | text | ws | intermediateDecl | applySyntactic | fallback invalidComposite = space+ "<" space* "@" name invalidAlternativeBar = "|" ws = space+ fallback = ~nl any Element = | Ingredient | Cookware | Timer | Temperature | Reference | CommentBlock | Comment intermediateDecl = | "->&" name "{}" -- full | "->&" singleWordName -- bare // Ingredients Ingredient = | Alternative | simpleIngredient Alternative = simpleIngredient ("|" simpleIngredient)+ // Rule: Quantity is mandatory unless it's a single word name // Uses refName (not name) so a bare @&chicken mention can't have its name // greedily swallow everything up to an unrelated later {...} that happens // to close a valid ingredientQuantity -- e.g. "@&chicken for ~{3min}" must // stop at "~" and fall back to the bare alternative, not consume "chicken // for ~" as a bogus multi-word name with the timer's quantity attached. simpleIngredient = | "@" modifier* refName alias? ingredientQuantity preparation? composite? -- full | "@" modifier* singleWordName alias? preparation? composite? -- bare modifier = "?" | "-" | "*" | "&" | "=" alias = ":" refName ingredientQuantity = "{" space* (relativeQuantity | absoluteQuantity) space* "}" relativeQuantity = number space* "%" space* ("@&" | "&") space* name absoluteQuantity = (range | number)? space* (unit space*)? textQuantity = "{" space* (~"}" any)+ space* "}" fixed = "=" unit = unitName unitName = (alnum | sp | "°" | "%")+ preparation = "(" (~")" any)* ")" composite = | "<@" refName ingredientQuantity preparation? -- full | "<@" singleWordName preparation? -- bare // Cookware Cookware = | CookwareAlternative | simpleCookware CookwareAlternative = simpleCookware ("|" simpleCookware)+ // Same refName fix as simpleIngredient above -- a bare #pan mention must not // swallow an unrelated later {...} (e.g. another ingredient's integer-only // quantity) into its own name. simpleCookware = | "#" modifier* refName alias? cookwareQuantity preparation? -- full | "#" modifier* singleWordName alias? preparation? -- bare // Cookware quantity is numbers only, no units (e.g. {}, {2}) -- unlike ingredientQuantity. cookwareQuantity = "{" space* number? space* "}" // Timer Timer = "~" "_"? name? ingredientQuantity // Temperature Temperature = "^" name? (ingredientQuantity | textQuantity) // Comments Comment = "//" (~nl any)* CommentBlock = "/*" (~"*/" any)* "*/" // Primitives name = (~(syntaxChar | nl) any)+ singleWordName = (~(syntaxChar | space | nl | sentencePunct) any)+ sentencePunct = "," | ";" | "!" | "?" | "." // Like name, but also stops at element sigils so a bare &dough is not consumed // into a Reference -- full when a sigil like # or @ appears later on the line. refName = (~(syntaxChar | refSigil | nl) any)+ refSigil = "@" | "#" | "~" | "^" | "&" number = mixedFraction | unicodeFraction | plainNumber plainNumber = digit+ ("." digit+)? ("/" digit+)? mixedFraction = digit+ sp+ digit+ "/" digit+ unicodeFraction = | digit+ unicodeFractionChar -- mixed | unicodeFractionChar -- bare unicodeFractionChar = "¼" | "½" | "¾" | "⅓" | "⅔" | "⅕" | "⅖" | "⅗" | "⅘" | "⅙" | "⅚" | "⅛" | "⅜" | "⅝" | "⅞" range = number space* "-" space* number text = space* (~(elementStart | nl | "|") any)+ Reference = | "&" refName ingredientQuantity -- full | "&" singleWordName -- bare // Delimiters that end a name (start of quantity/alias/preparation/composite/alternative). // @, #, ~, !, &, ?, * are deliberately absent here, so names may contain them freely -- // only elementStart (below) treats those as starting a new element, and only in free text. syntaxChar = "{" | "}" | "[" | "]" | "(" | ")" | "<" | "|" | ":" // Stricter than syntaxChar: used to detect where an element starts within free text. elementStart = "@" | "#" | "~" | "^" | "//" | "/*" | "->&" | "&" nl = "\r"? "\n" sp = " " | "\t" space := sp }