vickenty / lang-c

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

Compound literals do not work #21

Closed robbym closed 4 years ago

robbym commented 4 years ago

Compound literals do not seem to work.

Test preprocessed C file:

# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"
typedef struct
{
    int value;
} test_t;

void test(test_t* myStruct)
{
    *myStruct = (test_t) {.value = 1};
}

Error:

SyntaxError {
    source: --- see above ---,
    line: 12,
    column: 26,
    offset: 173,
    expected: {
        "<",
        "!=",
        "*=",
        "%=",
        "&",
        "==",
        ">",
        "<<",
        "&&",
        ">>",
        "u8",
        "[",
        "~",
        ">=",
        "*",
        "/",
        "++",
        "->",
        "--",
        "+",
        "<<=",
        ";",
        "?",
        "|=",
        "[_a-zA-Z]",
        ">>=",
        "[uUL]",
        "^=",
        ",",
        ".",
        "!",
        "||",
        "(",
        "-=",
        "\"",
        "/=",
        "<=",
        "^",
        "%",
        "=",
        "+=",
        "&=",
        "|",
        "-",
    },
}
vickenty commented 4 years ago

Thanks.

Two grammar bits seem to be not working properly:

robbym commented 4 years ago

Thanks.

Two grammar bits seem to be not working properly:

* typedef is not recognized as type name

* designators

Are those two grammar issues related to the compound literals issue? Or are you referring to https://github.com/vickenty/lang-c/issues/23?

vickenty commented 4 years ago

I was referring to this issue. In a test I did, (test_t) {.. didn't parse just as you reported, but (struct test_t) {... seemed to progress further and fail on the designator. I didn't see your PR yet when I wrote that, and I still need to go through it.