jlex 1.2.0 → 1.2.2
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/README.md +23 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,18 +8,27 @@
|
|
|
8
8
|
## Usage
|
|
9
9
|
|
|
10
10
|
```
|
|
11
|
-
npx jlex
|
|
12
|
-
|
|
11
|
+
npx jlex --help
|
|
12
|
+
Usage: jlex [options] <filename>
|
|
13
|
+
|
|
14
|
+
A tiny wrapper around jison-lex that allows you to use jison-lex as a standalone (flex like) processor.
|
|
13
15
|
|
|
16
|
+
Options:
|
|
17
|
+
-V, --version output the version number
|
|
18
|
+
-o, --output <fileName> Output file name
|
|
19
|
+
-v, --verbose Enable verbose output
|
|
20
|
+
-h, --help display help for command
|
|
21
|
+
See https://github.com/ULL-ESIT-PL/jlex/blob/main/README.md for more help
|
|
22
|
+
```
|
|
14
23
|
|
|
15
24
|
## Example
|
|
16
25
|
|
|
17
|
-
`jlex` is a tiny wrapper around
|
|
26
|
+
`jlex` is a tiny wrapper around [Zaach jison-lex](https://www.npmjs.com/package/jison-lex) that allows you to use the script
|
|
18
27
|
`jlex` as standalone (`flex` like) processor.
|
|
19
28
|
|
|
20
29
|
Assuming the following lexer in file [examples/example.l](examples/example.l):
|
|
21
30
|
|
|
22
|
-
```
|
|
31
|
+
```js
|
|
23
32
|
comment [/][*](.|[\r\n])*?[*][/]
|
|
24
33
|
%%
|
|
25
34
|
\s+|{comment} /* skip whitespace */
|
|
@@ -32,7 +41,13 @@ comment [/][*](.|[\r\n])*?[*][/]
|
|
|
32
41
|
Compile it with:
|
|
33
42
|
|
|
34
43
|
```
|
|
35
|
-
|
|
44
|
+
➜ jlex git:(main) ./jlex.js examples/example.l -v -o examples/example.js
|
|
45
|
+
📖 Reading lexer grammar from: examples/example.l
|
|
46
|
+
📝 Generated 11340 characters of lexer code
|
|
47
|
+
🔄 Applied transformation pattern: /var\s+lexer\s*=/
|
|
48
|
+
📝 Writing file: examples/example.js
|
|
49
|
+
✅ Successfully processed examples/example.l → examples/example.js
|
|
50
|
+
📊 Output size: 11.1KB
|
|
36
51
|
```
|
|
37
52
|
|
|
38
53
|
This produces a Common.JS module `examples/example.js` you can use with a simple `require` like in the file [main.js](examples/main.js) below:
|
|
@@ -82,8 +97,9 @@ When you execute the former program, you get:
|
|
|
82
97
|
|
|
83
98
|
## Using the lexer from a Jison grammar
|
|
84
99
|
|
|
85
|
-
In
|
|
86
|
-
of setting the
|
|
100
|
+
In folder [examples/](examples/) you'll find an example
|
|
101
|
+
of [grammar](examples/grammar.jison#L32-L33) setting the lexer generated by `jlex` from the file
|
|
102
|
+
[examples/example.l](examples/example.l) to be used from the Jison grammar. The key is
|
|
87
103
|
to set the `lex` attribute of the `parser` object to the generated lexer:
|
|
88
104
|
|
|
89
105
|
```js
|