stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
140 stars 44 forks source link

Add a special-case error message for old array syntax #1413

Closed WardBrian closed 6 months ago

WardBrian commented 6 months ago

Closes #1412. Surprisingly, this doesn't introduce any conflicts in the parser. If it ever does, we could remove it again, but for now it seems like a good quality of life feature.

One downside is printing a nice error message introduced a circular dependency between pretty printing and parsing. I resolved this by splitting the pretty printing module in two, but I'm not super happy with that.

Submission Checklist

Release notes

Added a better error message when a program attempts to use the removed array syntax.

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)

WardBrian commented 6 months ago

Examples of the new message:

Syntax error in 'declarations.stan', line 3, column 18 to column 18, parsing error:
   -------------------------------------------------
     1:  data {
     2:    int a0;
     3:    int<lower=0> a1[1];
                           ^
     4:    int a2[2,3];
     5:    array[1] int a3;
   -------------------------------------------------

";" expected after variable declaration.
It looks like you are trying to use the old array syntax.
Please use the new syntax:
array[...] int<lower=0> a1;
Syntax error in 'unsized-old-array.stan', line 2, column 18 to column 18, parsing error:
   -------------------------------------------------
     1:  functions{
     2:    real foo(  real[,] v){
                           ^
     3:      return sum(v);
     4:    }
   -------------------------------------------------

An identifier is expected after the type as a function argument name.
It looks like you are trying to use the old array syntax.
Please use the new syntax: 
array[...] real

(how does this look @andrjohns?)

codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 83.33333% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 89.87%. Comparing base (e162817) to head (02a1c64).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1413 +/- ## ======================================= Coverage 89.87% 89.87% ======================================= Files 63 64 +1 Lines 10529 10529 ======================================= Hits 9463 9463 Misses 1066 1066 ``` | [Files](https://app.codecov.io/gh/stan-dev/stanc3/pull/1413?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev) | Coverage Δ | | |---|---|---| | [src/frontend/Pretty\_printing.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1413?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL2Zyb250ZW5kL1ByZXR0eV9wcmludGluZy5tbA==) | `93.18% <ø> (+1.15%)` | :arrow_up: | | [src/stanc/stanc.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1413?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL3N0YW5jL3N0YW5jLm1s) | `82.14% <100.00%> (ø)` | | | [src/frontend/Pretty\_print\_prog.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1413?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL2Zyb250ZW5kL1ByZXR0eV9wcmludF9wcm9nLm1s) | `82.85% <82.85%> (ø)` | |