#!/usr/bin/env python3
"""Test which Lark grammars can be loaded."""

from pathlib import Path
import lark


def test_grammar(path: Path) -> tuple[bool, str]:
    """Try to load a Lark grammar and return (success, error_msg)."""
    try:
        content = path.read_text()
        parser = lark.Lark(content, parser='earley')
        return True, f"Loaded successfully - {len(parser.rules)} rules"
    except Exception as e:
        return False, str(e)[:200]


def main():
    lark_dir = Path(__file__).parent / 'lark'

    print("Testing Lark grammar loading:\n")

    for grammar_file in sorted(lark_dir.glob('*.lark')):
        success, msg = test_grammar(grammar_file)
        status = "✓" if success else "✗"
        print(f"{status} {grammar_file.name}")
        print(f"  {msg}\n")


if __name__ == '__main__':
    main()
