rhai-analyzer
Static analysis utilities for Rhai scripts.
Why this exists
rhai-analyzer provides a way to extract information from a compiled rhai::AST without executing it. This is useful for:
- Dependency Tracking: Identify which external variables or data paths a script depends on (e.g.,
input.value,settings.mode). - Schema Validation: Ensure a script only accesses allowed variables.
- Optimization: Pre-calculate or pre-fetch data based on what the script is guaranteed (or likely) to access.
Features
- Variable Path Extraction: Collects all unique, fully-qualified variable paths (e.g.,
user.profile.name) accessed in a script. - Local Variable Tracking: Identifies variables defined within the script (via
letor loop iterations) to distinguish them from external dependencies. - String Comparison Analysis: Maps variable paths to the literal strings they are compared against (via
==or!=). - Domain Agnostic: The analyzer doesn't make assumptions about your data model—it just reports what it finds.
Installation
Add via Cargo
Manual Configuration
Add the following to your Cargo.toml:
[]
= "0.1.0"
= "1.22.2"
Usage
1. Analyzing a Script
use Engine;
use analyze_ast;
2. Result Data Structure
The analyze_ast function returns a ScriptAnalysisResult:
License
- MIT license (http://opensource.org/licenses/MIT)