Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Haskell's language-c ported to Rust.

NotificationsYou must be signed in to change notification settings

tcr/parser-c

Repository files navigation

Gitterhttps://img.shields.io/crates/v/parser-c.svg

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:

  1. Building up an equivalent test bed to language-c's, then automatically cross-check
  2. Fix errors in the ported code to support those test cases
  3. Converting portions of the code into Rust idioms without breaking tests
  4. 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,                                ..                            )                        ),                        ...

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 Haskelldependencies 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, usethis script:

./test.sh

License

MIT

About

Haskell's language-c ported to Rust.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp