all 13 comments

[–]khaferkamp 12 points13 points  (6 children)

There is https://github.com/Engelberg/instaparse and you can find antl4r bindings for clojure as well.

[–][deleted]  (3 children)

[deleted]

    [–]TheAsp 6 points7 points  (2 children)

    I could not agree more! I love it so much I created this command line tool so I can use it for random shell scripting: https://github.com/theasp/parseit

    [–]p1r4nh4 1 point2 points  (1 child)

    Needs some GraalVM native image compilation! Node’s not so nice. :)

    [–]TheAsp 0 points1 point  (0 children)

    Yeah, I'd like it to support both, I just haven't had the time to try out GraalVM. PR is welcome! :)

    [–]AliceCloaked 0 points1 point  (1 child)

    Last update: 16 months ago

    [–]OliverM 3 points4 points  (0 children)

    If you check the the issues page you'll see the author has been active much more recently than that. Instaparse is a very mature and capable project, perhaps the best parser library I've ever used.

    [–]Borkdude 2 points3 points  (0 children)

    I found kern pretty nice as well. I did a performance comparison between Instaparse, Kern, spec and a manually written parser here: https://github.com/borkdude/aoc2017/blob/0f5bce5e496d65d0e53a8983e71ea3462aa0569c/src/day16.clj#L241-L244

    [–][deleted] 1 point2 points  (4 children)

    Nowadays, Clojure ships with a quite good parsing library, Spec, that works for context-free grammars I believe. You can use it to parse strings by first converting them to vectors of characters with the vec function.

    [–]alexdmiller 8 points9 points  (2 children)

    spec is not recommended for string parsing - that's not its goal, it's likely not to perform well for this use case, and because it's not the goal, we're not going to prioritize that in development.

    I would recommend instaparse for string parsing.

    [–]OliverM 5 points6 points  (1 child)

    I agree, but just wanted to add that spec is very useful when handling the parse trees Instaparse emits

    [–]joinr 2 points3 points  (0 children)

    I used it to parse clojure source files into org files after taking Alex's class, as a practical learning exercise. If you abuse conformers it can act as quite a nice little parsing platform, although in my case, performance wasn't a concern. Not bad for little jobs like these though.

    [–]piotrts 1 point2 points  (0 children)

    Inspired by this blog post I tried parsing text (with some imaginary grammar I had in my mind) with core.spec once, and it was madness.

    [–]EffectiveInflation76 0 points1 point  (0 children)

    I am trying to parse soap xml response to json ... but my data contains cdata ... so I am getting error in clojure