Make generated parsers thread-safe
Currently "global" variables like yytext, yyleng, $$, etc. are implemented either as module-level variables (in JS), or static class variables (in some plugins, C#, PHP, etc).
This makes parsing several files in parallel (e.g. in threads) impossible, since they mutate the same "global" data. We should make them instance variables, and always export a class for Tokenizer and the Parser (instead of a singleton instance which just access the global or static class variables).
This will require rewriting global code in handles like:
yytext = yytext.slice(1, -1);
to an instance property access. Currently we already rewrite it to static props access in some plugins):
Yyparse.yytext = Yyparse.yytext.slice(1, -1);
Eventually should be instance prop (specific to each plugin) instead of static one:
this.yytext = this.yytext.slice(1, -1);
You might look at the lemon parser used by SQLite for techniques to fix this. It’s been thread-safe since it was initially written.
It’s also in use at http://pikchr.org