Parser library
monkey-c-parser turns Monkey C source into an abstract syntax tree. The
formatter, linter and language server are all built on it, and it can be used on
its own to build other tools.
use monkey_c_parser::parser::Parser;
let output = Parser::new("function f() { return 1; }").parse()?;
// The syntax tree, and the comments kept in a separate table.
println!("{:#?}", output.ast);
println!("{:#?}", output.comments);
Comments aren’t part of the tree itself. They’re kept in their own table with their positions, so tools that don’t care about them can ignore them, and the formatter can put each one back where it belongs.
The parser follows Garmin’s Monkey C reference. Its design is based on the parser in ruff.