Fork me on GitHub
#instaparse
<
2020-02-27
>
sova-soars-the-sora16:02:23

@mmeix it looks to me at first glance that you could make some rules span = <span> val </span> paragraph = <p> val </p> val = paragraph* | span* | val [editS: added stars to p and span in val]

sova-soars-the-sora16:02:39

the last rule allows recursion, which can infinitely nest spans or p's

sova-soars-the-sora16:02:59

notice how i defined the rigid components of the grammar on the right-hand side, with my variable, and how i use variable names only on the left-hand side.

mmeix16:02:30

That looks like a good recipe. Thanks!

sova-soars-the-sora16:02:07

i had to make sure it works before setting you out

sova-soars-the-sora16:02:33

notice how there can be multiple valid parses with the recursion now.

sova-soars-the-sora16:02:47

you'll probably need to be creative with the output to get rid of tags you don't need 😃 i forget exactly how we would delete unnecessary strings in the grammar itself, there's a way with rules i think, it might just be mathematical though lol

mmeix16:02:20

Getting rid of tags is done by enclosing them with <…>

mmeix16:02:38

Thanks for the gist!

mmeix16:02:52

Now I’m thinking, if it would be possible to get a general solution without enumerating all possible tags (span, p , …). It would need to somehow remember the tag name until its closing cousin arrives

mmeix16:02:16

Didn’t know http://instaparse-live.matt.is ! Great tool!

👍 4