4 ms·
Most grammars define a very specific starting point for languages. This is fine of course, but what if we want to parse, say, only an expression, only a functio
by emmanueloga_ 6y ago
Most grammars define a very specific starting point for languages. This is fine of course, but what if we want to parse, say, only an expression, only a function body, etc?
I feel most parsing APIs tend to expose a single method, something like:
parser.parse(source)
... which is kind of a limited API to do the things I ask about above.
With a more flexible API, an structure aware editor [1] could keep different areas of the buffer separated, and know if the user is typing a function body, a variable definition, etc, and only parse that part w/o breaking the rest of the parser progress (is this a good idea? I think so but I don't think most editors work like this, so maybe not :-)
--
An area of parser APIs that I've recently seen trouble with is lack of metadata on the productions. I'd like to be able to do something like:
production.meta() => { :line 23, :column 10 }
... or something like that. This is very useful while error reporting, for instance. I was trying to find a parser for RDF Turtle that would do this, but couldn't find any!
1: https://en.wikipedia.org/wiki/Structure_editor https://en.wikipedia.org/wiki/Structure_editor
- userbinator 6y agoThis is fine of course, but what if we want to parse, say, only an expression, only a function body, etc? ...and this is the beauty of recursive descent: you can call the appropriate method directly to parse that part of the grammar.
- choeger 6y agoYou can always start from a different place even with an LR(k) parser. You just need to make sure that your starting point is sensible.