Structured error output format for stanc?

In short, I’m wondering whether it is possible to get a machine-readable structured error output (e.g., JSON, XML, etc) from the current stanc or a future version (stanc3).

Long version:

I’m currently trying to update the emacs stan-mode to the 2019 standards. One of the new feature is on-the-fly syntax check using flycheck (flycheck-stan. The example picture is a code with a single syntax error in cauchy_lpdf, which the on-the-fly syntax checker underlined.

But I’m having a difficulty parsing stanc error output for this. When there is only one error or info, it is fine. But when there are multiple info like deprecated syntax and an error, parsing them separately becomes little trickier.



  • Info’s do not have associated line numbers, making it difficulty to indicate it live
  • An error typically starts with " error" with associated line and column (some times just line). But in this case, the explanation “Probability function…” comes before “error…” making it difficult to capture its beginning unless all possible messages are encoded in the parser.

Ideal output

  • Machine-readable format (e.g., --json option gives the errors in json)
  • Data elements include: line, column, severity (error, warning, info, etc), one-liner error/info message, long error/info body for full description
  • If machine-readable format is too far-fetched, a consistent beginning (Error: in addition to Info:), consistent line number, one liner summary before the multi-line message body can make parsing much easier.

I had the same problem when I had a go at adding flycheck support and an Atom lintr.

1 Like

@jrnold, thanks for your comment. Is the logic for the Aom lintr available somewhere?

stan/src/stan/lang/grammars/semantic_actions_def.cpp seems to be where these messages are generated. If messages with pass = false all have the same prefix like “Error:” then it will be much easier.