fix replasing

This commit is contained in:
Aleksey Chichenkov 2019-01-30 16:53:12 +03:00
parent 7237cf3c54
commit 653db60651
2 changed files with 6 additions and 3 deletions

View File

@ -18,6 +18,7 @@ exec("re2c -i " + inp, function(err, stdout, stderr) {
});
var post_process_lexer = function (_string) {
var output = args["o"] || "lexer.js";
// replace start and end fbrackets
_string = _string.replace(/START\n\{/gm, "");
@ -25,7 +26,10 @@ var post_process_lexer = function (_string) {
_string = _string.replace(/^.*(_r2c_var_.*;|unsigned int yyaccept = 0;)\n/gm, ""); // replace var yych;
_string = _string.replace(/(yych = \*this._yy_cursor);\n/gm, "\tcase 1:\n yych = this._string[this._yy_cursor];\n"); // insert "case 1:" before;
_string = _string.replace(/\*\((.*?)\);/gm, "this._string[($1)];"); // замена разыменовываний
_string = _string.replace(/\*(.* ?);/gm, "this._string[$1];"); // замена разыменовываний
_string = _string.replace(/^yy(\d*?):/gm, "case $1:"); // replace goto marker onto case
_string = _string.replace(/\) goto yy(\d*?);/gm, ") { id = $1; break; }"); // replace goto inside if
_string = _string.replace(/goto yy(\d*?);/gm, "id = $1; break;"); // replace goto outside if
@ -55,7 +59,6 @@ var post_process_lexer = function (_string) {
}
}
var output = args["o"] || "lexer.js";
_string = process_metatags(_string);

View File

@ -4,7 +4,7 @@
var fs = require("fs");
var exec = require('child_process').exec;
exec("node main.js -o=lexer_test.js -t=node", function(err, stdout, stderr) {
exec("node main.js -o=lexer_test.js -t=node -logs", function(err, stdout, stderr) {
err && console.log("ERROR: ", err);
err && process.exit(1);