[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Feature request
Here's a feature request for the next version of SableCC.. implementing
this is probably really easy, or else really hard... :-)
Currently, one parses the input like this:
Parser p;
Start topNode;
p = new Parser(new Lexer(input));
topNode = p.parse();
It would be nice if you could parse any arbitrary other node besides
Start, by doing something like this:
Parser p;
PSomeArbitraryProduction node;
p = new Parser(new Lexer(input), PSomeArbitraryProduction.class);
node = p.parse();
The idea being that you throw away all of the grammar except for what
could possibly be in a tree with top node PSomeArbitraryProduction.
So the parser would parse a PSomeArbitraryProduction, followed by EOF,
and then finish.
In my application, for example, stuff gets written to a file and needs
to be read in again later. For example, you write out strings into a
file like this:
string1="This is a \"doubly quoted\" string."
You want to parse everything after the equals sign as a string
token in a way that's consistent with the rest of the application.
So you might send just that input to the parser, and get a PString
node back.
I'd be interested in what the right parser strategy for implementing
this might be. Would you just create two new parser states for each node
type? E.g.:
. node EOF
and
node . EOF
These states would never be entered during a "complete" parse.
-Archie
___________________________________________________________________________
Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com