vickenty / lang-c

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

Internal functions are not accepted #37

Open omarandlorraine opened 1 year ago

omarandlorraine commented 1 year ago

I've found this kind of code which is accepted by Clang and GCC, but not by lang-c.

int fn() {
        int ifn() {
                return 5;
        }
        return ifn();
}

fn is a function having an internal function, named ifn. ifn is only in scope inside the body of fn. This is not standard C, but a GNU extension. I don't think it's in ANSI C or ISO C99, or K&R, or anything like that. So I am not sure if we want or need to accept this kind of code in lang-c.

I'm getting this error message:

SyntaxError(SyntaxError { source: "# 0 \"c/fninfn.c\"\n# 0 \"<built-in>\"\n# 0 \"<command-line>\"\n# 1 \"/usr/include/stdc-predef.h\" 1 3 4\n# 0 \"<command-line>\" 2\n# 1 \"c/fninfn.c\"\nint fn() {\n int ifn() {\n  return 5;\n }\n return ifn();\n}\n", line: 8, column: 12, offset: 156, expected: {";", "asm", "(", "[", ",", "="} })

What do you think?

vickenty commented 1 year ago

Sure, it would be nice to add support for this extension. GNU extensions are definitely in the scope for lang-c, there is already support for a small number of them.