This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-27
Channels
- # admin-announcements (1)
- # announcements (1)
- # babashka (16)
- # beginners (222)
- # bristol-clojurians (6)
- # calva (13)
- # cestmeetup (5)
- # cider (19)
- # cljs-dev (2)
- # cljsrn (4)
- # clojure (65)
- # clojure-europe (31)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-uk (33)
- # clojurescript (64)
- # community-development (5)
- # core-async (18)
- # cursive (15)
- # datomic (6)
- # devcards (1)
- # emacs (18)
- # figwheel-main (102)
- # fulcro (51)
- # graalvm (2)
- # helix (8)
- # instaparse (33)
- # jobs (8)
- # jobs-discuss (3)
- # leiningen (42)
- # off-topic (88)
- # pedestal (15)
- # re-frame (18)
- # reagent (26)
- # reitit (15)
- # rum (3)
- # shadow-cljs (119)
- # spacemacs (9)
- # sql (2)
- # tools-deps (7)
Hi everyone, I'm interesting in dynamically defining grammar components. I have a big list of nouns, I'd like to incorporate them into my grammar without too much crazy. Is there some way I can add in a dynamic rule with something like nouns = coll?
You probably want instaparse.combinators
i shall take a gander
Would it be ok to do something like (str/join "|" nouns-seq)
in the grammar def
that might be more error-prone and hard to read, but it wouldn’t be more or less efficient than the combinator version
Okay cool
How many nouns are we talking? I’d be wary of putting too many into a parser rule
Because to parse text that satisfies the rule, it ultimately has to iterate through every option at every point in your text that could potentially be a noun
And if you pass a string to the parser that doesn’t successfully parse, the “failure” message will be really long
I'm using about 5-20 nouns
ah ok, that’s definitely manageable
I'm trying to just do string join on the nouns list I have, but they lose their quotes
maybe (apply str/join "|" (map #(str "'" % "'") nouns-seq))
ah beautiful
almost perfect, it gives me a ('list' 'of' 'nouns') .. not sure how to make it digestible for the parser
I think that’s where the apply str/join
comes in
oops, I was wrong, you don’t need apply
just (str/join "|" …)
Excellent! Thank you.
I'm looking forward to showing you guys what I've come up with, once it's done! 😃
can’t wait to see!
I keep ending up with a vector although I would like to use a map... I don't know if it's clojurescript
you mean for the input or the output?
the output of insta/parse
you can set :output-format :enlive
to get a map out of the parser
wizardry
Hmm, not bad, but it has :tag and :content, I could do with simply swapping [] with {}
Thanks for all the help, I'll scratch around
Can instaparse flatten a recursive structure with a rule?