this repo has no description
1# Typst math grammar for llama-cli --grammar-file
2#
3# Conservative: enforces balanced brackets/parens/braces and rejects bare
4# unmatched delimiters. Does not fully parse Typst math -- the goal is to
5# eliminate the bracket-mismatch error class with zero training cost, not
6# to validate full Typst semantics.
7#
8# Usage:
9# ./llama-cli ... --grammar-file grammar.gbnf
10#
11# If the model struggles to complete under grammar constraints, widen the
12# grammar by replacing inner rules with `atom` permitting arbitrary chars.
13
14root ::= ws? expr ws?
15
16expr ::= item (ws? item)*
17
18item ::= paren-group
19 | bracket-group
20 | brace-group
21 | script
22 | atom
23
24# Balanced delimiter groups
25paren-group ::= "(" ws? expr? ws? ")"
26bracket-group ::= "[" ws? expr? ws? "]"
27brace-group ::= "{" ws? expr? ws? "}"
28
29# Super/subscript -- bound is a single atom or parenthesised expr
30script ::= "_" bound ("^" bound)?
31 | "^" bound ("_" bound)?
32
33bound ::= paren-group | bracket-group | plain-atom
34
35# Atomic non-grouping token: identifier, number, operator, punctuation.
36# Does NOT include raw (, ), [, ], {, } -- those must be in a group.
37atom ::= plain-atom | "/" | "!" | "'"
38
39plain-atom ::= ident | number | operator
40
41ident ::= [a-zA-Z] [a-zA-Z0-9]*
42number ::= [0-9]+ ("." [0-9]+)?
43operator ::= "+" | "-" | "*" | "=" | "<" | ">" | "<=" | ">=" | "!="
44 | "->" | "<-" | "," | ";" | ":" | "|" | "&" | "~" | "."
45
46ws ::= [ \t\n]+