Estimating Parameters of a Mixture: Parser Error for Example?

I’m very new to Stan, so I may be missing something simple here. I’m trying to work with the example from the subsection “Estimating Parameters of a Mixture” (currently pg 193). I’ve tried copying the text by hand and copy/pasting from the PDF (my copy/paste version below).

data {
  int<lower=1> K; // number of mixture components
  int<lower=1> N; // number of data points
  real y[N]; // observations
}
parameters {
  simplex[K] theta; // mixing proportions
  ordered mu[K]; // locations of mixture components
  vector<lower=0>[K] sigma; // scales of mixture components
}
model {
  real log_theta[K] = log(theta); // cache log calculation
  sigma ~ lognormal(0, 2);
  mu ~ normal(0, 10);
  for (n in 1:N) {
    real lps[K] = log_theta;
    for (k in 1:K)
      lps[k] += normal_lpdf(y[n] | mu[k], sigma[k]);
      target += log_sum_exp(lps);
  }
}

In both cases I get a syntax error from the parser.

SYNTAX ERROR, MESSAGE(S) FROM PARSER:

  error in 'model_foo' at line 8, column 10
  -------------------------------------------------
     6: parameters {
     7:   simplex[K] theta; // mixing proportions
     8:   ordered mu[K]; // locations of mixture components
                 ^
     9:   vector<lower=0>[K] sigma; // scales of mixture components
  -------------------------------------------------

PARSER EXPECTED: <size declaration: integer (data-only) in square brackets>
Error in stanc(model_code = paste(program, collapse = "\n"), model_name = model_cppname,  : 
  failed to parse Stan model 'foo' due to the above error.

I fought with it a bit and finally got the parser to pass by changing the reals for log_theta and lps to vectors, and moving the size declaration square brackets to the type specification for those two and for mu. Was this the right thing to do? Did I miss something? If this was the right thing to do for the program, what’s the best way to share a revision of the code upstream?

It should say

ordered[K] mu; // locations of mixture components

The key is that the caret (^) is pointing at the place where the parser was expecting something other than what it found:

   8:   ordered mu[K]; // locations of mixture components
               ^

The parser indicates what it was expecting:

PARSER EXPECTED: <size declaration: integer (data-only) in square brackets>

Here, the fix is to do what Ben suggests and give it that size declaration where it’s pointing:

ordered[K] mu; 

For future travelers… one can find the manual errata at an open issue with manual in the title on the Stan Github repo.