This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-25
Channels
- # 100-days-of-code (6)
- # announcements (4)
- # aws (2)
- # beginners (151)
- # boot (1)
- # calva (1)
- # cider (19)
- # clara (47)
- # cljdoc (9)
- # cljs-dev (25)
- # clojars (18)
- # clojure (151)
- # clojure-canada (1)
- # clojure-conj (1)
- # clojure-dev (17)
- # clojure-italy (42)
- # clojure-nl (34)
- # clojure-spec (67)
- # clojure-uk (125)
- # clojurescript (163)
- # core-async (106)
- # cursive (19)
- # data-science (11)
- # datomic (9)
- # duct (2)
- # figwheel (1)
- # figwheel-main (6)
- # fulcro (97)
- # graphql (9)
- # instaparse (4)
- # jobs (6)
- # jobs-discuss (21)
- # leiningen (62)
- # mount (23)
- # off-topic (16)
- # re-frame (15)
- # reagent (16)
- # reitit (5)
- # remote-jobs (1)
- # ring-swagger (9)
- # shadow-cljs (176)
- # tools-deps (102)
- # unrepl (3)
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:
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