jlex 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jlex.js +30 -8
- package/package.json +4 -4
package/jlex.js
CHANGED
|
@@ -2,11 +2,33 @@
|
|
|
2
2
|
// replace example by the name of the generated module
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const { execSync } = require('child_process');
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const { Command } = require('commander')
|
|
6
|
+
const packageJson = require('./package.json')
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const program = new Command();
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.version(packageJson.version)
|
|
12
|
+
.description('A tiny wrapper around jison-lex that allows you to use jison-lex as a standalone (flex like) processor.')
|
|
13
|
+
.option("-o <fileName>", "Output file name")
|
|
14
|
+
.usage("[options] <filename>");
|
|
15
|
+
|
|
16
|
+
program.parse(process.argv);
|
|
17
|
+
const options = program.opts();
|
|
18
|
+
|
|
19
|
+
const fileName = program.args[0];
|
|
20
|
+
|
|
21
|
+
const {dir,name } = path.parse(fileName); // { dir, base, ext, name }
|
|
22
|
+
const outputFileName = options.o || path.join(dir, `${name}.js`);
|
|
23
|
+
const outputParse = path.parse(outputFileName);
|
|
24
|
+
|
|
25
|
+
const shellCommand = `npx jison-lex ${fileName} -o ${outputFileName}`;
|
|
26
|
+
try {
|
|
27
|
+
execSync(shellCommand, { encoding: 'utf-8' });
|
|
28
|
+
let lexerStr = fs.readFileSync(outputFileName, "utf8").toString();
|
|
29
|
+
let lexerModule = lexerStr.replace(new RegExp(`var ${outputParse.name} =`), `\nmodule.exports =`);
|
|
30
|
+
console.log("Writing file:", outputFileName);
|
|
31
|
+
fs.writeFileSync(outputFileName, lexerModule);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error("Error:", error.message);
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jlex",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A wrapper around jison-lex to make it work as a standalone program like Flex",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jison-lex",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
30
|
-
"example": "
|
|
30
|
+
"example": "./jlex.js examples/example.l && node examples/main.js"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"commander": "^11.0.3",
|
|
33
34
|
"jison": "^0.4.18"
|
|
34
|
-
}
|
|
35
|
-
"devDependencies": {}
|
|
35
|
+
}
|
|
36
36
|
}
|