| Crates.io | cgrammar |
| lib.rs | cgrammar |
| version | 0.1.0 |
| created_at | 2025-08-15 00:13:47.7841+00 |
| updated_at | 2025-08-15 00:13:47.7841+00 |
| description | A comprehensive C language grammar parser library written in Rust, implementing the C23 standard (ISO/IEC 9899:2023). |
| homepage | |
| repository | https://github.com/Wybxc/cgrammar |
| max_upload_size | |
| id | 1795998 |
| size | 567,037 |
A comprehensive C language grammar parser library written in Rust, implementing the C23 standard (ISO/IEC 9899:2023).
This library supports all major C23 features including:
0b prefix)_BitInt type specifiertypeof and typeof_unqual operators_Decimal128, _Decimal32, _Decimal64 typesAdd this to your Cargo.toml:
[dependencies]
cgrammar = "0.1.0"
use cgrammar::*;
use chumsky::Parser;
fn main() {
let source_code = r#"
int main() {
printf("Hello, World!\n");
return 0;
}
"#;
// Tokenize the source code
let lexer = balanced_token_sequence();
let tokens = lexer.parse(source_code).unwrap();
// Parse into AST
let parser = translation_unit();
let result = parser.parse(tokens.as_input());
if let Some(ast) = result.output() {
println!("Successfully parsed!");
println!("{:#?}", ast);
} else {
eprintln!("Parse failed!");
// Handle errors...
}
}
This project is licensed under the MIT License - see the LICENSE file for details.