nolanderc / glsl_analyzer

Language server for GLSL (autocomplete, goto-definition, formatter, and more)
GNU General Public License v3.0
201 stars 6 forks source link

False error 'missing semicolon' with macros #59

Closed akberg closed 7 months ago

akberg commented 7 months ago

I'm getting false errors claiming a missing semicolon, specifically for the below case of macro replacements of a for loop, which could suggest the syntax is not defined entirely correctly, or just be a symptom of macros not being preprocessed.

#version 450

#define FOREACH(x) for (x = 0; x < 42; x++)

void main() {
    uint x, y;
    FOREACH(x) {
        y += x;
    }
}

Produces this tree and error messages:

glsl_analyzer --parse-file shaders/src/bug.comp --print-ast
file
  function_declaration
    identifier 'void'
    identifier 'main'
    parameter_list
      (
      )
    block
      {
      declaration
        identifier 'uint'
        variable_declaration_list
          variable_declaration
            identifier 'x'
            ,
          variable_declaration
            identifier 'y'
        ;
      statement
        call
          identifier 'FOREACH'
          (
          argument
            identifier 'x'
          )
        invalid
      block
        {
        statement
          assignment
            identifier 'y'
            +=
            identifier 'x'
          ;
        }
      }
shaders/src/bug.comp:7:15: expected ;

glsl_analyzer version: 1.4.5

nolanderc commented 7 months ago

You are correct: we don’t expand macros currently, see #30. Closing as duplicate