2019-11-08 16:55:34 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const process = require("process");
|
|
|
|
const fs = require("fs");
|
2019-11-09 19:49:34 +01:00
|
|
|
const _ = require("lodash");
|
2019-11-08 16:55:34 +01:00
|
|
|
|
|
|
|
const file = process.argv[2];
|
|
|
|
const lines = fs
|
|
|
|
.readFileSync(file)
|
|
|
|
.toString()
|
|
|
|
.split("\n");
|
|
|
|
|
|
|
|
const definitions = {};
|
|
|
|
lines.forEach(line => {
|
2019-11-09 19:49:34 +01:00
|
|
|
// Constants
|
2019-11-08 16:55:34 +01:00
|
|
|
Object.keys(definitions).forEach(k => {
|
|
|
|
line = line.replace(
|
2019-11-09 19:49:34 +01:00
|
|
|
new RegExp("(\\s)" + _.escapeRegExp(k) + "(\\s|\\))", "g"),
|
2019-11-08 22:22:52 +01:00
|
|
|
"$1" + definitions[k] + " (; = " + k + " ;)$2"
|
2019-11-08 16:55:34 +01:00
|
|
|
);
|
|
|
|
});
|
2019-11-08 21:53:56 +01:00
|
|
|
const m = line.match(/^;;\s+([!a-zA-Z0-9_]+)\s*:=\s*([^\s]+)/);
|
2019-11-08 16:55:34 +01:00
|
|
|
if (m) {
|
|
|
|
definitions[m[1]] = m[2];
|
|
|
|
}
|
2019-11-09 19:49:34 +01:00
|
|
|
|
2019-11-08 21:53:56 +01:00
|
|
|
console.log(line);
|
2019-11-08 16:55:34 +01:00
|
|
|
});
|