| Crates.io | eecee |
| lib.rs | eecee |
| version | 0.1.0 |
| created_at | 2025-10-15 17:15:51.949948+00 |
| updated_at | 2025-10-15 17:15:51.949948+00 |
| description | Simple AST representation and formatter for the C programming language |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1884710 |
| size | 227,322 |
A comprehensive Rust library for representing and pretty-printing C programming language Abstract Syntax Trees (AST). The library provides a complete type-safe representation of C syntax following the C11 standards.
no_std Compatible - Works in embedded and bare-metal environmentsAdd this to your Cargo.toml:
[dependencies]
eecee = "0.1.0"
use eecee::ast::*;
use internment::Intern;
// Create a simple function: int add(int a, int b) { return a + b; }
let function = FunctionDefinition::builder()
.specifiers(SpecifierList::builder()
.specifiers(vec![Specifier::Type(TypeSpecifier::Int)])
.build())
.declarator(Declarator::builder()
.pointer(None)
.direct(DirectDeclarator::Function {
declarator: Intern::new(DirectDeclarator::Identifier(
Intern::new("add".to_string())
)),
params: ParameterTypeList::builder()
.parameters(vec![
ParameterDeclaration::builder()
.specifiers(SpecifierList::builder()
.specifiers(vec![Specifier::Type(TypeSpecifier::Int)])
.build())
.declarator(Some(ParameterDeclarator::Declarator(
Declarator::builder()
.pointer(None)
.direct(DirectDeclarator::Identifier(
Intern::new("a".to_string())
))
.build()
)))
.build(),
ParameterDeclaration::builder()
.specifiers(SpecifierList::builder()
.specifiers(vec![Specifier::Type(TypeSpecifier::Int)])
.build())
.declarator(Some(ParameterDeclarator::Declarator(
Declarator::builder()
.pointer(None)
.direct(DirectDeclarator::Identifier(
Intern::new("b".to_string())
))
.build()
)))
.build(),
])
.variadic(false)
.build(),
})
.build())
.declarations(vec![])
.body(CompoundStatement::builder()
.declarations(vec![])
.statements(vec![
Statement::Return {
value: Some(Expression::Binary {
left: Intern::new(Expression::Identifier(
Intern::new("a".to_string())
)),
op: BinaryOperator::Add,
right: Intern::new(Expression::Identifier(
Intern::new("b".to_string())
)),
}),
}
])
.build())
.build();
// Print the function
println!("{}", function);
TranslationUnit - Top-level compilation unit containing all declarationsFunctionDefinition - Complete function with signature and bodyDeclaration - Variable/type declarationsStatement - Executable statements (if, while, for, return, etc.)Expression - All expression types (binary ops, calls, literals, etc.)TypeSpecifier - Basic and complex types (int, struct, union, enum, etc.)TypeQualifier - Type qualifiers (const, volatile, restrict, _Atomic)StorageClassSpecifier - Storage classes (static, extern, auto, register, typedef)Declarator - Variable/function declarators with pointers and dimensionsTypeName - Abstract type names for casts and sizeofStructOrUnionSpecifier - Struct/union definitions and forward declarationsEnumSpecifier - Enum definitions with enumeratorsInitDeclarator - Declarator with optional initializerInitializer - Expression or aggregate initializersCompoundStatement - Block with declarations and statementsIf, While, For, DoWhile, SwitchReturn, Break, Continue, GotoCase, Default, LabelBinaryOperator - All binary operators (+, -, *, /, ==, !=, etc.)UnaryOperator - Unary operators (++, --, !, ~, *, &, etc.)Constant - Integer, floating-point, and character constantsStringLiteral - String literals and funcThe library includes a sophisticated indentation system for formatting output:
use eecee::indent_printer::{IndentContext, IndentDisplay};
let context = IndentContext::new(" "); // 4-space indentation
println!("{}", context.display(&translation_unit));
The library aims to support C11 standards with the following features:
no_std SupportThis library is no_std compatible by default. The library uses alloc for dynamic allocations (Vec, String).
Contributions are welcome! Areas for contribution: