Search code examples
clojureinstaparse

How do you get instaparse to skip whitespace?


How do you get instaparse to skip whitespace between tokens?

(I could of course define whitespace as a token in its own right and insert it between all the elements on the right hand side of every rule, but I'm dealing with a grammar that has over three hundred rules, and hoping for a way to say it once rather than three hundred times.)


Solution

  • You can pass an optional parameter to turn on auto-whitespace:

    (doc insta/parser)
    -------------------------
    instaparse.core/parser
    ([grammar-specification & {:as options}])
       :auto-whitespace (:standard or :comma)
       or
       :auto-whitespace custom-whitespace-parser