build2 / build2

build2 build system
MIT License
564 stars 13 forks source link

`script`: confusing `if-else` diagnostics #311

Open boris-kolpackov opened 11 months ago

boris-kolpackov commented 11 months ago

Consider this buildfile (notice erroneous endif instead of end):

./:
{{
  diag dummy

  if (true)
    if (false)
      exit "bad"
    else
      echo good
    endif
  elif (false)             # <-- error points to this line
  else
  end
}}

This produces the following diagnostics:

buildfile:11:3: error: 'elif' after 'else'

This is quite confusing. In the real situation where I hit this it took me several frustrating minutes to figure out what's the cause.

I believe the reason for this is that we treat endif as a command which causes the subsequent elif to be attributed to the inner if. Feel like the low-hanging fix here would be to point to the else and perhaps also to the if that is the beginning of the if-else chain.

Also, would be good to check if there is any other if-else diagnostics like this that can be confusing and can be improved in a similar way.

boris-kolpackov commented 1 month ago

BTW, this is probably related to that idea/desire to somehow change the script syntax to use {} instead of end.