jlex 1.0.0 → 1.0.1
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 +88 -71
- package/package.json +26 -9
package/README.md
CHANGED
|
@@ -1,85 +1,110 @@
|
|
|
1
|
-
##
|
|
1
|
+
## Install
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
`npm i jlex`
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
6
|
|
|
7
7
|
```
|
|
8
|
-
|
|
9
|
-
Processing file: example
|
|
10
|
-
Writing file: example.js
|
|
8
|
+
npx jlex <package name>
|
|
11
9
|
```
|
|
12
10
|
|
|
11
|
+
|
|
12
|
+
## Example
|
|
13
|
+
|
|
14
|
+
`jlex` is a tiny wrapper around `jison-lex` that allows you to use the script
|
|
15
|
+
`jlex` as standalone (`flex` like) processor.
|
|
16
|
+
|
|
17
|
+
Assuming the following lexer in file `example.js`:
|
|
18
|
+
|
|
13
19
|
```
|
|
14
|
-
|
|
20
|
+
%%
|
|
21
|
+
\s+ /* skip whitespace */
|
|
22
|
+
[0-9]+ return 'NUMBER';
|
|
23
|
+
"-" return '-';
|
|
24
|
+
<<EOF>> return 'EOF';
|
|
25
|
+
. return 'INVALID';%
|
|
15
26
|
```
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
Compile it with:
|
|
18
29
|
|
|
19
|
-
```js
|
|
20
|
-
module.exports = example;
|
|
21
30
|
```
|
|
31
|
+
➜ jlex-test npx jlex example
|
|
32
|
+
Processing file: example
|
|
33
|
+
Writing file: example.js
|
|
34
|
+
```
|
|
22
35
|
|
|
23
|
-
|
|
36
|
+
This produces a Common.JS module `example.js` you can use with a simple `require` like in the file `main.js` below:
|
|
24
37
|
|
|
38
|
+
```js
|
|
39
|
+
const lex = require("./example");
|
|
40
|
+
lex.setInput("2\n-\n3")
|
|
41
|
+
|
|
42
|
+
const results = [];
|
|
43
|
+
|
|
44
|
+
results.push({ type: lex.lex(), lexeme: lex.yytext, loc: lex.yylloc });
|
|
45
|
+
results.push({ type: lex.lex(), lexeme: lex.yytext, loc: lex.yylloc });
|
|
46
|
+
results.push({ type: lex.lex(), lexeme: lex.yytext, loc: lex.yylloc });
|
|
47
|
+
results.push({ type: lex.lex(), lexeme: lex.yytext, loc: lex.yylloc });
|
|
48
|
+
|
|
49
|
+
console.log(results);
|
|
50
|
+
/*
|
|
51
|
+
➜ examples git:(main) ✗ node main.js
|
|
52
|
+
[
|
|
53
|
+
{
|
|
54
|
+
type: 'NUMBER',
|
|
55
|
+
lexeme: '2',
|
|
56
|
+
loc: { first_line: 1, last_line: 1, first_column: 0, last_column: 1 }
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: '-',
|
|
60
|
+
lexeme: '-',
|
|
61
|
+
loc: { first_line: 2, last_line: 2, first_column: 0, last_column: 1 }
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: 'NUMBER',
|
|
65
|
+
lexeme: '3',
|
|
66
|
+
loc: { first_line: 3, last_line: 3, first_column: 0, last_column: 1 }
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'EOF',
|
|
70
|
+
lexeme: '',
|
|
71
|
+
loc: { first_line: 3, last_line: 3, first_column: 1, last_column: 1 }
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
*/
|
|
25
75
|
```
|
|
26
|
-
|
|
27
|
-
Welcome to Node.js v25.6.0.
|
|
28
|
-
Type ".help" for more information.
|
|
29
|
-
> lex = require("./example.js")
|
|
30
|
-
{
|
|
31
|
-
EOF: 1,
|
|
32
|
-
parseError: [Function: parseError],
|
|
33
|
-
setInput: [Function: setInput],
|
|
34
|
-
input: [Function: input],
|
|
35
|
-
unput: [Function: unput],
|
|
36
|
-
more: [Function: more],
|
|
37
|
-
reject: [Function: reject],
|
|
38
|
-
less: [Function: less],
|
|
39
|
-
pastInput: [Function: pastInput],
|
|
40
|
-
upcomingInput: [Function: upcomingInput],
|
|
41
|
-
showPosition: [Function: showPosition],
|
|
42
|
-
test_match: [Function: test_match],
|
|
43
|
-
next: [Function: next],
|
|
44
|
-
lex: [Function: lex],
|
|
45
|
-
begin: [Function: begin],
|
|
46
|
-
popState: [Function: popState],
|
|
47
|
-
_currentRules: [Function: _currentRules],
|
|
48
|
-
topState: [Function: topState],
|
|
49
|
-
pushState: [Function: pushState],
|
|
50
|
-
stateStackSize: [Function: stateStackSize],
|
|
51
|
-
options: { moduleName: 'example' },
|
|
52
|
-
performAction: [Function: anonymous],
|
|
53
|
-
rules: [ /^(?:\s+)/, /^(?:[0-9]+)/, /^(?:-)/, /^(?:$)/, /^(?:.)/ ],
|
|
54
|
-
conditions: { INITIAL: { rules: [Array], inclusive: true } }
|
|
55
|
-
}
|
|
56
|
-
```
|
|
76
|
+
When you execute the former program, you get:
|
|
57
77
|
|
|
58
|
-
Now:
|
|
59
78
|
|
|
60
79
|
```js
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
'-'
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
➜ jlex-test node main.js
|
|
81
|
+
[
|
|
82
|
+
{
|
|
83
|
+
type: 'NUMBER',
|
|
84
|
+
lexeme: '2',
|
|
85
|
+
loc: { first_line: 1, last_line: 1, first_column: 0, last_column: 1 }
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: '-',
|
|
89
|
+
lexeme: '-',
|
|
90
|
+
loc: { first_line: 2, last_line: 2, first_column: 0, last_column: 1 }
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: 'NUMBER',
|
|
94
|
+
lexeme: '3',
|
|
95
|
+
loc: { first_line: 3, last_line: 3, first_column: 0, last_column: 1 }
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: 'EOF',
|
|
99
|
+
lexeme: '',
|
|
100
|
+
loc: { first_line: 3, last_line: 3, first_column: 1, last_column: 1 }
|
|
101
|
+
}
|
|
102
|
+
]
|
|
76
103
|
```
|
|
77
104
|
|
|
78
|
-
|
|
79
|
-
|
|
105
|
+
Here is a description of the lexer object:
|
|
80
106
|
|
|
81
|
-
```
|
|
82
|
-
> lex = require("./example")
|
|
107
|
+
```js
|
|
83
108
|
{
|
|
84
109
|
EOF: 1,
|
|
85
110
|
parseError: [Function: parseError],
|
|
@@ -106,12 +131,4 @@ Now:
|
|
|
106
131
|
rules: [ /^(?:\s+)/, /^(?:[0-9]+)/, /^(?:-)/, /^(?:$)/, /^(?:.)/ ],
|
|
107
132
|
conditions: { INITIAL: { rules: [Array], inclusive: true } }
|
|
108
133
|
}
|
|
109
|
-
> lex.setInput("2 - 3")
|
|
110
|
-
> lex.lex()
|
|
111
|
-
'NUMBER'
|
|
112
|
-
> lex.yytext
|
|
113
|
-
'2'
|
|
114
|
-
> lex.yylloc
|
|
115
|
-
{ first_line: 1, last_line: 1, first_column: 0, last_column: 1 }
|
|
116
|
-
>
|
|
117
134
|
```
|
package/package.json
CHANGED
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jlex",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "jlex.js",
|
|
3
|
+
"version": "1.0.1",
|
|
5
4
|
"description": "A wrapper around jison-lex to make it work as a standalone program like Flex",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"jison-lex",
|
|
7
|
+
"jison",
|
|
8
|
+
"flex"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/ULL-ESIT-PL/jlex#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ULL-ESIT-PL/jlex/issues"
|
|
9
13
|
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/ULL-ESIT-PL/jlex.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"author": "Casiano Rodriguez Leon <crguezl@ull.edu.es> (https://crguezl.github.io/)",
|
|
20
|
+
"type": "commonjs",
|
|
21
|
+
"main": "jlex.js",
|
|
10
22
|
"bin": {
|
|
11
23
|
"jlex": "jlex.js"
|
|
12
24
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
"directories": {
|
|
26
|
+
"example": "examples"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
30
|
+
"example": "cd examples && ../jlex.js example"
|
|
31
|
+
},
|
|
16
32
|
"dependencies": {
|
|
17
33
|
"jison": "^0.4.18"
|
|
18
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {}
|
|
19
36
|
}
|