Skip to main content

Crate ryo_pattern

Crate ryo_pattern 

Source
Expand description

RyoPattern - AST pattern matching and lint rules

This crate provides declarative pattern matching for Rust AST nodes, designed for code quality checks and refactoring detection.

§Architecture

┌─────────────────────────────────────────────────────────────┐
│  RyoPattern Core                                             │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  CodePattern ──────► AST node predicate                     │
│       │               (structural matching)                  │
│       ▼                                                      │
│  Query Extension ──► Symbol filter + body + relations       │
│       │                                                      │
│       ▼                                                      │
│  Rule ─────────────► Query + Message + Severity             │
│       │                                                      │
│       ▼                                                      │
│  MatchResult ──────► Bool + Captures { $VAR: Node }         │
│                                                              │
└─────────────────────────────────────────────────────────────┘

§Design Principles

  1. Read-only: Pattern matching is pure detection; mutations are external
  2. Composable: any/all/none logical grouping
  3. Schema-Driven: JSON Schema enables LLM-perfect query generation
  4. Pre-built Graph: Relation queries use pre-computed graphs

Re-exports§

pub use concrete::parse_pattern;
pub use concrete::ConcreteParser;
pub use concrete::ParseError;
pub use concrete::ParseResult;
pub use matcher::BodyScanner;
pub use matcher::ExprMatcher;
pub use matcher::MatchContext;

Modules§

concrete
Concrete Syntax Parser
matcher
Pattern matcher for PureExpr

Structs§

ArmPattern
Match arm pattern for Match expressions
BodyMatch
Body match conditions for symbol bodies
CapturedNode
A captured AST node from pattern matching
CodePattern
AST Pattern for structural matching
Diagnostic
A diagnostic message (Clippy-compatible)
GeneratorLoader
Generator template loader
GeneratorMeta
Generator metadata
GeneratorTemplate
A generator template loaded from YAML
LintConfig
Lint configuration file structure
LintSettings
Global lint settings
MatchAttrs
Match attributes for symbol filtering
MatchResult
Result of pattern matching
NamePattern
Pattern-based name matching
ParamSpec
Parameter specification
PatternQuery
Query for pattern matching (extends RyoQL Query concept)
Position
Position in source code
Relation
Single relation condition
RelationTarget
Simplified target for relation queries
Relations
Relation conditions with logical grouping
Rule
Lint rule definition with optional fix
RuleEngine
Rule execution engine
RuleLoader
Rule loader
RuleOverride
Override for a specific rule
RuleOverrides
Rule overrides configuration
Span
Source span (line/column based)
TargetMatch
Target match conditions
TemplateSpec
Code template specification

Enums§

GeneratorLoadError
Errors from generator loading
InsertPosition
Where to insert the generated code
LoadError
Errors from rule loading
NameMatcher
Name matcher for symbol/method names
NodeKind
AST node type to match
PatternExpr
Pattern expression (recursive)
RelationKind
Relation kind enumeration.
RenderError
Errors during template rendering
Severity
Severity level
SymbolKind
Symbol kind for query filtering
TargetKind
Target symbol kind
TraversalScope
Traversal scope for transitive queries
Visibility
Visibility level

Functions§

interpolate_message
Message interpolation for captured variables