find-rule
Search ANTLR4 grammar rules by exact name, regex, wildcard, or partial match. Retrieve rule definitions, references, and usage counts to debug and understand grammar relationships.
Instructions
Find rules with multiple matching modes: exact, regex, wildcard, or partial matching.
When to use: Locate specific rules, understand rule relationships, or discover rules matching a pattern.
Matching Modes:
Exact (default) - Exact rule name match: rule_name: "expression"
Regex - Regular expression pattern: rule_name: "^[A-Z]+$" match_mode: "regex" (Finds all lexer rules)
Wildcard - Shell-style wildcards (* and ?): rule_name: "expr*" match_mode: "wildcard" (Finds expression, expr, exprStatement, etc.)
rule_name: "stat?" match_mode: "wildcard" (Finds stat1, stat2, stats, etc.)
Partial - Substring/contains search (case-insensitive): rule_name: "token" match_mode: "partial" (Finds tokenList, getToken, TOKEN_TYPE, etc.)
Examples:
All lexer rules: rule_name="^[A-Z]+$", match_mode="regex"
All parser rules: rule_name="^[a-z]+$", match_mode="regex"
Rules starting with "expr": rule_name="expr*", match_mode="wildcard"
Rules containing "statement": rule_name="statement", match_mode="partial"
Returns (exact match):
Rule definition, type, and line number
Referenced rules (fan-out: what this rule uses)
Referencing rules (fan-in: what uses this rule)
Usage count
Returns (pattern match):
All matching rules with their details
Match count
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_file | No | Optional: path to a grammar file to read | |
| rule_name | Yes | Rule name or pattern. For wildcards: * matches any characters, ? matches single character. For regex: use standard regex syntax. | |
| use_regex | No | DEPRECATED: Use match_mode="regex" instead. If true, treats rule_name as regex pattern. | |
| match_mode | No | Matching mode: "exact" (default, exact name), "regex" (regex pattern), "wildcard" (* and ?), "partial" (substring search) | |
| grammar_content | No | The content of the ANTLR4 grammar file |