Oak Tcl Parser
A high-performance Tcl parser for Rust, built with the Oak parser combinator framework. Parse Tool Command Language scripts with comprehensive AST generation and error handling.
Overview
Oak Tcl provides robust parsing capabilities for Tcl script files, supporting commands, procedures, control structures, and all major Tcl constructs. Built on the Oak parser combinator framework, it delivers excellent performance and detailed error messages.
Features
- ✅ Complete Tcl Support: Parse commands, procedures, control structures, and variables
- ✅ Modern Rust API: Type-safe parsing with comprehensive error handling
- ✅ High Performance: Built on the efficient Oak parser combinator framework
- ✅ Rich AST: Detailed Abstract Syntax Tree with source location tracking
- ✅ Extensible: Easy to extend for custom Tcl dialects
- ✅ Well Tested: Comprehensive test suite with real-world examples
Quick Start
Parsing Examples
Basic Command Parsing
use ;
use ;
Procedure Definition
use ;
use ;
Advanced Features
Lists and Arrays
Oak Tcl supports parsing complex list operations:
use ;
use ;
let mut session = default;
let parser = new;
let source = new;
let result = parser.parse;
Regular Expressions
Parse regexp operations:
let source = r#"
set text "Hello World 123"
set pattern {\d+}
if {[regexp $pattern $text match]} {
puts "Found number: $match"
}
set result [regsub $pattern $text "XXX"]
puts "Modified: $result"
"#;
AST Structure
The parser generates a rich AST with the following main node types:
TclFile- Root node containing the entire fileCommand- Tcl commands with argumentsProcedure- Procedure definitions with parameters and bodyVariable- Variable references and assignmentsExpression- Expressions in square bracketsList- List literals and operationsControlFlow- if, while, for, foreach statementsString- String literals with interpolation
Performance
Oak Tcl is designed for high performance:
- Zero-copy parsing where possible
- Streaming support for large script files
- Efficient memory usage with minimal allocations
- Fast error recovery for better developer experience
Integration
Oak Tcl integrates seamlessly with the Oak ecosystem:
use ;
use TclLanguage;
// Use with other Oak parsers
let mut parser = new;
let result = parser.parse;
Examples
More examples can be found in the examples directory:
Contributing
We welcome contributions! Please see our Contributing Guide for details.