[Misc] Validate grammar and fail early (#11119)

This commit is contained in:
Cody Yu
2024-12-12 18:34:26 +00:00
committed by GitHub
parent 5d712571af
commit 2c97eca1ff
2 changed files with 26 additions and 18 deletions
@@ -26,15 +26,11 @@ def grammar_is_likely_lark(grammar_str: str) -> bool:
if not line:
continue
# Look for Lark-style rule definitions
if ':' in line and '::=' not in line:
return True
# Look for GBNF rule definition
if '::=' in line:
return False
# Look for Lark-specific features
if any(pattern in line for pattern in ['?start:', '|', '~']):
return True
return False
return True
def convert_lark_to_gbnf(grammar_str: str) -> str: