Skip to content

Commit

Permalink
- updated Makefile to properly patch the modules' library files while…
Browse files Browse the repository at this point in the history
… they get copied into lib/util/

- patched all `require()` statements in the examples as well to match the 'scoped package' dependencies listed in package.json. This is also related to #11. Grmbkl!@#$%^&*!
- jison modules DO NOT belong in the **dependencies**, but should reside in the **devDependencies**. Where I screwed this up, I don't know (git blame should hand me the answer to that but I'll do that later when I feel like it), but now that we move towards 'scoped packages' it's biting me in the aXX!  :-(
- regenerated library files
  • Loading branch information
GerHobbelt committed Aug 27, 2017
1 parent 105211d commit a4324ab
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 142 deletions.
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,16 @@ build_bnf: lib/util/parser.js
lib/util/parser.js: $(JISON_DEPS) submodules prep_util_dir \
lib/cli.js lib/jison.js modules/ebnf-parser/bnf.y modules/ebnf-parser/bnf.l
NODE_PATH=lib/util node lib/cli.js -o $@ modules/ebnf-parser/bnf.y modules/ebnf-parser/bnf.l
cat $@ | node __patch_require.js > $@-tmp.js
mv -f $@-tmp.js $@.js

build_lex: lib/util/lex-parser.js

lib/util/lex-parser.js: $(JISON_DEPS) submodules prep_util_dir \
lib/cli.js lib/jison.js modules/lex-parser/lex.y modules/lex-parser/lex.l
NODE_PATH=lib/util node lib/cli.js -o $@ modules/lex-parser/lex.y modules/lex-parser/lex.l
cat $@ | node __patch_require.js > $@-tmp.js
mv -f $@-tmp.js $@.js

prep_util_dir:
@[ -d modules/ebnf-parser/node_modules/jison-gho/lib/util ] || echo "### FAILURE: Make sure you have run 'make prep' before as the jison compiler backup utility files are unavailable! ###"
Expand All @@ -414,22 +418,22 @@ prep_util_dir:


lib/util/regexp-set-management.js: modules/jison-lex/regexp-set-management.js
cat $< > $@
cat $< | node __patch_require.js > $@

lib/util/safe-code-exec-and-diag.js: modules/jison-lex/safe-code-exec-and-diag.js
cat $< > $@
cat $< | node __patch_require.js > $@

lib/util/regexp-lexer.js: modules/jison-lex/regexp-lexer.js
cat $< | sed -e 's/require("lex-parser")/require(".\/lex-parser")/' -e "s/require('lex-parser')/require('.\/lex-parser')/" > $@
cat $< | node __patch_require.js > $@

lib/util/ebnf-parser.js: modules/ebnf-parser/ebnf-parser.js submodules
cat $< | sed -e 's/require("lex-parser")/require(".\/lex-parser")/' -e "s/require('lex-parser')/require('.\/lex-parser')/" > $@
cat $< | node __patch_require.js > $@

lib/util/ebnf-transform.js: modules/ebnf-parser/ebnf-transform.js submodules
cat $< > $@
cat $< | node __patch_require.js > $@

lib/util/transform-parser.js: modules/ebnf-parser/transform-parser.js submodules
cat $< > $@
cat $< | node __patch_require.js > $@


submodules:
Expand Down
21 changes: 21 additions & 0 deletions __patch_require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// patch the require() statements in the javascript fed to us via STDIN
//

const getStdin = require('get-stdin');

getStdin().then(str => {
const modules = "regexp-set-management safe-code-exec-and-diag regexp-lexer ebnf-parser ebnf-transform transform-parser lex-parser".split(' ');

modules.forEach(function repl_module(name) {
var re = new RegExp(`require\\([^)]*?${name}['"]\\)`, 'g');

str = str
.replace(re, `require('./${name}')`);

return str;
});

console.log(str);
});

4 changes: 2 additions & 2 deletions examples/compiled_calc_const_rewrite_postprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// a very smart JS JIT compiler any more for doing this as we now perform
// this task manually...)

var recast = require('recast');
var recast = require('@gerhobbelt/recast');
var fs = require('fs');
var path = require('path');
var json5 = require('json5');
var json5 = require('@gerhobbelt/json5');
var assert = require("assert");

var types = recast.types;
Expand Down
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var Jison = require('./jison.js');

var json5 = require('json5');
var json5 = require('@gerhobbelt/json5');


function getCommandlineOptions() {
Expand Down
16 changes: 8 additions & 8 deletions lib/jison.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ var Lexer = require('./util/regexp-lexer.js');
var ebnfParser = require('./util/ebnf-parser.js');
var lexParser = require('./util/lex-parser.js');
var code_exec = require('./util/safe-code-exec-and-diag.js');
var XRegExp = require('xregexp');
//var recast = require('recast');
var XRegExp = require('@gerhobbelt/xregexp');
//var recast = require('@gerhobbelt/recast');
//var codeShift = require('jscodeshift');
var json5 = require('json5');
var json5 = require('@gerhobbelt/json5');
var assert = require('assert');


Expand Down Expand Up @@ -1907,27 +1907,27 @@ generator.buildProductionActions = function buildProductionActions() {
// the usual situation: `$3`; MUST reference an rhs[] element or it will be considered an ERROR:
if (v > 0) {
if (len - v < 0) {
throw new Error('invalid token reference in action code for rule: "' + rule4msg + '"');
throw new Error(`invalid token reference "\$${v}" in action code for rule: "${rule4msg}"`);
}
v = len - v;
if (v) {
return ' - ' + v;
return ` - ${v}`;
}
// do not generate code for superfluous `- 0` JS expression:
return '';
}
// the VERY UNusual situation: `$-1`: referencing *parent* rules' values
if (v < 0) {
return ' - ' + (len - v);
return ` - ${len - v}`;
}
// decode error?
if (v !== 0) {
throw new Error('invalid token reference in action code for rule: "' + rule4msg + '"');
throw new Error(`invalid token reference "\$${v}" in action code for rule: "${rule4msg}"`);
}
// the slightly unusual situation: `$0` (instead of `$$`)
v = len;
if (v) {
return ' - ' + v;
return ` - ${v}`;
}
// do not generate code for superfluous `- 0` JS expression:
return '';
Expand Down
6 changes: 4 additions & 2 deletions lib/util/ebnf-parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var bnf = require("./parser");
var ebnf = require("./ebnf-transform");
var jisonlex = require("./lex-parser");
var ebnf = require('./ebnf-transform');
var jisonlex = require('./lex-parser');

var version = '0.6.0-186'; // require('./package.json').version;

exports.parse = function parse(grammar) {
Expand Down Expand Up @@ -87,3 +88,4 @@ var parseLex = function bnfParseLex(text, position) {
}
return jisonlex.parse(prelude + text);
};

3 changes: 2 additions & 1 deletion lib/util/ebnf-transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var EBNF = (function () {
var parser = require('./transform-parser.js');
var XRegExp = require('xregexp');
var XRegExp = require('@gerhobbelt/xregexp');
//var assert = require('assert');

var devDebug = 0;
Expand Down Expand Up @@ -361,3 +361,4 @@ var EBNF = (function () {

exports.transform = EBNF.transform;


Loading

0 comments on commit a4324ab

Please sign in to comment.