- Notifications
You must be signed in to change notification settings - Fork5
Haskell's language-c ported to Rust.
tcr/parser-c
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Rust module for parsing C code. Port of Haskell'slanguage-c, semi-automatically translated usingCorollary.
This port is a work in progress. A lot of work remains to parse anything but very simple C files; while most source code has been translated from Haskell, errors in translation prevent it from matching language-c's functionality yet. Here are the next steps for achieving parity, in order:
- Building up an equivalent test bed to language-c's, then automatically cross-check
- Fix errors in the ported code to support those test cases
- Converting portions of the code into Rust idioms without breaking tests
- Figure out a porting story for the alex/happy generated parser output
parser-c requires nightly (for now). Seetests/ for some working examples, or try this example:
externcrate parser_c;use parser_c::parse;constINPUT:&'staticstr =r#"int main() { printf("hello world!\n"); return 0;}"#;fnmain(){matchparse(INPUT,"simple.c"){Err(err) =>{panic!("error: {}", err);}Ok(ast) =>{println!("success: {:#?}", ast);}}}
Result is:
success: Right( CTranslationUnit( [ CFDefExt( CFunctionDef( [ CTypeSpec( CIntType( .. ) ) ], CDeclarator( Some( Ident( "main", 124382170, .. ) ), ...Clone this crate:
git clone https://github.com/tcr/parser-c --init --recursiveHacking on the lexer and parser requires to build and run the Haskelldependencies using:
./regen.shThe test suite is being ported at the moment. It is in a separate crate,because it requires a build script with prerequisites, so to run it, usethis script:
./test.shMIT
About
Haskell's language-c ported to Rust.
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.