<div dir="ltr">I recently enjoyed using parslet (once I learned about using the output transformations). <br><br><a href="http://kschiess.github.io/parslet/">http://kschiess.github.io/parslet/</a><div><br></div><div>I haven't used treetop so can't compare parselet with treetop. Anyone?</div>
<div><br></div><div>regards</div><div>mark<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 14, 2014 at 9:11 AM, Tim Cowlishaw <span dir="ltr"><<a href="mailto:tim@timcowlishaw.co.uk" target="_blank">tim@timcowlishaw.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">It sounds like you need Parsing Expression Grammars, a nice, declarative way of solving exactly this sort of problem.<div>
<br></div><div>Treetop is probably the most-used ruby implementation: <a href="http://treetop.rubyforge.org/" target="_blank">http://treetop.rubyforge.org/</a></div>
<div><br></div><div>However, the canonical use-case for this sort of thing is writing parsers for programming languages, and I've been unable to find documentation or examples for the use-cases you describe. Still the principles should be the same.</div>
<div><br></div><div>Hope this helps!</div><div><br></div><div>Cheers,</div><div><br></div><div>Tim</div><div><div class="h5"><div><br></div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On 14 May 2014 08:49, Andrew Stewart <span dir="ltr"><<a href="mailto:boss@airbladesoftware.com" target="_blank">boss@airbladesoftware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hello El Rug!<br>
<br>
>From time to time I encounter a situation where I would like to parse (semi-)structured text. I'm sure this is trivial with the correct approach. Regrettably I don't know anything about parsers/compilers/etc and I end up hand-rolling fragile, line-based state machines which are soon impossible to reason about.<br>
<br>
I'd like to know how to do this properly but I don't know where to begin.<br>
<br>
Here are a couple of specific examples:<br>
<br>
- In 2006 before SASS etc existed, I wrote a Rails plugin for nested CSS. It read a nested stylesheet and flattened it into normal CSS. Back then I wasn't sure how to parse a nested stylesheet...and I still don't know how. (Stop laughing at the back!)<br>
<br>
- A few months ago I needed to convert hospital admissions records from a PDF to CSV. Each record had fields like id, name, various dates, clinical history, attending doctor, etc. The fields weren't always in the same order due to the layout of text in the PDF, and some fields were optional. Sometimes there were several fields on a line, and a field could be spread over several lines. I did my usual thing of looping over each line, matching field names with regular expressions, and trying to keep track of where I was with a state variable. Its sole virtue was that it (sort of) worked; otherwise it was horrible: hard to understand, hard to modify, hard to extend, and very hard to debug.<br>
<br>
Please could someone enlighten me?<br>
<br>
Cheers,<br>
Andy Stewart<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div><br></div></div></div></div></div>
<br>_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br><div><font color="#666666"><br></font></div>
</div></div></div>