Skip to content

Commit 726b2e7

Browse files
committed
feat: implement ZynPEG 2.0 Phase 1 - grammar IR and runtime
Phase 1 of the new PEG implementation with named bindings: Grammar IR (crates/zyn_peg/src/grammar/): - GrammarIR: Complete grammar representation with metadata - PatternIR: Patterns with named bindings (name:identifier syntax) - ActionIR: Semantic actions (Construct, HelperCall, PassThrough) - ExprIR: Action expressions for AST construction - Hand-written recursive descent parser for .zyn files Runtime (crates/zyn_peg/src/runtime2/): - ParserState: Position tracking, arena integration, bindings - MemoCache: Packrat memoization for O(n) parsing - Combinators: literal, optional, choice, sequence, repeat, etc. This replaces the fragile positional $N captures with named bindings and lays foundation for direct TypedAST code generation.
1 parent 93c21bc commit 726b2e7

8 files changed

Lines changed: 3156 additions & 0 deletions

File tree

crates/zyn_peg/src/grammar/ir.rs

Lines changed: 467 additions & 0 deletions
Large diffs are not rendered by default.

crates/zyn_peg/src/grammar/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Grammar IR and Parser for ZynPEG 2.0
2+
//!
3+
//! This module provides:
4+
//! - `ir.rs`: Intermediate representation for grammar rules with named bindings
5+
//! - `parser.rs`: Parser for the new .zyn grammar syntax
6+
//!
7+
//! The new grammar syntax uses named bindings instead of positional `$N` captures:
8+
//!
9+
//! ```zyn
10+
//! fn_def = { "fn" ~ name:identifier ~ "(" ~ params:fn_params? ~ ")" ~ ret:type_annotation? ~ body:block }
11+
//! -> TypedDeclaration::Function {
12+
//! name: name.text,
13+
//! params: params.unwrap_or_default(),
14+
//! return_type: ret,
15+
//! body: body,
16+
//! }
17+
//! ```
18+
19+
pub mod ir;
20+
pub mod parser;
21+
22+
pub use ir::*;
23+
pub use parser::*;

0 commit comments

Comments
 (0)