instaparse

If you're not trampolining your parser, why bother getting up in the morning?
schmee 2018-10-25T21:03:56.000100Z

hey folks! I’m trying to write my first parser for a very simple file format. I’ve made it work, but my solution uses negative lookahead. Is there any way to write a grammar that produces the same output without negative lookahead? here a REPL example:

schmee 2018-10-25T21:04:00.000100Z

user=> (def s
   #_=>   "NAME=Thing 1
   #_=> ACTIVE=120201-171231
   #_=>
   #_=> NAME=Thing 2
   #_=> ACTIVE=120201-171231")
   #_=>
#'user/s

user=> (def grammar
   #_=>   (insta/parser
   #_=>     "top = (block <newline?>)+
   #_=>      block = line+ !line
   #_=>      line = key <'='> value <newline?>
   #_=>      key = #'[A-Z]+'
   #_=>      value = #'[^\n]*'
   #_=>      newline = '\n'"))
   #_=>
#'user/grammar

user=> (clojure.pprint/pprint (insta/parse grammar s))
[:top
 [:block
  [:line [:key "NAME"] [:value "Thing 1"]]
  [:line [:key "ACTIVE"] [:value "120201-171231"]]]
 [:block
  [:line [:key "NAME"] [:value "Thing 2"]]
  [:line [:key "ACTIVE"] [:value "120201-171231"]]]]
nil

schmee 2018-10-25T21:08:19.000100Z

if there’s any other way to simplify it I’d love to hear about it 🙂

socksy 2018-11-01T12:13:14.000300Z

I don't have a repl to hand, but couldn't you use a newline as a character separator rather than a negative look ahead for another line?