Skip to main content

Crate cjc_ast

Crate cjc_ast 

Source
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 traversal
  • metrics — Structural statistics (node counts, depths, feature flags)
  • validate — Lightweight structural validation before HIR lowering
  • inspect — Deterministic text dumps for debugging and testing
  • node_utils — Pure query methods on Expr, Block, and Program

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.
ClassDecl
Class declaration: class Widget { ... }
ConstDecl
A compile-time constant declaration: const PI: f64 = 3.14159;
Decl
A declaration (top-level item).
Decorator
A decorator applied to a function declaration.
EnumDecl
Enum declaration: enum Color { Red, Green, Blue(i64) }
Expr
An expression node in the AST.
FieldDecl
A named field within a struct, class, or record declaration.
FieldInit
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 TraitDecl method declarations.
ForStmt
For loop statement: for i in 0..n { ... } or for x in arr { ... }
Ident
An identifier with its source span.
IfStmt
If statement: if cond { ... } else { ... }
ImplDecl
Impl block: impl Foo { ... } or impl Trait for Foo { ... }
ImportDecl
Import declaration: import math.linalg or import stats as s.
LetStmt
Let binding statement: let x = 1; or let mut y: f64 = 3.14;
MatchArm
A single arm of a match expression: pattern => body
Param
Pattern
A pattern for use in match arms.
PatternField
A field pattern inside a struct pattern: x or x: pat
PrettyPrinter
Pretty-printer that converts an AST back into human-readable CJC source.
Program
Top-level program: a sequence of declarations.
RecordDecl
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.
StructDecl
Struct declaration: struct Point { x: f64, y: f64 }
TraitDecl
Trait declaration: trait Numeric { fn zero() -> Self; }
TypeExpr
A type expression in source code.
TypeParam
A generic type parameter declaration: <T: Numeric>.
VariantDecl
A single variant within an EnumDecl.
WhileStmt
While loop statement: while cond { ... }

Enums§

BinOp
Binary operator.
DeclKind
The kind of a top-level declaration.
ElseBranch
The else clause of an if statement or expression.
ExprKind
The kind of an expression.
ForIter
The iteration source for a for loop.
PatternKind
ShapeDim
A single dimension in a tensor shape specification.
StmtKind
The kind of a statement.
TypeArg
A type argument in a generic instantiation.
TypeExprKind
The kind of a type expression.
UnaryOp
Unary operator.
Visibility
Visibility qualifier for declarations and fields. pub makes 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.