Looking for tool to replace 'real xyz [nnn]' with 'array [nnn] real xyz'

Hi, I’m working with CmdStan 2.31.0 and stanc emits warning messages such as the following:

Warning in 'tmp1.stan', line 127, column 4: Declaration of arrays by placing
    brackets after a variable name is deprecated and will be removed in Stan
    2.32.0. Instead use the array keyword before the type. This can be
    changed automatically using the auto-format flag to stanc

I guess that’s from instances of real xyz [nnn], which, I gather from the message, are going to be discontinued at some point in the near future. Looks like I just need to replace that with array [nnn] real xyz.

I am looking for an existing tool or whatever to carry out just that conversion, as I have a number of models, so I’d rather not do it by hand, and I’d rather not reinvent the wheel if someone else has already tackled it. There are several variations, and getting the regular expression syntax just right is a delicate operation.

I know that I can say stanc --auto-format and that rewrites the array declarations, but it also rewrites everything else, which I’d rather not.

Thanks in advance for any light you can shed on this problem.

Robert Dodier

I updated the Stan documentation using a series of regular expressions. As you suggest, this was a bit of a pain, but did work.

For Stan source code the auto formatter built into Stanc3 is the only existing tool which I know of. May I ask what it does that you find undesirable?

Hi Brian, thanks for your reply.

Yeah, I’m plodding through the business with regular expressions, and it looks like I can get it sorted out.

About the auto formatter, it has different ideas about white space and line breaking than I do. I know, one can say, well, Robert, why not just do it the way everybody else does it? I don’t have any defense except to say I like it this way, and aside from that, changing the formatting around is orthogonal to the problem of changing array syntax – it’s too bad the two cannot be separated.

All the best,


Fair enough. It is indeed unfortunate that the automated way is all-or-nothing due to cases like this