clojureinstaparse

How to parse > character in Clojure Instaparse?


I am trying to parse the > character in Clojure Instaparse. I have tried |> and |\> but the parser doesn't seem to recognize any of these. Does anyone know the correct syntax?


Solution

  • You would just handle them as strings. E.g.:

    ((insta/parser 
       "S = '<' tag '>'
       tag = #'\\w+'
       ") "<html>")
    ; [:S "<" [:tag "html"] ">"]
    

    In instaparse, you can use angle brackets <> to hide parsed elements, suppressing them from the tree output.

    ((insta/parser 
       "S = <'<'> tag <'>'>
       tag = #'\\w+'
       ")  "<html>")
    ; [:S [:tag "html"]]