{2}Open and answer this issue on GitHub.
ready · opened 2026-10-31 · updated 2026-10-31 · 0 comments
Found while writing grammar_hex_digit_is_one_hex_digit.nika (#1002).
grammar Pair {
rule WS = "" -> { }
entry rule top -> String = "#" r:hex_digit{2} g:hex_digit{2} b:hex_digit{2} eof -> { f"{r} {g} {b}" }
}
nikaia fmt turns the long line into
entry rule top -> String = "#" r:hex_digit{
2
} g:hex_digit{2} b:hex_digit{2} eof -> { f"{r} {g} {b}" }
It still parses and runs the same, but the formatter reads the bound {2} as a block and breaks there. A bound is one token group and should never be broken; a long rule is broken between elements, or before ->.
To build
{n}, {m,n}, {m,}) on one line, the same for digit, hex_digit and any element.tests/compiler/tests/fmt_keeps_a_repetition_bound_whole.nika with the rule above, its .stdout the formatted text.