Currently __parse() returns an error count. There is no clean way to return %% from the top rule to the __parse() caller. The only way is to use an ugly global variable. And this makes parsing non thread safe.
Instead __parse() could return an object containing:
- src: the parsed string
- errors: the error list
- result: %% of the top grammar rule
For an attempt to implement this around the current (0.30) JS/CC generated code, see http://registry-files-tools.googlecode.com/svn-history/r3/trunk/msreg.par
This is a good idea, especially because ECMAScript is typeless.
I also need this behavior.
The code generated should have a namespace and everything could be inside.
Then a call that could look like this:
JSCC.parse('my string to parse')
would return what the parser returned as the top rule.