Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tcr/parser-c
Haskell's language-c ported to Rust.
https://github.com/tcr/parser-c
c haskell-language parse rust
Last synced: 12 days ago
JSON representation
Haskell's language-c ported to Rust.
- Host: GitHub
- URL: https://github.com/tcr/parser-c
- Owner: tcr
- Created: 2017-06-26T02:48:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-04T12:36:46.000Z (over 6 years ago)
- Last Synced: 2024-10-07T04:07:35.529Z (about 1 month ago)
- Topics: c, haskell-language, parse, rust
- Language: Rust
- Homepage: http://docs.rs/parser-c
- Size: 3.97 MB
- Stars: 30
- Watchers: 4
- Forks: 5
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# parser-c
[![Gitter](https://img.shields.io/gitter/room/tcr/parser-c.svg)](http://gitter.im/parser-c/Lobby) [![https://img.shields.io/crates/v/parser-c.svg](https://img.shields.io/crates/v/parser-c.svg)](http://crates.io/crates/parser-c/)
Rust module for parsing C code. Port of Haskell's [language-c](https://github.com/visq/language-c), semi-automatically translated using [Corollary](https://github.com/tcr/corrode-but-in-rust).
**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:
1. Building up an equivalent test bed to language-c's, then automatically cross-check
1. Fix errors in the ported code to support those test cases
1. Converting portions of the code into Rust idioms without breaking tests
1. Figure out a porting story for the alex/happy generated parser output`parser-c` requires nightly (for now). See `tests/` for some working examples, or try this example:
```rust
extern crate parser_c;use parser_c::parse;
const INPUT: &'static str = r#"
int main() {
printf("hello world!\n");
return 0;
}"#;
fn main() {
match parse(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,
..
)
),
...
```## Development
Clone this crate:
```
git clone https://github.com/tcr/parser-c --init --recursive
```Hacking on the lexer and parser requires to build and run the Haskell
dependencies using:```
./regen.sh
```The 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, use
this script:```
./test.sh
```## License
MIT