oobabooga/textgen · error · RuntimeError
expecting newline or end at {remaining_src}
Error message
expecting newline or end at {remaining_src} What it means
Error "expecting newline or end at {remaining_src}" thrown in oobabooga/textgen.
Source
Thrown at modules/grammar/grammar_utils.py:278
def parse_rule(state, src):
name, remaining_src = parse_name(src)
remaining_src = remove_leading_white_space(remaining_src, False)
rule_id = get_symbol_id(state, name)
if remaining_src[:3] != "::=":
raise RuntimeError("expecting ::= at " + remaining_src)
remaining_src = remove_leading_white_space(remaining_src[3:], True)
remaining_src = parse_alternates(state, remaining_src, name, rule_id, False)
if remaining_src and remaining_src[0] == "\r":
remaining_src = remaining_src[2:] if remaining_src[1] == "\n" else remaining_src[1:]
elif remaining_src and remaining_src[0] == "\n":
remaining_src = remaining_src[1:]
elif remaining_src:
raise RuntimeError("expecting newline or end at " + remaining_src)
return remove_leading_white_space(remaining_src, True)
def parse_ebnf(src):
try:
state = ParseState()
grammar_repr = remove_leading_white_space(src, True)
last_grammar_repr = ""
while grammar_repr:
if last_grammar_repr:
last_parsed_rule_len = len(last_grammar_repr) - len(grammar_repr)
logger.debug(f"last_parsed_rule: {last_grammar_repr[:last_parsed_rule_len]}")
last_grammar_repr = grammar_repr
grammar_repr = parse_rule(state, grammar_repr)
state.grammar_encoding.append(0xFFFF)
return state
except RuntimeError as err:
logger.warning("error parsing grammar:", err)View on GitHub (pinned to ed888c71f2)
Solutions
- End each grammar rule with a newline or the end of the input; remove any trailing characters after the rule body.
- Check the grammar text near the reported position for a missing line break between rules.
When it happens
Trigger: Raised while parsing a GBNF grammar string: after a rule expression the parser found extra tokens where it expected a newline or the end of input. Triggers when a grammar rule line contains trailing characters (e.g. an unclosed alternation, stray literal, or missing newline between rules) in the grammar passed to the grammar-constrained generation feature.
Common situations: See trigger scenarios.
AI-assisted analysis of oobabooga/textgen@ed888c71f2 (2026-08-15).
Data as JSON: /api/errors/9596e786c8f7106d.
Report an issue: GitHub.