hadronized / glsl

GLSL parser for Rust
191 stars 27 forks source link

CompoundStatement requires braces. #75

Closed seivan closed 5 years ago

seivan commented 5 years ago

I want to join existing partial glsl code with one that's built programatically.

    let existing_code = CompoundStatement::parse(
        "
    r = t;
    f = h; 

    ",
    )
    .unwrap();

I'm then adding it to an existing CompoundStatement that has programatically built everything else.

    compound
        .statement_list
        .extend(&existing_code.statement_list);

    let external_declaration = ExternalDeclaration::new_fn(
        TypeSpecifierNonArray::Void,
        "main",
        Vec::new(),
        compound.statement_list,
    );

    let translation_unit = TranslationUnit::from_iter(vec![external_declaration]).unwrap();

The issue, the CompoundStatement::parse() fails unless the string is surrounded with {}. Maybe CompoundStatement is the wrong type, in which case could you direct me to the correct type for parsing existing code that could be within a function (e.g no declarations).

I tested Statement and Expr but those seem to be for one liners and I'd have to separate each line into its own string before parsing?

hadronized commented 5 years ago

Yes, a CompoundStatement is always surrounded by braces. Currently, there’s no such parser for what you’re asking. Either you want to break, as you mention, the lines or you need to add the braces if you want to use CompoundStatement.

Besides that, what’s it you want to do? :)

seivan commented 5 years ago

No, that’s perfect. I just wanted to make sure I was understanding correctly, it works alright for me.