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
thanks!
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
thank you very much
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!
it's a great wonder to have the power of magic at your fingertips! š
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?