vickenty / lang-c

Lightweight C parser for Rust
Apache License 2.0
202 stars 30 forks source link

Support GNU case ranges #36

Closed 00xc closed 2 years ago

00xc commented 2 years ago

Case ranges are a GNU extension that allow matching a number of consecutive cases, like so:

#include <stdio.h>
int main() {
    int v = 4;

    switch (v) {
        case 0 ... 4: puts("Between 0 and 4"); break;
        case 5: puts("5"); break;
        default: puts("something else"); break;
    }

    return 0;
}

This will be compiled without errors with gcc -std=gnu11 range.c. However, when parsing with lang-c, this results in a SyntaxError:

use lang_c::driver::{Config, parse};

fn main() {
   let config = Config::with_gcc();
    let p = parse(&config, "range.c");
    if let Err(e) = p {
        println!("{}", e);
    }
}

Output:

syntax error: unexpected token at line 733 column 11, expected '[_a-zA-Z]'
vickenty commented 2 years ago

Thanks!