Confusing parser warning


#1

Currently when a comma is missing in the arguments to a function call the Stan parser throws a confusing warning: ‘PARSER EXPECTED: “(”’, could we make it say ‘PARSER EXPECTED: “,”’ instead? Didn’t file an issue b/c I’m not sure how hard this is.

--- Translating Stan model to C++ code ---
Model name=delay_model_l1_model
Input file=/Users/krzysztof/projekty/delay-analysis-thailand-build/models/delay-model-l1.stan
Output file=/Users/krzysztof/projekty/delay-analysis-thailand-build/models/delay-model-l1.hpp

SYNTAX ERROR, MESSAGE(S) FROM PARSER:


ERROR at line 292

 290:        province_index, district_index, subdistrict_index, delivery_index);
 291:    
 292:      vector[n_obs] delta = construct(1, 0, n_obs, 
                                          ^
 293:        scaling[4], delta_0 + offset[4]

PARSER EXPECTED: "("

make[3]: *** [/Users/krzysztof/projekty/delay-analysis-thailand-build/models/delay-model-l1.hpp] Error 253
make[2]: *** [models/delay-model-l1] Error 2
make[1]: *** [models/CMakeFiles/compiled-delay-model.dir/all] Error 2
make: *** [all] Error 2

#2

Please don’t let difficulty of solving something hold you back from filing an issue.

We can fix this if we have a minimal reproducible example (preferably less than 300 lines long). I couldn’t actually tell where you thought the comma was missing from in this example.


#3

This misleading error message is still around.
Here is a reproducible example:

functions{     
 
  
  real fun_mre(real x, real y, real z ){ 
    return(x + y + z);
                      }          
  
  
  real fun_mre1( real x, real y, real z ){ 
       real total;
       total = fun_mre(x,
                        y;
                        z); 
        return(total);
    }
  }
  data{}
  model{}

When I try to parse it I get:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:

  error in 'model2892f772215_mre' at line 11, column 23
  -------------------------------------------------
     9:   real fun_mre1( real x, real y, real z ){ 
    10:        real total;
    11:        total = fun_mre(x,
                              ^
    12:                         y;
  -------------------------------------------------

PARSER EXPECTED: "("
Error in stanc(filename, allow_undefined = TRUE) : 
  failed to parse Stan model 'mre' due to the above error.

I am pleased to say that putting this example together enabled to find what was causing the rouble in my own code.


#4

Thanks. Here’s an even simpler example:

transformed data {
  real x = atan2(2 ; 3);
}

I’m opening an issue and we’ll clean this up. Right now, GitHub seems to be down, so it’s queued up.


#5

Hey all. Just to let you know I observed this same error just now when I mistakenly included an extra , in the function call.

E.g.

functions{     
 
  
  real fun_mre(real x, real y, real z ){ 
    return(x + y + z);
                      }          
  
  
  real fun_mre1( real x, real y, real z ){ 
       real total;
       total = fun_mre(x,
                        y,,
                        z); 
        return(total);
    }
  }
  data{}
  model{}

#6

Thanks. Here’s the issue.

I’ll link it back to here to make sure it all gets cleaned up for our next release.