grammar-metrics
Analyze ANTLR4 grammar complexity and dependencies to identify optimization opportunities and estimate parsing performance.
Instructions
Calculate comprehensive grammar metrics including branching estimation, complexity, and dependencies.
When to use: Understanding grammar complexity, identifying optimization opportunities, estimating parsing performance.
Metrics included:
Size Metrics:
Total/parser/lexer rule counts
Fragment counts
Lines of code, average rule length
Branching Metrics:
Average/max alternatives per rule
Branching depth (subrule nesting)
Branching distribution (1-2, 3-5, 6-10, 10+)
Rules with most branching
Complexity Metrics:
Cyclomatic complexity (per rule and total)
Recursive rules detection
Estimated parse complexity (low/medium/high/very-high)
Dependency Metrics:
Fan-in/fan-out averages
Orphan rules (unused)
Hub rules (highly referenced)
Most referenced rules
Example: from_file: "MyGrammar.g4"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_file | No | Optional: path to a grammar file to read | |
| grammar_content | No | The ANTLR4 grammar file content |