@formulavize/lezer-fiz 0.1.1 → 0.2.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/.github/workflows/ci.yml +13 -21
- package/README.md +1 -0
- package/dist/index.cjs +66 -40
- package/dist/index.es.js +66 -38
- package/package.json +16 -11
- package/rollup.config.js +15 -14
- package/src/fiz.grammar +18 -12
- package/src/highlight.js +5 -2
- package/src/tokens.js +65 -33
- package/test/assignments.txt +8 -8
- package/test/calls.txt +31 -25
- package/test/namespaces.txt +171 -0
- package/test/qualifiers.txt +94 -0
- package/test/statements.txt +88 -33
- package/test/styling.txt +51 -27
- package/test/test-fiz.js +14 -11
- package/src/parser.js +0 -26
- package/src/parser.terms.js +0 -27
package/src/tokens.js
CHANGED
|
@@ -1,53 +1,85 @@
|
|
|
1
|
-
import { ExternalTokenizer, ContextTracker } from "@lezer/lr"
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ExternalTokenizer, ContextTracker } from "@lezer/lr";
|
|
2
|
+
import {
|
|
3
|
+
insertSemi,
|
|
4
|
+
spaces,
|
|
5
|
+
newline,
|
|
6
|
+
LineComment,
|
|
7
|
+
BlockComment,
|
|
8
|
+
Unit,
|
|
9
|
+
cssIdentifier,
|
|
10
|
+
} from "./fiz.grammar.terms";
|
|
4
11
|
|
|
5
|
-
const space = [
|
|
6
|
-
5760, 8192, 8193, 8194, 8195, 8196, 8197,
|
|
7
|
-
8201, 8202, 8232, 8233, 8239, 8287, 12288
|
|
12
|
+
const space = [
|
|
13
|
+
9, 10, 11, 12, 13, 32, 133, 160, 5760, 8192, 8193, 8194, 8195, 8196, 8197,
|
|
14
|
+
8198, 8199, 8200, 8201, 8202, 8232, 8233, 8239, 8287, 12288,
|
|
15
|
+
];
|
|
8
16
|
|
|
9
|
-
const percent = 37,
|
|
17
|
+
const percent = 37,
|
|
18
|
+
dash = 45,
|
|
19
|
+
underscore = 95,
|
|
20
|
+
braceR = 125;
|
|
10
21
|
|
|
11
|
-
function isAlpha(ch) {
|
|
22
|
+
function isAlpha(ch) {
|
|
23
|
+
return (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || ch >= 161;
|
|
24
|
+
}
|
|
12
25
|
|
|
13
|
-
function isDigit(ch) {
|
|
26
|
+
function isDigit(ch) {
|
|
27
|
+
return ch >= 48 && ch <= 57;
|
|
28
|
+
}
|
|
14
29
|
|
|
15
30
|
export const trackNewline = new ContextTracker({
|
|
16
31
|
start: false,
|
|
17
32
|
shift(context, term) {
|
|
18
|
-
return term == LineComment || term == BlockComment || term == spaces
|
|
33
|
+
return term == LineComment || term == BlockComment || term == spaces
|
|
34
|
+
? context
|
|
35
|
+
: term == newline;
|
|
19
36
|
},
|
|
20
|
-
strict: false
|
|
21
|
-
})
|
|
37
|
+
strict: false,
|
|
38
|
+
});
|
|
22
39
|
|
|
23
|
-
export const insertSemicolon = new ExternalTokenizer(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
export const insertSemicolon = new ExternalTokenizer(
|
|
41
|
+
(input, stack) => {
|
|
42
|
+
let { next } = input;
|
|
43
|
+
if (
|
|
44
|
+
(next == braceR || next == -1 || stack.context) &&
|
|
45
|
+
stack.canShift(insertSemi)
|
|
46
|
+
)
|
|
47
|
+
input.acceptToken(insertSemi);
|
|
48
|
+
},
|
|
49
|
+
{ contextual: true, fallback: true },
|
|
50
|
+
);
|
|
28
51
|
|
|
29
|
-
export const unitToken = new ExternalTokenizer(input => {
|
|
52
|
+
export const unitToken = new ExternalTokenizer((input) => {
|
|
30
53
|
if (!space.includes(input.peek(-1))) {
|
|
31
|
-
let {next} = input
|
|
32
|
-
if (next == percent) {
|
|
54
|
+
let { next } = input;
|
|
55
|
+
if (next == percent) {
|
|
56
|
+
input.advance();
|
|
57
|
+
input.acceptToken(Unit);
|
|
58
|
+
}
|
|
33
59
|
if (isAlpha(next)) {
|
|
34
|
-
do {
|
|
35
|
-
|
|
60
|
+
do {
|
|
61
|
+
input.advance();
|
|
62
|
+
} while (isAlpha(input.next));
|
|
63
|
+
input.acceptToken(Unit);
|
|
36
64
|
}
|
|
37
65
|
}
|
|
38
|
-
})
|
|
66
|
+
});
|
|
39
67
|
|
|
40
68
|
export const cssIdentifierToken = new ExternalTokenizer((input) => {
|
|
41
|
-
for (let inside = false, dashes = 0, i = 0
|
|
42
|
-
let {next} = input
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
69
|
+
for (let inside = false, dashes = 0, i = 0; ; i++) {
|
|
70
|
+
let { next } = input;
|
|
71
|
+
if (
|
|
72
|
+
isAlpha(next) ||
|
|
73
|
+
next == dash ||
|
|
74
|
+
next == underscore ||
|
|
75
|
+
(inside && isDigit(next))
|
|
76
|
+
) {
|
|
77
|
+
if (!inside && (next != dash || i > 0)) inside = true;
|
|
78
|
+
if (dashes === i && next == dash) dashes++;
|
|
79
|
+
input.advance();
|
|
47
80
|
} else {
|
|
48
|
-
if (inside)
|
|
49
|
-
|
|
50
|
-
break
|
|
81
|
+
if (inside) input.acceptToken(cssIdentifier);
|
|
82
|
+
break;
|
|
51
83
|
}
|
|
52
84
|
}
|
|
53
|
-
})
|
|
85
|
+
});
|
package/test/assignments.txt
CHANGED
|
@@ -6,9 +6,9 @@ x = y
|
|
|
6
6
|
|
|
7
7
|
Recipe(
|
|
8
8
|
Alias(
|
|
9
|
-
LhsVariable(
|
|
9
|
+
LhsVariable(Identifier),
|
|
10
10
|
Eq,
|
|
11
|
-
|
|
11
|
+
RhsVariable(QualifiableIdentifier(Identifier))
|
|
12
12
|
)
|
|
13
13
|
)
|
|
14
14
|
|
|
@@ -20,9 +20,9 @@ foo = f()
|
|
|
20
20
|
|
|
21
21
|
Recipe(
|
|
22
22
|
Assignment(
|
|
23
|
-
LhsVariable(
|
|
23
|
+
LhsVariable(Identifier),
|
|
24
24
|
Eq,
|
|
25
|
-
Call(Identifier,ArgList)
|
|
25
|
+
Call(QualifiableIdentifier(Identifier), ArgList)
|
|
26
26
|
)
|
|
27
27
|
)
|
|
28
28
|
|
|
@@ -34,10 +34,10 @@ a, b, c = g()
|
|
|
34
34
|
|
|
35
35
|
Recipe(
|
|
36
36
|
Assignment(
|
|
37
|
-
LhsVariable(
|
|
38
|
-
LhsVariable(
|
|
39
|
-
LhsVariable(
|
|
37
|
+
LhsVariable(Identifier),
|
|
38
|
+
LhsVariable(Identifier),
|
|
39
|
+
LhsVariable(Identifier),
|
|
40
40
|
Eq,
|
|
41
|
-
Call(Identifier,ArgList)
|
|
41
|
+
Call(QualifiableIdentifier(Identifier), ArgList)
|
|
42
42
|
)
|
|
43
43
|
)
|
package/test/calls.txt
CHANGED
|
@@ -5,7 +5,7 @@ func()
|
|
|
5
5
|
==>
|
|
6
6
|
|
|
7
7
|
Recipe(
|
|
8
|
-
Call(Identifier,ArgList)
|
|
8
|
+
Call(QualifiableIdentifier(Identifier), ArgList)
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
# One Variable
|
|
@@ -15,8 +15,8 @@ f( x )
|
|
|
15
15
|
==>
|
|
16
16
|
|
|
17
17
|
Recipe(
|
|
18
|
-
Call(Identifier,ArgList(
|
|
19
|
-
|
|
18
|
+
Call(QualifiableIdentifier(Identifier), ArgList(
|
|
19
|
+
RhsVariable(QualifiableIdentifier(Identifier))
|
|
20
20
|
))
|
|
21
21
|
)
|
|
22
22
|
|
|
@@ -27,9 +27,9 @@ f(x,y)
|
|
|
27
27
|
==>
|
|
28
28
|
|
|
29
29
|
Recipe(
|
|
30
|
-
Call(Identifier,ArgList(
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
Call(QualifiableIdentifier(Identifier), ArgList(
|
|
31
|
+
RhsVariable(QualifiableIdentifier(Identifier)),
|
|
32
|
+
RhsVariable(QualifiableIdentifier(Identifier))
|
|
33
33
|
))
|
|
34
34
|
)
|
|
35
35
|
|
|
@@ -41,11 +41,11 @@ f(x, y, z)
|
|
|
41
41
|
|
|
42
42
|
Recipe(
|
|
43
43
|
Call(
|
|
44
|
-
Identifier,
|
|
44
|
+
QualifiableIdentifier(Identifier),
|
|
45
45
|
ArgList(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
RhsVariable(QualifiableIdentifier(Identifier)),
|
|
47
|
+
RhsVariable(QualifiableIdentifier(Identifier)),
|
|
48
|
+
RhsVariable(QualifiableIdentifier(Identifier))
|
|
49
49
|
)
|
|
50
50
|
)
|
|
51
51
|
)
|
|
@@ -57,8 +57,8 @@ f(g())
|
|
|
57
57
|
==>
|
|
58
58
|
|
|
59
59
|
Recipe(
|
|
60
|
-
Call(Identifier,ArgList(
|
|
61
|
-
Call(Identifier,ArgList)
|
|
60
|
+
Call(QualifiableIdentifier(Identifier), ArgList(
|
|
61
|
+
Call(QualifiableIdentifier(Identifier), ArgList)
|
|
62
62
|
))
|
|
63
63
|
)
|
|
64
64
|
|
|
@@ -69,9 +69,9 @@ f( g( h() ) )
|
|
|
69
69
|
==>
|
|
70
70
|
|
|
71
71
|
Recipe(
|
|
72
|
-
Call(Identifier,ArgList(
|
|
73
|
-
Call(Identifier,ArgList(
|
|
74
|
-
Call(Identifier,ArgList)
|
|
72
|
+
Call(QualifiableIdentifier(Identifier), ArgList(
|
|
73
|
+
Call(QualifiableIdentifier(Identifier), ArgList(
|
|
74
|
+
Call(QualifiableIdentifier(Identifier), ArgList)
|
|
75
75
|
))
|
|
76
76
|
))
|
|
77
77
|
)
|
|
@@ -83,9 +83,9 @@ f ( x , g ( ) )
|
|
|
83
83
|
==>
|
|
84
84
|
|
|
85
85
|
Recipe(
|
|
86
|
-
Call(Identifier,ArgList(
|
|
87
|
-
|
|
88
|
-
Call(Identifier,ArgList)
|
|
86
|
+
Call(QualifiableIdentifier(Identifier), ArgList(
|
|
87
|
+
RhsVariable(QualifiableIdentifier(Identifier)),
|
|
88
|
+
Call(QualifiableIdentifier(Identifier), ArgList)
|
|
89
89
|
))
|
|
90
90
|
)
|
|
91
91
|
|
|
@@ -99,9 +99,9 @@ f (
|
|
|
99
99
|
==>
|
|
100
100
|
|
|
101
101
|
Recipe(
|
|
102
|
-
Call(Identifier,ArgList(
|
|
103
|
-
Call(Identifier,ArgList),
|
|
104
|
-
|
|
102
|
+
Call(QualifiableIdentifier(Identifier), ArgList(
|
|
103
|
+
Call(QualifiableIdentifier(Identifier), ArgList),
|
|
104
|
+
RhsVariable(QualifiableIdentifier(Identifier))
|
|
105
105
|
))
|
|
106
106
|
)
|
|
107
107
|
|
|
@@ -117,10 +117,16 @@ f(
|
|
|
117
117
|
==>
|
|
118
118
|
|
|
119
119
|
Recipe(
|
|
120
|
-
Call(Identifier,ArgList(
|
|
121
|
-
Call(Identifier,ArgList(
|
|
122
|
-
Call(
|
|
123
|
-
|
|
120
|
+
Call(QualifiableIdentifier(Identifier), ArgList(
|
|
121
|
+
Call(QualifiableIdentifier(Identifier), ArgList(
|
|
122
|
+
Call(
|
|
123
|
+
QualifiableIdentifier(Identifier),
|
|
124
|
+
ArgList(
|
|
125
|
+
RhsVariable(QualifiableIdentifier(Identifier)),
|
|
126
|
+
RhsVariable(QualifiableIdentifier(Identifier))
|
|
127
|
+
)
|
|
128
|
+
),
|
|
129
|
+
RhsVariable(QualifiableIdentifier(Identifier))
|
|
124
130
|
))
|
|
125
131
|
))
|
|
126
132
|
)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Empty Anonymous Namespace
|
|
2
|
+
|
|
3
|
+
[]
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
Recipe(
|
|
8
|
+
Namespace()
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
# Empty Named Namespace
|
|
12
|
+
|
|
13
|
+
n[]
|
|
14
|
+
|
|
15
|
+
==>
|
|
16
|
+
|
|
17
|
+
Recipe(
|
|
18
|
+
Namespace(Identifier)
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# Call in Namespace
|
|
22
|
+
|
|
23
|
+
[
|
|
24
|
+
f()
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
==>
|
|
28
|
+
|
|
29
|
+
Recipe(
|
|
30
|
+
Namespace(Call(QualifiableIdentifier(Identifier), ArgList))
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Alias in Namespace
|
|
34
|
+
|
|
35
|
+
[
|
|
36
|
+
y = x
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
==>
|
|
40
|
+
|
|
41
|
+
Recipe(
|
|
42
|
+
Namespace(
|
|
43
|
+
Alias(
|
|
44
|
+
LhsVariable(Identifier),
|
|
45
|
+
Eq,
|
|
46
|
+
RhsVariable(QualifiableIdentifier(Identifier))
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Assignment in Namespace
|
|
52
|
+
|
|
53
|
+
[
|
|
54
|
+
y = f(x)
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
==>
|
|
58
|
+
|
|
59
|
+
Recipe(
|
|
60
|
+
Namespace(
|
|
61
|
+
Assignment(
|
|
62
|
+
LhsVariable(Identifier),
|
|
63
|
+
Eq,
|
|
64
|
+
Call(
|
|
65
|
+
QualifiableIdentifier(Identifier),
|
|
66
|
+
ArgList(RhsVariable(QualifiableIdentifier(Identifier)))
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# StyleTagDeclaration in Namespace
|
|
73
|
+
|
|
74
|
+
[
|
|
75
|
+
#empty{}
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
==>
|
|
79
|
+
|
|
80
|
+
Recipe(
|
|
81
|
+
Namespace(
|
|
82
|
+
StyleTagDeclaration(
|
|
83
|
+
Identifier,
|
|
84
|
+
StyleArgList
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# StyleBinding in Namespace
|
|
90
|
+
|
|
91
|
+
[
|
|
92
|
+
%s{}
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
==>
|
|
96
|
+
|
|
97
|
+
Recipe(
|
|
98
|
+
Namespace(
|
|
99
|
+
StyleBinding(Identifier, StyleTagList())
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# Nested Namespaces
|
|
104
|
+
|
|
105
|
+
a[
|
|
106
|
+
[]
|
|
107
|
+
b[]
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
==>
|
|
111
|
+
|
|
112
|
+
Recipe(
|
|
113
|
+
Namespace(
|
|
114
|
+
Identifier,
|
|
115
|
+
Namespace(),
|
|
116
|
+
Namespace(Identifier)
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Comments in Namespace
|
|
121
|
+
|
|
122
|
+
[
|
|
123
|
+
// comment
|
|
124
|
+
/* comment */
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
==>
|
|
128
|
+
|
|
129
|
+
Recipe(
|
|
130
|
+
Namespace(
|
|
131
|
+
LineComment,
|
|
132
|
+
BlockComment
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# Namespace with ArgList
|
|
137
|
+
|
|
138
|
+
[]()
|
|
139
|
+
|
|
140
|
+
==>
|
|
141
|
+
|
|
142
|
+
Recipe(
|
|
143
|
+
Namespace(
|
|
144
|
+
ArgList
|
|
145
|
+
)
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# Namespace with StyleArgList
|
|
149
|
+
|
|
150
|
+
[]{}
|
|
151
|
+
|
|
152
|
+
==>
|
|
153
|
+
|
|
154
|
+
Recipe(
|
|
155
|
+
Namespace(
|
|
156
|
+
StyleArgList
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# Namespace with ArgList and StyleArgList
|
|
161
|
+
|
|
162
|
+
[](){}
|
|
163
|
+
|
|
164
|
+
==>
|
|
165
|
+
|
|
166
|
+
Recipe(
|
|
167
|
+
Namespace(
|
|
168
|
+
ArgList,
|
|
169
|
+
StyleArgList
|
|
170
|
+
)
|
|
171
|
+
)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Qualified Call Identifier
|
|
2
|
+
|
|
3
|
+
n.x()
|
|
4
|
+
n.m.x()
|
|
5
|
+
|
|
6
|
+
==>
|
|
7
|
+
|
|
8
|
+
Recipe(
|
|
9
|
+
Call(
|
|
10
|
+
QualifiableIdentifier(Identifier, Identifier),
|
|
11
|
+
ArgList
|
|
12
|
+
)
|
|
13
|
+
Call(
|
|
14
|
+
QualifiableIdentifier(Identifier, Identifier, Identifier),
|
|
15
|
+
ArgList
|
|
16
|
+
)
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# Qualified RhsVariable in Alias
|
|
20
|
+
|
|
21
|
+
a = b.c
|
|
22
|
+
|
|
23
|
+
==>
|
|
24
|
+
|
|
25
|
+
Recipe(
|
|
26
|
+
Alias(
|
|
27
|
+
LhsVariable(Identifier),
|
|
28
|
+
Eq,
|
|
29
|
+
RhsVariable(QualifiableIdentifier(Identifier, Identifier))
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Qualified RhsVariable in Call Assignment
|
|
34
|
+
|
|
35
|
+
a = b(c.d)
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
Recipe(
|
|
40
|
+
Assignment(
|
|
41
|
+
LhsVariable(Identifier),
|
|
42
|
+
Eq,
|
|
43
|
+
Call(
|
|
44
|
+
QualifiableIdentifier(Identifier),
|
|
45
|
+
ArgList(RhsVariable(QualifiableIdentifier(Identifier, Identifier)))
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Qualified RhsVariable in Namespace ArgList
|
|
51
|
+
|
|
52
|
+
[](x.y)
|
|
53
|
+
|
|
54
|
+
==>
|
|
55
|
+
|
|
56
|
+
Recipe(
|
|
57
|
+
Namespace(
|
|
58
|
+
ArgList(RhsVariable(QualifiableIdentifier(Identifier, Identifier)))
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# Qualified StyleTag in StyleTagDeclaration
|
|
63
|
+
|
|
64
|
+
#s{
|
|
65
|
+
#x.y
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
==>
|
|
69
|
+
|
|
70
|
+
Recipe(
|
|
71
|
+
StyleTagDeclaration(
|
|
72
|
+
Identifier,
|
|
73
|
+
StyleArgList(
|
|
74
|
+
StyleTag(QualifiableIdentifier(Identifier, Identifier))
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Qualified StyleTag in StyleBinding
|
|
80
|
+
|
|
81
|
+
%a{
|
|
82
|
+
#x.y
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
==>
|
|
86
|
+
|
|
87
|
+
Recipe(
|
|
88
|
+
StyleBinding(
|
|
89
|
+
Identifier,
|
|
90
|
+
StyleTagList(
|
|
91
|
+
StyleTag(QualifiableIdentifier(Identifier, Identifier))
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
)
|