synkit_core/traits/
mod.rs

1//! Core traits for the synkit parsing framework.
2//!
3//! This module defines the fundamental traits that enable synkit's parsing
4//! capabilities. Implementations of these traits work together to provide
5//! a flexible, type-safe parsing infrastructure.
6//!
7//! # Trait Hierarchy
8//!
9//! ```text
10//! TokenStream (stream interface)
11//!     ├── parse::<T>() where T: Parse
12//!     └── peek::<T>() where T: Peek
13//!
14//! SpanLike (position tracking)
15//!     └── SpannedLike<T> (value + span)
16//!
17//! ToTokens (code generation)
18//!     └── Printer (formatting)
19//!
20//! Diagnostic (error reporting)
21//!     └── SpannedError (error + span)
22//! ```
23//!
24//! # Usage Patterns
25//!
26//! ## Parsing
27//!
28//! ```ignore
29//! use synkit::{TokenStream, Parse};
30//!
31//! fn parse_expression(stream: &mut impl TokenStream) -> Result<Expr, Error> {
32//!     // Peek to decide which production to use
33//!     if stream.peek::<NumberToken>() {
34//!         let num = stream.parse::<NumberLiteral>()?;
35//!         Ok(Expr::Number(num))
36//!     } else if stream.peek::<IdentToken>() {
37//!         let ident = stream.parse::<Identifier>()?;
38//!         Ok(Expr::Ident(ident))
39//!     } else {
40//!         Err(Error::unexpected_token())
41//!     }
42//! }
43//! ```
44//!
45//! ## Code Generation
46//!
47//! ```ignore
48//! use synkit::{ToTokens, Printer};
49//!
50//! impl ToTokens for MyExpr {
51//!     fn to_tokens(&self, printer: &mut impl Printer) {
52//!         match self {
53//!             MyExpr::Number(n) => printer.write(&n.to_string()),
54//!             MyExpr::Ident(i) => printer.write(&i.name),
55//!         }
56//!     }
57//! }
58//! ```
59//!
60//! # Feature Flags
61//!
62//! - `std`: Enables `std::error::Error` implementations
63//! - `serde`: Enables serialization for span types
64
65mod diagnostic;
66mod error;
67mod parse;
68mod peek;
69mod printer;
70mod stream;
71mod to_tokens;
72
73pub use diagnostic::Diagnostic;
74pub use error::SpannedError;
75pub use parse::Parse;
76pub use peek::Peek;
77pub use printer::Printer;
78pub use stream::{SpanLike, SpannedLike, TokenStream};
79pub use to_tokens::ToTokens;