instaparse

If you're not trampolining your parser, why bother getting up in the morning?
mmeix 2020-02-21T09:19:29.007900Z

New to Instaparse and wrapping my head around grammars: how would I write a grammar that can do nested tag pairs like in xml: "<p><span>text</span></p>" => [:p [:span text]] ?

aengelberg 2020-02-27T00:37:56.005Z

it’s possible to parse XML hierarchies into Clojure data, however I don’t think you can enforce that the tags must be matching.

aengelberg 2020-02-27T00:38:36.005300Z

You can enforce that manually with your own custom logic after the fact, just not as part of the parser.

mmeix 2020-02-27T17:03:00.014Z

So I would just trust, that tags are properly matched/paired/nested.

mmeix 2020-02-27T17:03:46.014200Z

and take each closing tag as the next needed

2020-02-21T12:30:44.011400Z

caveat: I haven’t had my coffee yet, but the basic idea is that you say something like “a BLOCK element is a P or a DIV or a TABLE (etc), an INLINE element is a SPAN or a B or TEXT (etc),” and then say “a P element is the literal string ‘<P>’ or ‘<p>’ followed by zero or more INLINE elements, followed by the literal string ‘</P>’ or ‘</p>’.” And similarly with SPAN.

mmeix 2020-02-21T13:11:36.012100Z

ah! thanks ... that should start it

2020-02-21T13:13:52.012700Z

The other caveat is that Instaparse is incredibly fun to work with and may be addictive. 😉

mmeix 2020-02-21T14:32:29.013100Z

Confirmed! 😁