[ccan] The lemon parser as a ccan module

Tim Post echo at echoreply.us
Mon Apr 13 20:08:37 EST 2009


Hi Joel, 

On Sun, 2009-04-12 at 20:46 -0400, Joel C. Salomon wrote:
> > /tmp/foo/%s/jobs/%d.out
> <snip>
> > So either I come up with a hand rolled parser that knows to expand %s to
> > a process name and %d to a job id (despite presence or order), or I
> > depend on a generator that the user may or may not have, all to deal
> > with a single string.
> 
> Sounds like a job for an extensible printf like Plan 9's libfmt,

Thank you for the links, that is going to come in really really handy.

In this case, I didn't want to introduce new verbs.. I just wanted a
normal printf format with a smarter way to expand variadic arguments.
Given a format with "%s .. %d" , or "%d .. %s ..." or nothing to expand
at all.

I finally resorted to some clever (but hard to read) pointer arithmetic,
but meanwhile I discovered lemon. I just could not make myself add a
thousand lines of code (or a parser) to handle just one string :)

> The lemon parser idea still sounds cool, though.

I hope to eventually make ciniparser smart enough to handle anything
from INI to BIND style configurations. I think lemon would make that
easier to maintain, and its grammar easier for people who need to
tinker.

I've seen similar tools that scope and edit various kinds of
configuration files though regex "lenses", but if pcre is not available,
those lenses become as time consuming to tweak as a parser's grammar,
unless your used to POSIX regular expressions.

Something 'pcre like' was suggested as a module, but I don't think it
was very popular. So, I guess, a simple drop in parser with forgiving
grammar is a good compromise.


Cheers,
--Tim





More information about the ccan mailing list