clojureinstaparse

Easiest way to get an error message as a string in Instaparse?


Instaparse can pprint nice error messages to the REPL

=> (negative-lookahead-example "abaaaab")
Parse error at line 1, column 1:
abaaaab
^
Expected:
NOT "ab"

but I can not find a built-in function to get the message as a String. How to do that?


Solution

  • You could always wrap it using with-out-str:

    (with-out-str 
      (negative-lookahead-example "abaaaab"))
    

    You may also be interested in using with-err-str documented here.

    (with-err-str 
      (negative-lookahead-example "abaaaab"))
    

    I can't remember if instaparse writes to stdout or stderr, but one of those will do what you want.