Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix parser warnings for semicolons in function arguments #2676

Closed
bob-carpenter opened this issue Oct 22, 2018 · 6 comments
Closed

fix parser warnings for semicolons in function arguments #2676

bob-carpenter opened this issue Oct 22, 2018 · 6 comments

Comments

@bob-carpenter
Copy link
Member

bob-carpenter commented Oct 22, 2018

Summary:

The parser is producing a confusing warning for the following ill-formed Stan program:

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

See the Discourse topic for more examples

Current Output:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
 error in '/Users/carp/temp2/confusing.stan' at line 2, column 17
  -------------------------------------------------
     1: transformed data {
     2:   real x = atan2(2 ; 3);
                        ^
     3: }
  -------------------------------------------------

PARSER EXPECTED: "("

Expected Output:

Something like "expected , or )" pointing before the semicolon.

Current Version:

v2.18.0

@VMatthijs
Copy link
Member

Stanc3 produces

Syntax error at file "test.stan", line 2, characters 17-18, parsing error:
   -------------------------------------------------
     1:  transformed data {
     2:    real x = atan2(2 ; 3);
                           ^
     3:  }
   -------------------------------------------------

Ill-formed function application. Expect comma-separated list of expressions followed by ")" after "(".

@mitzimorris mitzimorris modified the milestones: 2.18.1, 2.18.1++ Dec 23, 2018
@seantalts seantalts modified the milestones: 2.18.1++, 2.19.0++ Mar 20, 2019
@csetraynor
Copy link

csetraynor commented Aug 18, 2019

Hi,
maybe an error that only an R user a bit newb in Stan would do. But the same confusing parser warnings appears if one tries passing an int[] type to a function without declaring and expecting that it will work as it would in R... for example as following:

functions{
vector construct_eta(matrix X, vector b, int[] loc, int[] b_K, int N){
    vector[N] eta;
     eta = X[loc, K] * b[b_K];
    return(eta);
  }
}
data{
int nSubjects
}
...
transformed parameters{
for(j in 1:nSubjects){
eta = construct_eta(predictors, beta, start[j]:end[j],  b_K, N);
}
}

I do not know how hard might be to catch this error, but in any case I also leave the comment here for future reference.

EDIT:
Actually maybe catching the colon : would be enough probably that is where the error comes from and not the int[] type.

@mitzimorris mitzimorris assigned VMatthijs and unassigned mitzimorris Aug 19, 2019
@VMatthijs
Copy link
Member

VMatthijs commented Aug 19, 2019

Stanc3 says the following on @bob-carpenter 's example model (top):

Syntax error in 'temp.stan', line 2, column 17 to column 18, parsing error:
   -------------------------------------------------
     1:  transformed data {
     2:    real x = atan2(2 ; 3);
                           ^
     3:  }
   -------------------------------------------------

Ill-formed function application. Expect comma-separated list of expressions followed by ")" after "(".

and the following for @csetraynor 's model:

Syntax error in 'temp.stan', line 9, column 4 to column 13, parsing error:
   -------------------------------------------------
     7:  }
     8:  data{
     9:  int nSubjects
                      ^
    10:  }
    11:  ...
   -------------------------------------------------

Only top-level variable declarations are allowed in data and parameter blocks.

after which we can add the missing semi-colon to get the following error:

Syntax error in 'temp.stan', line 13, column 38 to column 46, parsing error:
   -------------------------------------------------
    11:  transformed parameters{
    12:  for(j in 1:nSubjects){
    13:  eta = construct_eta(predictors, beta, start[j]:end[j],  b_K, N);
                                                       ^
    14:  }
    15:  }
   -------------------------------------------------

Ill-formed phrase. We found an L-value. Parse failed on token after the L-value.

Are these considered informative enough? It's sometimes hard to give a very informative error, like in the last case, because that parse rule appears in many different contexts (meaning it's hard to give an error message that is not entirely generic). Of course, it's possible to many the grammar more complicated to get more specific error messages, but it's a matter of weighing cost and benefit then.

(The reason this last program isn't accepted is because a : b is not an expression in Stan (a design choice, it seems) but rather only used as a part of the for-loop and indexing syntaxes.)

@VMatthijs
Copy link
Member

Does it make sense to label this Won't fix until stanc3?

@csetraynor
Copy link

Hi @VMatthijs yes
Ill-formed phrase. We found an L-value. Parse failed on token after the L-value.
would be informative enough for a user. my opinion as a current user.

@mcol
Copy link
Contributor

mcol commented Feb 22, 2020

Fixed in stanc3.

@mcol mcol closed this as completed Feb 22, 2020
@mcol mcol modified the milestones: 2.22.0++, 2.22.0 Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants