alashworth / test-issue-import

0 stars 0 forks source link

better error message for program block names which contain typos #159

Open alashworth opened 5 years ago

alashworth commented 5 years ago

Issue by mitzimorris Friday Jul 28, 2017 at 16:42 GMT Originally opened as https://github.com/stan-dev/stan/issues/2367


Summary:

When a Stan program has a model block name which is wrong, e.g. parameter instead of parameters, the parser error message is misleading:

PARSER EXPECTED: whitespace to end of file.
FOUND AT line <n>:

Description:

At the point where the parser encounters a bad model block name, the parse fails. Because all model blocks are optional, an empty file is a legal parse, hence the error message.

Reproducible Steps:

This program will result in the bad error message:

parameter {
  real x;
}

transformed parameter {
  real y = x;
}

model {
  x ~ normal(0, 1);
}

Current Output:

Current error message:

PARSER EXPECTED: whitespace to end of file.
FOUND AT line 1: 

Expected Output:

better error message would list allowed model block names, given model blocks already encountered.

Additional Information:

Current Version:

v2.16.0

alashworth commented 5 years ago

Comment by HaotianLin Sunday Aug 19, 2018 at 20:21 GMT


I have the same problem, have you fix it now ?

alashworth commented 5 years ago

Comment by bob-carpenter Sunday Aug 19, 2018 at 21:48 GMT


The only fix is going to be to the error message. There wasn't a bug in the language for well-formed code.

alashworth commented 5 years ago

Comment by VMatthijs Thursday Dec 13, 2018 at 13:06 GMT


Stanc3 currently says

Syntax error at file "test.stan", line 1, characters 0-9, parsing error:
   -------------------------------------------------
     1:  parameter {
                  ^
     2:    real x;
     3:  }
   -------------------------------------------------

Expected "functions {" or "data {" or "transformed data {" or "parameters {" or "transformed parameters {" or "model {" or "generated quantities {".
alashworth commented 5 years ago

Comment by bob-carpenter Thursday Dec 13, 2018 at 14:07 GMT


This is one of these errors that's bugged me in the current setup.

Is it possible to say something like

unknown block 'parameter', expected `functions' or 'data' or ...

?

On Dec 13, 2018, at 8:06 AM, Matthijs Vákár notifications@github.com wrote:

Stanc3 currently says

Syntax error at file "test.stan", line 1, characters 0-9, parsing error:

 1:  parameter {
              ^
 2:    real x;
 3:  }

Expected "functions {" or "data {" or "transformed data {" or "parameters {" or "transformed parameters {" or "model {" or "generated quantities {".

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

alashworth commented 5 years ago

Comment by VMatthijs Thursday Dec 13, 2018 at 15:08 GMT


It might be possible, but it would take me a while to figure out how to capture part of the input program in Menhir's custom errors. Changes to the parsing error messages which do not requires quoting the user program are easy to implement, however, and might amount to a better investment of our time. Quoting the user program in semantic errors is easy, on the other hand.

alashworth commented 5 years ago

Comment by madeleineth Saturday Dec 22, 2018 at 03:10 GMT


I'm not sure if it counts as the same issue, but I'm also seeing this message when I put the functions block (without a typo) after the data and parameters blocks. (rstan 2.18.2)