Expand description
Semantic analysis, symbol extraction, and type inference. Scope analysis for variable and subroutine resolution. Scope analysis and variable tracking for Perl parsing workflows
This module provides comprehensive scope analysis for Perl scripts, tracking variable declarations, usage patterns, and potential issues across different scopes within the LSP workflow stages.
§LSP Workflow Integration
Scope analysis supports semantic validation across LSP workflow stages:
- Parse: Identify declarations and scopes during syntax analysis
- Index: Provide scope metadata for symbol indexing
- Navigate: Resolve references with scope-aware lookups
- Complete: Filter completion items based on visible bindings
- Analyze: Report unused, shadowed, and undeclared variables
§Performance
- Time complexity: O(n) over AST nodes with scoped hash lookups
- Space complexity: O(n) for scope tables and variable maps (memory bounded)
- Optimizations: Fast sigil indexing to keep performance stable
- Benchmarks: Typically <5ms for mid-sized files, low ms for large files
- Large file scaling: Designed to scale across large file sets in workspaces
§Usage Examples
ⓘ
use perl_parser::scope_analyzer::{ScopeAnalyzer, IssueKind};
use perl_parser::{Parser, ast::Node};
// Analyze Perl script for scope issues
let script = "my $var = 42; sub hello { print $var; }";
let mut parser = Parser::new(script);
let ast = parser.parse()?;
let analyzer = ScopeAnalyzer::new();
let pragma_map = vec![];
let issues = analyzer.analyze(&ast, script, &pragma_map);
// Check for common scope issues in Perl parsing code
for issue in &issues {
match issue.kind {
IssueKind::UnusedVariable => println!("Unused variable: {}", issue.variable_name),
IssueKind::VariableShadowing => println!("Variable shadowing: {}", issue.variable_name),
_ => {}
}
}