Expand description
Abstract Syntax Tree definitions for the CJC compiler.
This crate defines the complete AST node taxonomy produced by [cjc_parser]:
Program, Stmt/StmtKind, Expr/ExprKind, Decl/DeclKind,
type expressions (TypeExpr/TypeExprKind), patterns (Pattern/PatternKind),
and all supporting structures (identifiers, spans, operators, etc.).
This is a leaf crate with zero internal dependencies, ensuring it can be consumed by every downstream stage of the compiler pipeline without cycles.
§Submodules
visit— Read-only visitor trait and walk functions for AST traversalmetrics— Structural statistics (node counts, depths, feature flags)validate— Lightweight structural validation before HIR loweringinspect— Deterministic text dumps for debugging and testingnode_utils— Pure query methods onExpr,Block, andProgram
Modules§
- inspect
- AST Inspect/Diagnostics — Deterministic text dumps for debugging and tests
- metrics
- AST Metrics — Structural statistics computed via visitor traversal
- node_
utils - AST Node Utilities — Pure query methods on existing types
- validate
- AST Validation — Lightweight structural checks before downstream lowering
- visit
- AST Visitor — Read-only traversal infrastructure
Structs§
- Block
- A block of statements with an optional trailing expression.
- CallArg
- A function call argument, optionally named.
- Class
Decl - Class declaration:
class Widget { ... } - Const
Decl - A compile-time constant declaration:
const PI: f64 = 3.14159; - Decl
- A declaration (top-level item).
- Decorator
- A decorator applied to a function declaration.
- Enum
Decl - Enum declaration:
enum Color { Red, Green, Blue(i64) } - Expr
- An expression node in the AST.
- Field
Decl - A named field within a struct, class, or record declaration.
- Field
Init - A field initializer in a struct literal:
x: expr. - FnDecl
- Function declaration:
fn solve(x: f64, tol: f64 = 1e-6) -> f64 { ... } - FnSig
- Function signature without a body, used in
TraitDeclmethod declarations. - ForStmt
- For loop statement:
for i in 0..n { ... }orfor x in arr { ... } - Ident
- An identifier with its source span.
- IfStmt
- If statement:
if cond { ... } else { ... } - Impl
Decl - Impl block:
impl Foo { ... }orimpl Trait for Foo { ... } - Import
Decl - Import declaration:
import math.linalgorimport stats as s. - LetStmt
- Let binding statement:
let x = 1;orlet mut y: f64 = 3.14; - Match
Arm - A single arm of a match expression:
pattern => body - Param
- Pattern
- A pattern for use in match arms.
- Pattern
Field - A field pattern inside a struct pattern:
xorx: pat - Pretty
Printer - Pretty-printer that converts an AST back into human-readable CJC source.
- Program
- Top-level program: a sequence of declarations.
- Record
Decl - Record declaration: immutable value type.
record Point { x: f64, y: f64 }Records are like structs but always immutable — field reassignment is a type error. - Span
- Source span: byte offset range in source code. Duplicated from cjc-diag to avoid circular dependency. AST is a leaf crate with no dependencies.
- Stmt
- A statement node in the AST.
- Struct
Decl - Struct declaration:
struct Point { x: f64, y: f64 } - Trait
Decl - Trait declaration:
trait Numeric { fn zero() -> Self; } - Type
Expr - A type expression in source code.
- Type
Param - A generic type parameter declaration:
<T: Numeric>. - Variant
Decl - A single variant within an
EnumDecl. - While
Stmt - While loop statement:
while cond { ... }
Enums§
- BinOp
- Binary operator.
- Decl
Kind - The kind of a top-level declaration.
- Else
Branch - The else clause of an if statement or expression.
- Expr
Kind - The kind of an expression.
- ForIter
- The iteration source for a
forloop. - Pattern
Kind - Shape
Dim - A single dimension in a tensor shape specification.
- Stmt
Kind - The kind of a statement.
- TypeArg
- A type argument in a generic instantiation.
- Type
Expr Kind - The kind of a type expression.
- UnaryOp
- Unary operator.
- Visibility
- Visibility qualifier for declarations and fields.
pubmakes an item publicly visible; the default is private. NOTE: Enforcement is deferred — single-file programs treat all items as public regardless of annotation. This enum is stored but not checked yet.