I'm intrested to know if there exists a tool that lets you input examples of valid documents and lets you then generalize from that to a reusable parser.
I can imagine this, but everytime i start learning about parsers it gets to the granularity of something like lex and yacc and it seems more complicated than my instincts say it should be.
So I'm left wondering if
- a) it's just fundamentally that complicated and I need to see it or
- b) there's a way to build ad-hoc DSLs for relatively simple tasks that I could learn about
Update: a simple example of an "ad hoc" dsl i might like to make quickly.
Instead of the XML
<foo> <item>bar</item> <item>bat</item> </foo>
I might want something like:
foo bar bat
- lines contain data items
- indentation produces parent-child relations
My imaginary tool lets me convey the above information.
Then, in my imaginary tool, I might highlight "foo" above and right click, at which point it would prompt me to restrict the values to a choice list....
Then I might extend the first one to:
foo bar(5) bat
- in a line, '(' and ')' surround a sub item
The above might be qualified with a boolean value that specifies recursion or not, if set to true then bar(lala(4)) might work...
This is the kind of train of thought I generally have that led me to ask the question. It's possible that now I've qualified it, the answer changes - if so I apologize in advance.