@tbela99/css-parser 1.8.1 → 2.0.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/CHANGELOG.md +66 -0
- package/README.md +129 -31
- package/dist/index-umd-web.js +27382 -24086
- package/dist/index.d.ts +2737 -2200
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +1 -1
- package/dist/src/lib/ast/arena-node.js +548 -0
- package/dist/src/lib/ast/arena.js +3198 -0
- package/dist/src/lib/ast/features/calc.js +85 -76
- package/dist/src/lib/ast/features/if.js +155 -115
- package/dist/src/lib/ast/features/index.js +1 -1
- package/dist/src/lib/ast/features/inlinecssvariables.js +77 -84
- package/dist/src/lib/ast/features/prefix.js +184 -183
- package/dist/src/lib/ast/features/shorthand.js +40 -46
- package/dist/src/lib/ast/features/transform.js +24 -24
- package/dist/src/lib/ast/features/type.js +1 -1
- package/dist/src/lib/ast/fingerprint.js +333 -0
- package/dist/src/lib/ast/math/expression.js +458 -543
- package/dist/src/lib/ast/math/math.js +19 -41
- package/dist/src/lib/ast/minify.js +590 -647
- package/dist/src/lib/ast/transform/compute.js +82 -85
- package/dist/src/lib/ast/transform/matrix.js +21 -38
- package/dist/src/lib/ast/transform/minify.js +82 -193
- package/dist/src/lib/ast/transform/perspective.js +2 -3
- package/dist/src/lib/ast/transform/rotate.js +1 -1
- package/dist/src/lib/ast/transform/scale.js +1 -1
- package/dist/src/lib/ast/transform/skew.js +1 -1
- package/dist/src/lib/ast/transform/translate.js +1 -1
- package/dist/src/lib/ast/transform/utils.js +2 -2
- package/dist/src/lib/ast/types.js +263 -258
- package/dist/src/lib/ast/walk.js +246 -610
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +223 -139
- package/dist/src/lib/parser/declaration/map.js +251 -238
- package/dist/src/lib/parser/declaration/set.js +74 -66
- package/dist/src/lib/parser/linesmap.js +1 -1
- package/dist/src/lib/parser/parse.js +1379 -1662
- package/dist/src/lib/parser/source.js +7 -4
- package/dist/src/lib/parser/tokenize.js +406 -199
- package/dist/src/lib/parser/utils/angle.js +11 -13
- package/dist/src/lib/parser/utils/at-rule-container.js +183 -168
- package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +5 -5
- package/dist/src/lib/parser/utils/at-rule-generic.js +31 -24
- package/dist/src/lib/parser/utils/at-rule-import.js +44 -44
- package/dist/src/lib/parser/utils/at-rule-media.js +216 -205
- package/dist/src/lib/parser/utils/at-rule-support.js +83 -88
- package/dist/src/lib/parser/utils/at-rule-when-else.js +47 -47
- package/dist/src/lib/parser/utils/at-rule.js +5 -5
- package/dist/src/lib/parser/utils/base64.js +2 -2
- package/dist/src/lib/parser/utils/cache.js +1 -1
- package/dist/src/lib/parser/utils/config.js +1 -1
- package/dist/src/lib/parser/utils/declaration.js +233 -234
- package/dist/src/lib/parser/utils/eq.js +50 -3
- package/dist/src/lib/parser/utils/hash.js +2 -35
- package/dist/src/lib/parser/utils/selector.js +309 -387
- package/dist/src/lib/parser/utils/text.js +18 -4
- package/dist/src/lib/parser/utils/token.js +16 -69
- package/dist/src/lib/parser/utils/type.js +37 -24
- package/dist/src/lib/printer/render.js +965 -511
- package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
- package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
- package/dist/src/lib/syntax/color/a98rgb.js +1 -1
- package/dist/src/lib/syntax/color/alpha.js +36 -37
- package/dist/src/lib/syntax/color/cmyk.js +35 -52
- package/dist/src/lib/syntax/color/color-mix.js +96 -132
- package/dist/src/lib/syntax/color/color.js +222 -231
- package/dist/src/lib/syntax/color/hex.js +45 -55
- package/dist/src/lib/syntax/color/hsl.js +54 -62
- package/dist/src/lib/syntax/color/hwb.js +60 -68
- package/dist/src/lib/syntax/color/lab.js +59 -67
- package/dist/src/lib/syntax/color/lch.js +59 -67
- package/dist/src/lib/syntax/color/oklab.js +60 -68
- package/dist/src/lib/syntax/color/oklch.js +60 -67
- package/dist/src/lib/syntax/color/p3.js +1 -1
- package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
- package/dist/src/lib/syntax/color/rec2020.js +1 -1
- package/dist/src/lib/syntax/color/relative-color.js +94 -144
- package/dist/src/lib/syntax/color/rgb.js +54 -57
- package/dist/src/lib/syntax/color/srgb.js +55 -53
- package/dist/src/lib/syntax/color/utils/color-type.js +13 -10
- package/dist/src/lib/syntax/color/utils/colorspace.js +11 -11
- package/dist/src/lib/syntax/color/utils/components.js +19 -20
- package/dist/src/lib/syntax/color/utils/distance.js +15 -13
- package/dist/src/lib/syntax/color/utils/make-color.js +15 -19
- package/dist/src/lib/syntax/color/utils/matrix.js +2 -2
- package/dist/src/lib/syntax/color/xyz.js +1 -1
- package/dist/src/lib/syntax/color/xyzd50.js +1 -1
- package/dist/src/lib/syntax/constants.js +2 -16
- package/dist/src/lib/syntax/syntax.js +301 -407
- package/dist/src/lib/validation/config.js +1 -1
- package/dist/src/lib/validation/match.js +959 -723
- package/dist/src/lib/validation/parser/parse.js +230 -112
- package/dist/src/lib/validation/parser/typedef.js +1 -1
- package/dist/src/lib/validation/utils/list.js +27 -12
- package/dist/src/node.js +12 -72
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +9 -6
- package/dist/src/web.js +11 -73
- package/package.json +9 -10
- package/dist/index.cjs +0 -35874
- package/dist/src/lib/ast/clone.js +0 -51
- package/dist/src/lib/ast/expand.js +0 -311
- package/dist/src/lib/ast/find.js +0 -192
- package/dist/src/lib/ast/node.js +0 -59
|
@@ -2,21 +2,33 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
|
+
import { TokenField } from '../ast/arena.js';
|
|
8
9
|
import { getParsedSyntax, getSyntaxConfig } from './config.js';
|
|
9
10
|
import { EnumToken } from '../ast/types.js';
|
|
10
11
|
import { ValidationSyntaxGroupEnum, ValidationTokenEnum, MediaFeatureType } from './parser/typedef.js';
|
|
11
|
-
import {
|
|
12
|
+
import { tokensfuncDefMap, tokensfuncSet, funcLike, mFLT, mFGT } from '../syntax/constants.js';
|
|
12
13
|
import { isColor } from '../syntax/syntax.js';
|
|
13
|
-
import { equalsIgnoreCase } from '../parser/utils/text.js';
|
|
14
|
-
import { cloneNode } from '../ast/clone.js';
|
|
14
|
+
import { equalsIgnoreCase, lowercase } from '../parser/utils/text.js';
|
|
15
15
|
import { parseTokens } from '../parser/parse.js';
|
|
16
16
|
|
|
17
17
|
const config = getSyntaxConfig();
|
|
18
18
|
// @ts-expect-error
|
|
19
19
|
const allValues = config.declarations.all.syntax.split(/[\s|]+/g);
|
|
20
|
+
/**
|
|
21
|
+
* true if the value is a css wide keyword (`inherit`, `initial`, ...), ignoring the case
|
|
22
|
+
* @param value
|
|
23
|
+
*/
|
|
24
|
+
function isCssWideKeyword(value) {
|
|
25
|
+
for (let i = 0; i < allValues.length; i++) {
|
|
26
|
+
if (equalsIgnoreCase(allValues[i], value)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
20
32
|
const selectorNodeTypes = [
|
|
21
33
|
EnumToken.CommaTokenType,
|
|
22
34
|
EnumToken.ColumnCombinatorTokenType,
|
|
@@ -31,6 +43,57 @@ const selectorEnumMap = new Map([
|
|
|
31
43
|
[EnumToken.GtTokenType, EnumToken.ChildCombinatorTokenType],
|
|
32
44
|
]);
|
|
33
45
|
const propertyKeywordValues = new Map();
|
|
46
|
+
/**
|
|
47
|
+
* empty error list shared by the results
|
|
48
|
+
*/
|
|
49
|
+
const noErrors = Object.freeze([]);
|
|
50
|
+
/**
|
|
51
|
+
* allocate a result. the results are passed to the matching functions that fill them (see {@link setMatch})
|
|
52
|
+
*/
|
|
53
|
+
function createMatch() {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
valid: true,
|
|
57
|
+
token: null,
|
|
58
|
+
context: null,
|
|
59
|
+
syntaxToken: null,
|
|
60
|
+
errors: noErrors,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* fill a result
|
|
65
|
+
* @param out
|
|
66
|
+
* @param success
|
|
67
|
+
* @param valid
|
|
68
|
+
* @param token
|
|
69
|
+
* @param context
|
|
70
|
+
* @param syntaxToken
|
|
71
|
+
* @param errors
|
|
72
|
+
*/
|
|
73
|
+
function setMatch(out, success, valid, token, context, syntaxToken, errors) {
|
|
74
|
+
out.success = success;
|
|
75
|
+
out.valid = valid;
|
|
76
|
+
out.token = token;
|
|
77
|
+
out.context = context;
|
|
78
|
+
out.syntaxToken = syntaxToken;
|
|
79
|
+
out.errors = errors;
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* the error list returned to the callers of {@link matchAllSyntaxes}: the callers may add errors to it
|
|
84
|
+
* @param errors
|
|
85
|
+
*/
|
|
86
|
+
function ownErrors(errors) {
|
|
87
|
+
return errors === noErrors ? [] : errors;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* copy a result
|
|
91
|
+
* @param out
|
|
92
|
+
* @param from
|
|
93
|
+
*/
|
|
94
|
+
function copyMatch(out, from) {
|
|
95
|
+
return setMatch(out, from.success, from.valid, from.token, from.context, from.syntaxToken, from.errors);
|
|
96
|
+
}
|
|
34
97
|
/**
|
|
35
98
|
* @type {Array.<EnumToken>}
|
|
36
99
|
*/
|
|
@@ -41,11 +104,11 @@ funcTypes.push(EnumToken.FunctionTokenType, EnumToken.PseudoClassFuncTokenType);
|
|
|
41
104
|
* @param tokens
|
|
42
105
|
* @returns
|
|
43
106
|
*/
|
|
44
|
-
function trimArray(tokens) {
|
|
45
|
-
while (tokens[0]
|
|
107
|
+
function trimArray(arena, tokens) {
|
|
108
|
+
while (tokens.length > 0 && arena.dataTypes[tokens[0]] === EnumToken.WhitespaceTokenType) {
|
|
46
109
|
tokens.shift();
|
|
47
110
|
}
|
|
48
|
-
while (tokens[tokens.length - 1]
|
|
111
|
+
while (tokens.length > 0 && arena.dataTypes[tokens[tokens.length - 1]] === EnumToken.WhitespaceTokenType) {
|
|
49
112
|
tokens.pop();
|
|
50
113
|
}
|
|
51
114
|
return tokens;
|
|
@@ -68,9 +131,9 @@ function getMFInfo(featureName) {
|
|
|
68
131
|
* - valid: boolean. true the media feaure is known or is a custom property. false otherwise
|
|
69
132
|
* - success: boolean. validation result
|
|
70
133
|
*/
|
|
71
|
-
function isMFValue(featureName, tokens, isMFRange) {
|
|
134
|
+
function isMFValue(arena, featureName, tokens, isMFRange) {
|
|
72
135
|
// mf-value: <number> | <dimension> | <ident> | <ratio>
|
|
73
|
-
tokens = tokens.filter((token) => token
|
|
136
|
+
tokens = tokens.filter((token) => arena.dataTypes[token] !== EnumToken.WhitespaceTokenType && arena.dataTypes[token] !== EnumToken.CommentTokenType);
|
|
74
137
|
// if (tokens.length === 0) {
|
|
75
138
|
// return { valid: true, success: false };
|
|
76
139
|
// }
|
|
@@ -91,47 +154,47 @@ function isMFValue(featureName, tokens, isMFRange) {
|
|
|
91
154
|
return {
|
|
92
155
|
valid: true,
|
|
93
156
|
success: tokens.length === 1 &&
|
|
94
|
-
tokens[0]
|
|
95
|
-
(tokens[0]
|
|
157
|
+
arena.dataTypes[tokens[0]] === EnumToken.NumberTokenType &&
|
|
158
|
+
(arena.numericValue[tokens[0]] === 0 || arena.numericValue[tokens[0]] === 1),
|
|
96
159
|
};
|
|
97
160
|
case MediaFeatureType.KeywordType:
|
|
98
161
|
return {
|
|
99
162
|
valid: true,
|
|
100
163
|
success: tokens.length === 1 &&
|
|
101
|
-
tokens[0]
|
|
102
|
-
mediaFeature.values.includes(tokens[0].
|
|
164
|
+
arena.dataTypes[tokens[0]] === EnumToken.IdenTokenType &&
|
|
165
|
+
mediaFeature.values.includes(arena.strings[arena.stringValue[tokens[0]]].toLowerCase()),
|
|
103
166
|
};
|
|
104
167
|
case MediaFeatureType.LengthType:
|
|
105
|
-
return { valid: true, success: tokens.length === 1 && tokens[0]
|
|
168
|
+
return { valid: true, success: tokens.length === 1 && arena.dataTypes[tokens[0]] == EnumToken.LengthTokenType };
|
|
106
169
|
case MediaFeatureType.IntergerType:
|
|
107
170
|
return {
|
|
108
171
|
valid: true,
|
|
109
172
|
success: tokens.length === 1 &&
|
|
110
|
-
tokens[0]
|
|
111
|
-
!tokens[0].
|
|
173
|
+
arena.dataTypes[tokens[0]] == EnumToken.NumberTokenType &&
|
|
174
|
+
!arena.numericValue[tokens[0]].toString().includes("."),
|
|
112
175
|
};
|
|
113
176
|
case MediaFeatureType.NumberType:
|
|
114
177
|
return {
|
|
115
178
|
valid: true,
|
|
116
179
|
success: tokens.length === 1 &&
|
|
117
|
-
tokens[0]
|
|
118
|
-
|
|
180
|
+
arena.dataTypes[tokens[0]] == EnumToken.NumberTokenType &&
|
|
181
|
+
!arena.hasFraction(tokens[0]),
|
|
119
182
|
};
|
|
120
183
|
case MediaFeatureType.StringType:
|
|
121
|
-
return { valid: true, success: tokens.length === 1 && tokens[0]
|
|
184
|
+
return { valid: true, success: tokens.length === 1 && arena.dataTypes[tokens[0]] == EnumToken.StringTokenType };
|
|
122
185
|
case MediaFeatureType.ResolutionType:
|
|
123
|
-
return { valid: true, success: tokens.length === 1 && tokens[0]
|
|
186
|
+
return { valid: true, success: tokens.length === 1 && arena.dataTypes[tokens[0]] == EnumToken.ResolutionTokenType };
|
|
124
187
|
case MediaFeatureType.RatioType:
|
|
125
188
|
return {
|
|
126
189
|
valid: true,
|
|
127
|
-
success: (tokens.length == 1 && tokens[0]
|
|
190
|
+
success: (tokens.length == 1 && arena.dataTypes[tokens[0]] == EnumToken.NumberTokenType) ||
|
|
128
191
|
(tokens.length === 3 &&
|
|
129
|
-
tokens[0]
|
|
130
|
-
|
|
131
|
-
tokens[1]
|
|
132
|
-
tokens[1]
|
|
133
|
-
tokens[2]
|
|
134
|
-
|
|
192
|
+
arena.dataTypes[tokens[0]] == EnumToken.NumberTokenType &&
|
|
193
|
+
!arena.hasFraction(tokens[0]) &&
|
|
194
|
+
arena.dataTypes[tokens[1]] == EnumToken.LiteralTokenType &&
|
|
195
|
+
arena.strings[arena.stringValue[tokens[1]]] === "/" &&
|
|
196
|
+
arena.dataTypes[tokens[2]] == EnumToken.NumberTokenType &&
|
|
197
|
+
!arena.hasFraction(tokens[2])),
|
|
135
198
|
};
|
|
136
199
|
default:
|
|
137
200
|
console.debug("Unknown media feature type " + mediaFeature.type);
|
|
@@ -142,155 +205,167 @@ function isMFValue(featureName, tokens, isMFRange) {
|
|
|
142
205
|
};
|
|
143
206
|
}
|
|
144
207
|
/**
|
|
145
|
-
*
|
|
146
|
-
* @param tokens
|
|
147
|
-
* @returns
|
|
208
|
+
* validation context: a cursor over the tokens being validated. the methods are shared by all the contexts
|
|
148
209
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
210
|
+
class ValidationTokenContext {
|
|
211
|
+
arena;
|
|
212
|
+
tokens;
|
|
213
|
+
index;
|
|
214
|
+
constructor(arena, tokens, index) {
|
|
215
|
+
this.arena = arena;
|
|
216
|
+
this.tokens = tokens;
|
|
217
|
+
this.index = index;
|
|
154
218
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
while (token?.typ == EnumToken.WhitespaceTokenType ||
|
|
169
|
-
token?.typ == EnumToken.CommentTokenType ||
|
|
170
|
-
token?.typ == EnumToken.CDOCOMMTokenType) {
|
|
171
|
-
token = this.tokens[++index];
|
|
172
|
-
}
|
|
173
|
-
if (token == null || offset === 0) {
|
|
174
|
-
return token;
|
|
175
|
-
}
|
|
176
|
-
offset--;
|
|
219
|
+
current() {
|
|
220
|
+
if (this.index < 0) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
return this.tokens[this.index];
|
|
224
|
+
}
|
|
225
|
+
peek(offset = 0) {
|
|
226
|
+
let index = this.index;
|
|
227
|
+
let token = this.tokens[++index];
|
|
228
|
+
while (offset >= 0 && index < this.tokens.length) {
|
|
229
|
+
while (this.arena.dataTypes[token] == EnumToken.WhitespaceTokenType ||
|
|
230
|
+
this.arena.dataTypes[token] == EnumToken.CommentTokenType ||
|
|
231
|
+
this.arena.dataTypes[token] == EnumToken.CDOCOMMTokenType) {
|
|
177
232
|
token = this.tokens[++index];
|
|
178
233
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
*
|
|
183
|
-
* @returns
|
|
184
|
-
* @param open
|
|
185
|
-
* @param close
|
|
186
|
-
* @param counter
|
|
187
|
-
*/
|
|
188
|
-
peekRange(open = EnumToken.StartParensTokenType, close = EnumToken.EndParensTokenType, counter = 0) {
|
|
189
|
-
let index = this.index;
|
|
190
|
-
let token = this.tokens[index];
|
|
191
|
-
// track balanced parens
|
|
192
|
-
let matchCount = 0;
|
|
193
|
-
const tokens = [];
|
|
194
|
-
while (index + 1 < this.tokens.length && this.tokens[index + 1]?.typ === EnumToken.WhitespaceTokenType) {
|
|
195
|
-
index++;
|
|
196
|
-
}
|
|
197
|
-
while (index + 1 < this.tokens.length) {
|
|
198
|
-
token = this.tokens[++index];
|
|
199
|
-
if (token?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) {
|
|
200
|
-
matchCount++;
|
|
201
|
-
}
|
|
202
|
-
else if (token?.typ === EnumToken.EndParensTokenType) {
|
|
203
|
-
matchCount--;
|
|
204
|
-
}
|
|
205
|
-
if (matchCount >= 0) {
|
|
206
|
-
tokens.push(token);
|
|
207
|
-
}
|
|
208
|
-
if (matchCount === 0) {
|
|
209
|
-
if (close !== EnumToken.EndParensTokenType && token?.typ === close) {
|
|
210
|
-
counter--;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
if (matchCount <= 0 && counter <= 0) {
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
234
|
+
if (token == null || offset === 0) {
|
|
235
|
+
return token;
|
|
216
236
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
237
|
+
offset--;
|
|
238
|
+
token = this.tokens[++index];
|
|
239
|
+
}
|
|
240
|
+
return token;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
*
|
|
244
|
+
* @returns
|
|
245
|
+
* @param open
|
|
246
|
+
* @param close
|
|
247
|
+
* @param counter
|
|
248
|
+
*/
|
|
249
|
+
peekRange(close = EnumToken.EndParensTokenType, counter = 0) {
|
|
250
|
+
let index = this.index;
|
|
251
|
+
let token = this.tokens[index];
|
|
252
|
+
// track balanced parens
|
|
253
|
+
let matchCount = 0;
|
|
254
|
+
const tokens = [];
|
|
255
|
+
while (index + 1 < this.tokens.length && this.arena.dataTypes[this.tokens[index + 1]] === EnumToken.WhitespaceTokenType) {
|
|
256
|
+
index++;
|
|
257
|
+
}
|
|
258
|
+
while (index + 1 < this.tokens.length) {
|
|
259
|
+
token = this.tokens[++index];
|
|
260
|
+
if (this.arena.dataTypes[token] === EnumToken.StartParensTokenType || tokensfuncDefMap.has(this.arena.dataTypes[token])) {
|
|
261
|
+
matchCount++;
|
|
262
|
+
}
|
|
263
|
+
else if (this.arena.dataTypes[token] === EnumToken.EndParensTokenType) {
|
|
264
|
+
matchCount--;
|
|
265
|
+
}
|
|
266
|
+
if (matchCount >= 0) {
|
|
267
|
+
tokens.push(token);
|
|
268
|
+
}
|
|
269
|
+
if (matchCount === 0) {
|
|
270
|
+
if (close !== EnumToken.EndParensTokenType && this.arena.dataTypes[token] === close) {
|
|
271
|
+
counter--;
|
|
233
272
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
273
|
+
}
|
|
274
|
+
if (matchCount <= 0 && counter <= 0) {
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return tokens;
|
|
279
|
+
}
|
|
280
|
+
// 2
|
|
281
|
+
split(split = EnumToken.CommaTokenType) {
|
|
282
|
+
let index = this.index;
|
|
283
|
+
let token = this.tokens[index];
|
|
284
|
+
// track balanced parens
|
|
285
|
+
let matchCount = 0;
|
|
286
|
+
const tokens = [[]];
|
|
287
|
+
while (index + 1 < this.tokens.length) {
|
|
288
|
+
token = this.tokens[++index];
|
|
289
|
+
if (this.arena.dataTypes[token] === EnumToken.StartParensTokenType || tokensfuncDefMap.has(this.arena.dataTypes[token])) {
|
|
290
|
+
matchCount++;
|
|
291
|
+
}
|
|
292
|
+
else if (this.arena.dataTypes[token] === EnumToken.EndParensTokenType) {
|
|
293
|
+
matchCount--;
|
|
294
|
+
}
|
|
295
|
+
if (matchCount === 0 && this.arena.dataTypes[token] === split) {
|
|
296
|
+
tokens.at(-1).push(token);
|
|
297
|
+
tokens.push([]);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
tokens.at(-1).push(token);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return tokens;
|
|
304
|
+
}
|
|
305
|
+
getRemainingTokens() {
|
|
306
|
+
return this.tokens.slice(this.index + 1);
|
|
307
|
+
}
|
|
308
|
+
end() {
|
|
309
|
+
this.index = this.tokens.length + 1;
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
next() {
|
|
313
|
+
let token = this.tokens[++this.index];
|
|
314
|
+
while (this.arena.dataTypes[token] === EnumToken.WhitespaceTokenType ||
|
|
315
|
+
this.arena.dataTypes[token] === EnumToken.CommentTokenType ||
|
|
316
|
+
this.arena.dataTypes[token] === EnumToken.CDOCOMMTokenType ||
|
|
317
|
+
this.arena.dataTypes[token] === EnumToken.BadCdoTokenType ||
|
|
318
|
+
this.arena.dataTypes[token] === EnumToken.BadCommentTokenType ||
|
|
319
|
+
this.arena.dataTypes[token] === EnumToken.BadStringTokenType) {
|
|
320
|
+
token = this.tokens[++this.index];
|
|
321
|
+
}
|
|
322
|
+
return token;
|
|
323
|
+
}
|
|
324
|
+
slice() {
|
|
325
|
+
return new ValidationTokenContext(this.arena, this.index == -1 ? this.tokens.slice() : this.tokens.slice(this.index), this.index == -1 ? -1 : 0);
|
|
326
|
+
}
|
|
327
|
+
update(token) {
|
|
328
|
+
const index = token == null ? -1 : this.tokens.indexOf(token);
|
|
329
|
+
if (index != -1) {
|
|
330
|
+
this.index = index;
|
|
331
|
+
}
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
done() {
|
|
335
|
+
if (this.index + 1 < this.tokens.length) {
|
|
336
|
+
let index = this.index + 1;
|
|
337
|
+
while (index < this.tokens.length) {
|
|
338
|
+
if (this.arena.dataTypes[this.tokens[index]] === EnumToken.WhitespaceTokenType ||
|
|
339
|
+
this.arena.dataTypes[this.tokens[index]] === EnumToken.CommentTokenType) {
|
|
340
|
+
index++;
|
|
237
341
|
}
|
|
238
342
|
else {
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return tokens;
|
|
243
|
-
},
|
|
244
|
-
getRemainingTokens() {
|
|
245
|
-
return this.tokens.slice(this.index + 1);
|
|
246
|
-
},
|
|
247
|
-
end() {
|
|
248
|
-
this.index = this.tokens.length + 1;
|
|
249
|
-
return this;
|
|
250
|
-
},
|
|
251
|
-
next() {
|
|
252
|
-
let token = this.tokens[++this.index];
|
|
253
|
-
while (token?.typ === EnumToken.WhitespaceTokenType ||
|
|
254
|
-
token?.typ === EnumToken.CommentTokenType ||
|
|
255
|
-
token?.typ === EnumToken.CDOCOMMTokenType ||
|
|
256
|
-
token?.typ === EnumToken.InvalidCommentTokenType ||
|
|
257
|
-
token?.typ === EnumToken.BadCommentTokenType ||
|
|
258
|
-
token?.typ === EnumToken.BadStringTokenType) {
|
|
259
|
-
token = this.tokens[++this.index];
|
|
260
|
-
}
|
|
261
|
-
return token;
|
|
262
|
-
},
|
|
263
|
-
slice() {
|
|
264
|
-
return {
|
|
265
|
-
...token,
|
|
266
|
-
index: this.index == -1 ? -1 : 0,
|
|
267
|
-
tokens: this.index == -1 ? this.tokens.slice() : this.tokens.slice(this.index),
|
|
268
|
-
};
|
|
269
|
-
},
|
|
270
|
-
update(token) {
|
|
271
|
-
const index = this.tokens.indexOf(token);
|
|
272
|
-
if (index != -1) {
|
|
273
|
-
this.index = index;
|
|
274
|
-
}
|
|
275
|
-
return this;
|
|
276
|
-
},
|
|
277
|
-
done() {
|
|
278
|
-
if (this.index + 1 < this.tokens.length) {
|
|
279
|
-
let index = this.index + 1;
|
|
280
|
-
while (index < this.tokens.length) {
|
|
281
|
-
if (this.tokens[index].typ === EnumToken.WhitespaceTokenType ||
|
|
282
|
-
this.tokens[index].typ === EnumToken.CommentTokenType) {
|
|
283
|
-
index++;
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
return false;
|
|
287
|
-
}
|
|
343
|
+
return false;
|
|
288
344
|
}
|
|
289
345
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
|
|
346
|
+
}
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* create validation context
|
|
352
|
+
* @param tokens
|
|
353
|
+
* @returns
|
|
354
|
+
*/
|
|
355
|
+
function createValidationContext(arena, tokens) {
|
|
356
|
+
const filtered = [];
|
|
357
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
358
|
+
if (arena.dataTypes[tokens[i]] !== EnumToken.CommentTokenType) {
|
|
359
|
+
filtered.push(tokens[i]);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
tokens = trimArray(arena, filtered);
|
|
363
|
+
// inlined: arena.typeOf(tokens.at(-1))
|
|
364
|
+
if (arena.dataTypes[tokens.at(-1)] === EnumToken.ImportantTokenType) {
|
|
365
|
+
tokens.pop();
|
|
366
|
+
trimArray(arena, tokens);
|
|
367
|
+
}
|
|
368
|
+
return new ValidationTokenContext(arena, tokens, -1);
|
|
294
369
|
}
|
|
295
370
|
/**
|
|
296
371
|
* match selector syntax
|
|
@@ -300,18 +375,18 @@ function createValidationContext(tokens) {
|
|
|
300
375
|
* @param nested
|
|
301
376
|
* @returns
|
|
302
377
|
*/
|
|
303
|
-
function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
378
|
+
function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
|
|
304
379
|
const stack = [];
|
|
305
380
|
const tokens = [];
|
|
306
381
|
let token;
|
|
307
382
|
let i = 0;
|
|
308
383
|
let success = true;
|
|
309
384
|
while (i < stream.length &&
|
|
310
|
-
(stream[i]
|
|
385
|
+
(arena.dataTypes[stream[i]] === EnumToken.WhitespaceTokenType || arena.dataTypes[stream[i]] === EnumToken.CommentTokenType)) {
|
|
311
386
|
i++;
|
|
312
387
|
}
|
|
313
388
|
if (i < stream.length) {
|
|
314
|
-
switch (stream[i]
|
|
389
|
+
switch (arena.dataTypes[stream[i]]) {
|
|
315
390
|
case EnumToken.Plus:
|
|
316
391
|
case EnumToken.Tilda:
|
|
317
392
|
case EnumToken.GtTokenType:
|
|
@@ -325,10 +400,11 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
325
400
|
errors: [
|
|
326
401
|
{
|
|
327
402
|
action: "drop",
|
|
328
|
-
message: `Unexpected token ${EnumToken[stream[i]
|
|
403
|
+
message: `Unexpected token ${EnumToken[arena.dataTypes[stream[i]]]}`,
|
|
329
404
|
node: stream[i],
|
|
405
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[i]))
|
|
330
406
|
// @ts-expect-error
|
|
331
|
-
location: options.source.
|
|
407
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i]))],
|
|
332
408
|
},
|
|
333
409
|
],
|
|
334
410
|
};
|
|
@@ -337,29 +413,29 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
337
413
|
}
|
|
338
414
|
for (; i < stream.length; i++) {
|
|
339
415
|
token = stream[i];
|
|
340
|
-
if (token
|
|
341
|
-
token
|
|
416
|
+
if (arena.dataTypes[token] === EnumToken.Star) {
|
|
417
|
+
arena.dataTypes[token] = EnumToken.UniversalSelectorTokenType;
|
|
342
418
|
}
|
|
343
419
|
tokens.push(token);
|
|
344
|
-
if (tokensfuncDefMap.has(token
|
|
345
|
-
if (stack.length > 0 && selectorNodeTypes.includes(stack.
|
|
420
|
+
if (tokensfuncDefMap.has(arena.dataTypes[token])) {
|
|
421
|
+
if (stack.length > 0 && selectorNodeTypes.includes(arena.dataTypes[stack[stack.length - 1]])) {
|
|
346
422
|
stack.pop();
|
|
347
423
|
}
|
|
348
424
|
stack.push(token);
|
|
349
425
|
continue;
|
|
350
426
|
}
|
|
351
427
|
if (stack.length > 0 &&
|
|
352
|
-
selectorNodeTypes.includes(stack.
|
|
353
|
-
!selectorNodeTypes.includes(token
|
|
354
|
-
token
|
|
355
|
-
token
|
|
356
|
-
token
|
|
428
|
+
selectorNodeTypes.includes(arena.dataTypes[stack[stack.length - 1]]) &&
|
|
429
|
+
!selectorNodeTypes.includes(arena.dataTypes[token]) &&
|
|
430
|
+
arena.dataTypes[token] !== EnumToken.WhitespaceTokenType &&
|
|
431
|
+
arena.dataTypes[token] !== EnumToken.CommentTokenType &&
|
|
432
|
+
arena.dataTypes[token] !== EnumToken.CDOCOMMTokenType) {
|
|
357
433
|
stack.pop();
|
|
358
434
|
}
|
|
359
|
-
switch (token
|
|
435
|
+
switch (arena.dataTypes[token]) {
|
|
360
436
|
case EnumToken.PseudoClassFuncTokenType:
|
|
361
437
|
{
|
|
362
|
-
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token
|
|
438
|
+
const result = matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi ?? [], createValidationContext(arena, arena.tokens(token)), options);
|
|
363
439
|
if (!result.success) {
|
|
364
440
|
success = false;
|
|
365
441
|
if (result.errors.length > 0) {
|
|
@@ -383,42 +459,46 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
383
459
|
action: "drop",
|
|
384
460
|
message: `Nesting selector is not allowed`,
|
|
385
461
|
node: token,
|
|
462
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
386
463
|
// @ts-expect-error
|
|
387
|
-
location: options.source.
|
|
464
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(token))],
|
|
388
465
|
},
|
|
389
466
|
],
|
|
390
467
|
};
|
|
391
468
|
}
|
|
392
469
|
break;
|
|
393
470
|
case EnumToken.Plus:
|
|
394
|
-
|
|
471
|
+
arena.dataTypes[token] = EnumToken.NextSiblingCombinatorTokenType;
|
|
395
472
|
stack.push(token);
|
|
396
473
|
break;
|
|
397
474
|
case EnumToken.Tilda:
|
|
398
475
|
case EnumToken.GtTokenType:
|
|
399
|
-
|
|
476
|
+
arena.dataTypes[token] = selectorEnumMap.get(arena.dataTypes[token]);
|
|
400
477
|
case EnumToken.ColumnCombinatorTokenType:
|
|
401
478
|
case EnumToken.ChildCombinatorTokenType:
|
|
402
479
|
case EnumToken.UniversalSelectorTokenType:
|
|
403
480
|
case EnumToken.DescendantCombinatorTokenType:
|
|
404
481
|
case EnumToken.NextSiblingCombinatorTokenType:
|
|
405
482
|
case EnumToken.SubsequentSiblingCombinatorTokenType:
|
|
406
|
-
if (stream[i + 1]
|
|
483
|
+
if (arena.dataTypes[stream[i + 1]] === EnumToken.WhitespaceTokenType) {
|
|
407
484
|
i++;
|
|
408
485
|
}
|
|
409
|
-
|
|
486
|
+
// inlined: arena.typeOf(stack.at(-1))
|
|
487
|
+
if (stack.length > 0 && arena.dataTypes[stack.at(-1)] === EnumToken.UniversalSelectorTokenType) {
|
|
410
488
|
stack.pop();
|
|
411
489
|
}
|
|
412
|
-
|
|
490
|
+
// inlined: arena.typeOf(stack.at(-1))
|
|
491
|
+
if (stack.length > 0 && selectorNodeTypes.includes((stack.at(-1) == null ? null : arena.dataTypes[stack.at(-1)]))) {
|
|
413
492
|
return {
|
|
414
493
|
success: false,
|
|
415
494
|
errors: [
|
|
416
495
|
{
|
|
417
496
|
action: "drop",
|
|
418
|
-
message: `Unexpected combinator ${EnumToken[token
|
|
497
|
+
message: `Unexpected combinator ${EnumToken[arena.dataTypes[token]]}`,
|
|
419
498
|
node: token,
|
|
499
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
420
500
|
// @ts-expect-error
|
|
421
|
-
location: options.source.
|
|
501
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(token))],
|
|
422
502
|
},
|
|
423
503
|
],
|
|
424
504
|
};
|
|
@@ -426,7 +506,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
426
506
|
stack.push(token);
|
|
427
507
|
break;
|
|
428
508
|
case EnumToken.CommaTokenType:
|
|
429
|
-
if (stack.length > 0 && stack.
|
|
509
|
+
if (stack.length > 0 && arena.dataTypes[stack[stack.length - 1]] === EnumToken.UniversalSelectorTokenType) {
|
|
430
510
|
stack.pop();
|
|
431
511
|
}
|
|
432
512
|
stack.push(token);
|
|
@@ -450,39 +530,41 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
450
530
|
stack.push(token);
|
|
451
531
|
break;
|
|
452
532
|
case EnumToken.AttrEndTokenType:
|
|
453
|
-
if (stack.length > 0 && stack.
|
|
533
|
+
if (stack.length > 0 && arena.dataTypes[stack[stack.length - 1]] === EnumToken.UniversalSelectorTokenType) {
|
|
454
534
|
stack.pop();
|
|
455
535
|
}
|
|
456
|
-
|
|
536
|
+
// inlined: arena.typeOf(stack.at(-1))
|
|
537
|
+
if (arena.dataTypes[stack.at(-1)] !== EnumToken.AttrStartTokenType) {
|
|
457
538
|
return {
|
|
458
539
|
success: false,
|
|
459
540
|
errors: [
|
|
460
541
|
{
|
|
461
542
|
action: "drop",
|
|
462
|
-
message: `Unexpected token ${EnumToken[token
|
|
543
|
+
message: `Unexpected token ${EnumToken[arena.dataTypes[token]]}`,
|
|
463
544
|
node: token,
|
|
545
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
464
546
|
// @ts-expect-error
|
|
465
|
-
location: options.source.
|
|
547
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(token))],
|
|
466
548
|
},
|
|
467
549
|
],
|
|
468
550
|
};
|
|
469
551
|
}
|
|
470
552
|
{
|
|
471
553
|
const k = tokens.length - 1;
|
|
472
|
-
let index = tokens.indexOf(stack.
|
|
554
|
+
let index = tokens.indexOf(stack[stack.length - 1]);
|
|
473
555
|
const slice = [];
|
|
474
556
|
for (let n = index + 1; n < k; n++) {
|
|
475
|
-
if (tokens[n]
|
|
476
|
-
tokens[n]
|
|
477
|
-
tokens[n]
|
|
557
|
+
if (arena.dataTypes[tokens[n]] === EnumToken.WhitespaceTokenType ||
|
|
558
|
+
arena.dataTypes[tokens[n]] === EnumToken.CommentTokenType ||
|
|
559
|
+
arena.dataTypes[tokens[n]] === EnumToken.CDOCOMMTokenType) {
|
|
478
560
|
continue;
|
|
479
561
|
}
|
|
480
562
|
slice.push(tokens[n]);
|
|
481
563
|
}
|
|
482
|
-
if (slice[1]
|
|
564
|
+
if (arena.dataTypes[slice[1]] === EnumToken.PipeTokenType) {
|
|
483
565
|
slice.shift();
|
|
484
566
|
}
|
|
485
|
-
if (slice[0]
|
|
567
|
+
if (arena.dataTypes[slice[0]] === EnumToken.PipeTokenType) {
|
|
486
568
|
slice.shift();
|
|
487
569
|
}
|
|
488
570
|
if (slice.length === 1) {
|
|
@@ -491,29 +573,29 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
491
573
|
}
|
|
492
574
|
slice.shift();
|
|
493
575
|
slice.shift();
|
|
494
|
-
if (slice[0]
|
|
495
|
-
/^[a-zA-Z0-9_-]+$/.test(slice[0].
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
});
|
|
576
|
+
if (arena.dataTypes[slice[0]] === EnumToken.StringTokenType &&
|
|
577
|
+
/^[a-zA-Z0-9_-]+$/.test(arena.strings[arena.stringValue[slice[0]]].slice(1, -1))) {
|
|
578
|
+
// inlined: arena.setStr(slice[0], arena.strings[arena.stringValue[slice[0]]].slice(1, -1))
|
|
579
|
+
arena.stringValue[slice[0]] = arena.internString(arena.strings[arena.stringValue[slice[0]]].slice(1, -1));
|
|
580
|
+
arena.dataTypes[slice[0]] = EnumToken.IdenTokenType;
|
|
500
581
|
}
|
|
501
582
|
slice.shift();
|
|
502
583
|
if (slice.length === 0) {
|
|
503
584
|
stack.pop();
|
|
504
585
|
break;
|
|
505
586
|
}
|
|
506
|
-
if (slice[0]
|
|
507
|
-
(slice[0]
|
|
587
|
+
if (arena.dataTypes[slice[0]] !== EnumToken.IdenTokenType ||
|
|
588
|
+
(arena.strings[arena.stringValue[slice[0]]] != "i" && arena.strings[arena.stringValue[slice[0]]] != "s")) {
|
|
508
589
|
return {
|
|
509
590
|
success: false,
|
|
510
591
|
errors: [
|
|
511
592
|
{
|
|
512
593
|
action: "drop",
|
|
513
|
-
message: `Unexpected token ${EnumToken[slice[0]
|
|
594
|
+
message: `Unexpected token ${EnumToken[arena.dataTypes[slice[0]]]}`,
|
|
514
595
|
node: slice[0],
|
|
596
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(slice[0]))
|
|
515
597
|
// @ts-expect-error
|
|
516
|
-
location: options.source.
|
|
598
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(slice[0]))],
|
|
517
599
|
},
|
|
518
600
|
],
|
|
519
601
|
};
|
|
@@ -528,22 +610,27 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
528
610
|
errors: [
|
|
529
611
|
{
|
|
530
612
|
action: "drop",
|
|
531
|
-
message: `Unexpected token ${EnumToken[token
|
|
613
|
+
message: `Unexpected token ${EnumToken[arena.dataTypes[token]]}`,
|
|
532
614
|
node: token,
|
|
615
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
533
616
|
// @ts-expect-error
|
|
534
|
-
location: options.source.
|
|
617
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(token))],
|
|
535
618
|
},
|
|
536
619
|
],
|
|
537
620
|
};
|
|
538
621
|
case EnumToken.EndParensTokenType:
|
|
539
|
-
|
|
622
|
+
// inlined: arena.typeOf(stack.at(-1))
|
|
623
|
+
if (stack.length > 0 && arena.dataTypes[stack.at(-1)] === EnumToken.UniversalSelectorTokenType) {
|
|
540
624
|
stack.pop();
|
|
541
625
|
}
|
|
542
|
-
if (
|
|
543
|
-
|
|
626
|
+
if (
|
|
627
|
+
// inlined: arena.typeOf(stack.at(-1))
|
|
628
|
+
arena.dataTypes[stack.at(-1)] === EnumToken.PseudoClassFunctionTokenDefType ||
|
|
629
|
+
// inlined: arena.typeOf(stack.at(-1))
|
|
630
|
+
arena.dataTypes[stack.at(-1)] === EnumToken.PseudoElementTokenType) {
|
|
544
631
|
const token = stack.at(-1);
|
|
545
632
|
const index = tokens.indexOf(token);
|
|
546
|
-
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token
|
|
633
|
+
const result = matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi ?? [], createValidationContext(arena, tokens.slice(index + 1, tokens.length - 1)), options);
|
|
547
634
|
if (!result.success) {
|
|
548
635
|
success = false;
|
|
549
636
|
if (result.errors.length > 0) {
|
|
@@ -560,17 +647,19 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
560
647
|
errors: [
|
|
561
648
|
{
|
|
562
649
|
action: "drop",
|
|
563
|
-
message: `Unexpected token ${EnumToken[token
|
|
650
|
+
message: `Unexpected token ${EnumToken[arena.dataTypes[token]]}`,
|
|
564
651
|
node: token,
|
|
652
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
565
653
|
// @ts-expect-error
|
|
566
|
-
location: options.source.
|
|
654
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(token))],
|
|
567
655
|
},
|
|
568
656
|
],
|
|
569
657
|
};
|
|
570
658
|
case EnumToken.NumberTokenType:
|
|
571
659
|
case EnumToken.LiteralTokenType:
|
|
572
660
|
case EnumToken.DimensionTokenType:
|
|
573
|
-
|
|
661
|
+
// inlined: arena.typeOf(stack.at(-1))
|
|
662
|
+
if (arena.dataTypes[stack.at(-1)] === EnumToken.PseudoClassFunctionTokenDefType) {
|
|
574
663
|
break;
|
|
575
664
|
}
|
|
576
665
|
default:
|
|
@@ -579,24 +668,28 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
579
668
|
errors: [
|
|
580
669
|
{
|
|
581
670
|
action: "drop",
|
|
582
|
-
message: `Unsupported selector token ${EnumToken[token
|
|
671
|
+
message: `Unsupported selector token ${EnumToken[arena.dataTypes[token]]}`,
|
|
583
672
|
node: token,
|
|
673
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
584
674
|
// @ts-expect-error
|
|
585
|
-
location: options.source.
|
|
675
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(token))],
|
|
586
676
|
},
|
|
587
677
|
],
|
|
588
678
|
};
|
|
589
679
|
}
|
|
590
|
-
if (token
|
|
591
|
-
|
|
592
|
-
tokens.at(-
|
|
680
|
+
if (arena.dataTypes[token] === EnumToken.WhitespaceTokenType &&
|
|
681
|
+
// inlined: arena.typeOf(tokens.at(-2))
|
|
682
|
+
trimWhitespaceAfter.includes((tokens.at(-2) == null ? null : arena.dataTypes[tokens.at(-2)])) &&
|
|
683
|
+
// inlined: arena.typeOf(tokens.at(-1))
|
|
684
|
+
arena.dataTypes[tokens.at(-1)] === EnumToken.WhitespaceTokenType) {
|
|
593
685
|
tokens.pop();
|
|
686
|
+
// inlined: arena.typeOf(token), arena.typeOf(tokens.at(-2))
|
|
594
687
|
}
|
|
595
|
-
else if (trimWhitespaceBefore.includes(token
|
|
688
|
+
else if (trimWhitespaceBefore.includes(arena.dataTypes[token]) && arena.dataTypes[tokens.at(-2)] === EnumToken.WhitespaceTokenType) {
|
|
596
689
|
tokens.splice(tokens.length - 2, 1);
|
|
597
690
|
}
|
|
598
691
|
}
|
|
599
|
-
if (stack.length > 0 && stack.
|
|
692
|
+
if (stack.length > 0 && arena.dataTypes[stack[stack.length - 1]] === EnumToken.UniversalSelectorTokenType) {
|
|
600
693
|
stack.pop();
|
|
601
694
|
}
|
|
602
695
|
if (stack.length > 0) {
|
|
@@ -605,10 +698,11 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
605
698
|
errors: [
|
|
606
699
|
{
|
|
607
700
|
action: "drop",
|
|
608
|
-
message: `Unmatched token ${EnumToken[stack.
|
|
609
|
-
node: stack.
|
|
701
|
+
message: `Unmatched token ${EnumToken[arena.dataTypes[stack[stack.length - 1]]]}`,
|
|
702
|
+
node: stack[stack.length - 1],
|
|
703
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stack[stack.length - 1]))
|
|
610
704
|
// @ts-expect-error
|
|
611
|
-
location: options.source.
|
|
705
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(stack[stack.length - 1]))],
|
|
612
706
|
},
|
|
613
707
|
],
|
|
614
708
|
};
|
|
@@ -619,6 +713,319 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
619
713
|
}
|
|
620
714
|
return { success, errors };
|
|
621
715
|
}
|
|
716
|
+
/**
|
|
717
|
+
* declaration validations (successful and failed), by string table of the arena, by syntax and by hash of the value
|
|
718
|
+
* encoding (see {@link encodeToken}). the encoding contains interned string ids: the string table is the key, it is
|
|
719
|
+
* replaced when the arena is compacted and the ids change (see {@link AstArena.compact})
|
|
720
|
+
*/
|
|
721
|
+
const declarationValidations = new WeakMap();
|
|
722
|
+
/**
|
|
723
|
+
* shared result of a declaration whose validation is cached
|
|
724
|
+
*/
|
|
725
|
+
const cachedValidMatch = Object.freeze({
|
|
726
|
+
success: true,
|
|
727
|
+
valid: true,
|
|
728
|
+
context: null,
|
|
729
|
+
token: null,
|
|
730
|
+
syntaxToken: null,
|
|
731
|
+
errors: Object.freeze([]),
|
|
732
|
+
});
|
|
733
|
+
/**
|
|
734
|
+
* encoding of the value being validated: 6 fields per token (type, interned name, interned string value, numeric
|
|
735
|
+
* value, interned unit, color type), followed by the encoding of its tokens between markers -1 / -2 and of its
|
|
736
|
+
* children between markers -3 / -4. the buffer is reused: no allocation unless a new valid value is cached
|
|
737
|
+
*/
|
|
738
|
+
let encoding = new Float64Array(512);
|
|
739
|
+
let encodingLength = 0;
|
|
740
|
+
let encodingHash = 0;
|
|
741
|
+
/**
|
|
742
|
+
* append a value to the encoding and update its hash
|
|
743
|
+
* @param value
|
|
744
|
+
*/
|
|
745
|
+
function encode(value) {
|
|
746
|
+
if (encodingLength == encoding.length) {
|
|
747
|
+
const previous = encoding;
|
|
748
|
+
encoding = new Float64Array(previous.length * 2);
|
|
749
|
+
encoding.set(previous);
|
|
750
|
+
}
|
|
751
|
+
encoding[encodingLength++] = value;
|
|
752
|
+
encodingHash = Math.imul(encodingHash ^ (Number.isInteger(value) ? value | 0 : (value * 4096) | 0), 0x01000193);
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* encode a token and its descendants. the validation only depends on these fields: two values with the same encoding
|
|
756
|
+
* are validated the same way
|
|
757
|
+
* @param arena
|
|
758
|
+
* @param token
|
|
759
|
+
*/
|
|
760
|
+
function encodeToken(arena, token) {
|
|
761
|
+
encode(arena.dataTypes[token]);
|
|
762
|
+
encode(arena.name[token]);
|
|
763
|
+
encode(arena.stringValue[token]);
|
|
764
|
+
encode(arena.numericValue[token]);
|
|
765
|
+
encode(arena.unit[token]);
|
|
766
|
+
encode(arena.colorType[token]);
|
|
767
|
+
if (arena.firstToken[token] != 0) {
|
|
768
|
+
encode(-1);
|
|
769
|
+
for (let child = arena.firstToken[token]; child != 0; child = arena.nextSibling[child]) {
|
|
770
|
+
encodeToken(arena, child);
|
|
771
|
+
}
|
|
772
|
+
encode(-2);
|
|
773
|
+
}
|
|
774
|
+
if (arena.firstChild[token] != 0) {
|
|
775
|
+
encode(-3);
|
|
776
|
+
for (let child = arena.firstChild[token]; child != 0; child = arena.nextSibling[child]) {
|
|
777
|
+
encodeToken(arena, child);
|
|
778
|
+
}
|
|
779
|
+
encode(-4);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* the cached validations with the hash of the current encoding
|
|
784
|
+
* @param arena
|
|
785
|
+
* @param syntaxes
|
|
786
|
+
* @param create create the bucket when missing
|
|
787
|
+
*/
|
|
788
|
+
function cachedValidations(arena, syntaxes, create) {
|
|
789
|
+
let bySyntax = declarationValidations.get(arena.strings);
|
|
790
|
+
if (bySyntax == null) {
|
|
791
|
+
if (!create) {
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
bySyntax = new Map();
|
|
795
|
+
declarationValidations.set(arena.strings, bySyntax);
|
|
796
|
+
}
|
|
797
|
+
let byHash = bySyntax.get(syntaxes);
|
|
798
|
+
if (byHash == null) {
|
|
799
|
+
if (!create) {
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
802
|
+
byHash = new Map();
|
|
803
|
+
bySyntax.set(syntaxes, byHash);
|
|
804
|
+
}
|
|
805
|
+
let bucket = byHash.get(encodingHash);
|
|
806
|
+
if (bucket == null && create) {
|
|
807
|
+
bucket = [];
|
|
808
|
+
byHash.set(encodingHash, bucket);
|
|
809
|
+
}
|
|
810
|
+
return bucket ?? null;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* the cached validation of the current encoding for the syntax
|
|
814
|
+
* @param arena
|
|
815
|
+
* @param syntaxes
|
|
816
|
+
*/
|
|
817
|
+
function findValidation(arena, syntaxes) {
|
|
818
|
+
const bucket = cachedValidations(arena, syntaxes, false);
|
|
819
|
+
if (bucket != null) {
|
|
820
|
+
for (let i = 0; i < bucket.length; i++) {
|
|
821
|
+
const candidate = bucket[i].encoding;
|
|
822
|
+
if (candidate.length == encodingLength) {
|
|
823
|
+
let k = 0;
|
|
824
|
+
while (k < encodingLength && candidate[k] === encoding[k]) {
|
|
825
|
+
k++;
|
|
826
|
+
}
|
|
827
|
+
if (k == encodingLength) {
|
|
828
|
+
return bucket[i];
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* cache the validation of an encoding for the syntax
|
|
837
|
+
* @param arena
|
|
838
|
+
* @param syntaxes
|
|
839
|
+
* @param value encoding
|
|
840
|
+
* @param hash encoding hash
|
|
841
|
+
* @param valid
|
|
842
|
+
* @param errors errors of a failed validation, null when unknown
|
|
843
|
+
*/
|
|
844
|
+
function cacheValidation(arena, syntaxes, value, hash, valid, errors) {
|
|
845
|
+
encodingHash = hash;
|
|
846
|
+
cachedValidations(arena, syntaxes, true).push({ encoding: value, valid, errors });
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* the value tokens and their descendants, in the encoding order (see {@link encodeToken})
|
|
850
|
+
* @param arena
|
|
851
|
+
* @param token
|
|
852
|
+
* @param result
|
|
853
|
+
*/
|
|
854
|
+
function collectTokens(arena, token, result) {
|
|
855
|
+
result.push(token);
|
|
856
|
+
for (let child = arena.firstToken[token]; child != 0; child = arena.nextSibling[child]) {
|
|
857
|
+
collectTokens(arena, child, result);
|
|
858
|
+
}
|
|
859
|
+
for (let child = arena.firstChild[token]; child != 0; child = arena.nextSibling[child]) {
|
|
860
|
+
collectTokens(arena, child, result);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* same source location
|
|
865
|
+
* @param a
|
|
866
|
+
* @param b
|
|
867
|
+
*/
|
|
868
|
+
function sameLocation(a, b) {
|
|
869
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* bind the errors of a failed validation to the position of their tokens in the value. null when an error refers to
|
|
873
|
+
* a token that is not part of the value (a copy created by the validation, ...)
|
|
874
|
+
* @param arena
|
|
875
|
+
* @param tokens value tokens, see {@link collectTokens}
|
|
876
|
+
* @param errors
|
|
877
|
+
* @param options
|
|
878
|
+
*/
|
|
879
|
+
function bindErrors(arena, tokens, errors, options) {
|
|
880
|
+
const result = [];
|
|
881
|
+
for (let i = 0; i < errors.length; i++) {
|
|
882
|
+
const error = errors[i];
|
|
883
|
+
let node = -1;
|
|
884
|
+
let location = -1;
|
|
885
|
+
if (error.node != null) {
|
|
886
|
+
node = tokens.indexOf(error.node);
|
|
887
|
+
if (node == -1) {
|
|
888
|
+
return null;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
if (error.location != null) {
|
|
892
|
+
// the location is computed from a token of the value: the error node, the last token, ...
|
|
893
|
+
if (node != -1 &&
|
|
894
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(tokens[node]))
|
|
895
|
+
sameLocation(error.location, [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(tokens[node]))])) {
|
|
896
|
+
location = node;
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
for (let k = 0; k < tokens.length; k++) {
|
|
900
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(tokens[k]))
|
|
901
|
+
if (sameLocation(error.location, [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(tokens[k]))])) {
|
|
902
|
+
location = k;
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (location == -1) {
|
|
907
|
+
return null;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
const copy = { ...error };
|
|
912
|
+
delete copy.node;
|
|
913
|
+
delete copy.location;
|
|
914
|
+
result.push({ error: copy, node, location });
|
|
915
|
+
}
|
|
916
|
+
return result;
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* rebuild the errors of a cached failed validation with the tokens of the value
|
|
920
|
+
* @param arena
|
|
921
|
+
* @param tokens value tokens, see {@link collectTokens}
|
|
922
|
+
* @param errors
|
|
923
|
+
* @param options
|
|
924
|
+
*/
|
|
925
|
+
function rebuildErrors(arena, tokens, errors, options) {
|
|
926
|
+
const result = [];
|
|
927
|
+
for (let i = 0; i < errors.length; i++) {
|
|
928
|
+
const error = { ...errors[i].error };
|
|
929
|
+
if (errors[i].node != -1) {
|
|
930
|
+
error.node = tokens[errors[i].node];
|
|
931
|
+
}
|
|
932
|
+
if (errors[i].location != -1) {
|
|
933
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(tokens[errors[i].location]))
|
|
934
|
+
error.location = [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(tokens[errors[i].location]))];
|
|
935
|
+
}
|
|
936
|
+
result.push(error);
|
|
937
|
+
}
|
|
938
|
+
return result;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* the value tokens and their descendants
|
|
942
|
+
* @param arena
|
|
943
|
+
* @param tokens
|
|
944
|
+
*/
|
|
945
|
+
function valueTokens(arena, tokens) {
|
|
946
|
+
const result = [];
|
|
947
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
948
|
+
collectTokens(arena, tokens[i], result);
|
|
949
|
+
}
|
|
950
|
+
return result;
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* validate the value of a declaration. a value that has already been validated for the same syntax in the same arena
|
|
954
|
+
* (same encoding, see {@link encodeToken}) is not validated again: `width: 10px` is validated once, whatever the number
|
|
955
|
+
* of rules that contain it. the failed validations are cached too: their errors are rebuilt with the tokens of the value
|
|
956
|
+
* @param arena
|
|
957
|
+
* @param syntaxes declaration syntax
|
|
958
|
+
* @param tokens value tokens
|
|
959
|
+
* @param options
|
|
960
|
+
*/
|
|
961
|
+
function matchDeclarationSyntax(arena, syntaxes, tokens, options) {
|
|
962
|
+
encodingLength = 0;
|
|
963
|
+
encodingHash = 0x811c9dc5;
|
|
964
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
965
|
+
encodeToken(arena, tokens[i]);
|
|
966
|
+
}
|
|
967
|
+
const cached = findValidation(arena, syntaxes);
|
|
968
|
+
if (cached != null) {
|
|
969
|
+
if (cached.valid) {
|
|
970
|
+
return cachedValidMatch;
|
|
971
|
+
}
|
|
972
|
+
if (cached.errors != null) {
|
|
973
|
+
return {
|
|
974
|
+
success: false,
|
|
975
|
+
valid: true,
|
|
976
|
+
context: null,
|
|
977
|
+
token: null,
|
|
978
|
+
syntaxToken: null,
|
|
979
|
+
errors: rebuildErrors(arena, valueTokens(arena, tokens), cached.errors, options),
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
// the encoding is copied before the validation, which may encode other values
|
|
984
|
+
const value = encoding.slice(0, encodingLength);
|
|
985
|
+
const hash = encodingHash;
|
|
986
|
+
const result = matchAllSyntaxes(arena, syntaxes, createValidationContext(arena, tokens), options);
|
|
987
|
+
if (result.success) {
|
|
988
|
+
cacheValidation(arena, syntaxes, value, hash, true, null);
|
|
989
|
+
}
|
|
990
|
+
else {
|
|
991
|
+
const errors = bindErrors(arena, valueTokens(arena, tokens), result.errors, options);
|
|
992
|
+
if (cached != null) {
|
|
993
|
+
// failure cached without its errors
|
|
994
|
+
cached.errors = errors;
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
cacheValidation(arena, syntaxes, value, hash, false, errors);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
return result;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* validate the value tokens of a declaration node, see {@link matchDeclarationSyntax}. the successful and the failed
|
|
1004
|
+
* validations are cached
|
|
1005
|
+
* @param arena
|
|
1006
|
+
* @param syntaxes declaration syntax
|
|
1007
|
+
* @param declaration declaration node
|
|
1008
|
+
* @param options
|
|
1009
|
+
* @returns true if the value is valid
|
|
1010
|
+
*/
|
|
1011
|
+
function isValidDeclarationValue(arena, syntaxes, declaration, options) {
|
|
1012
|
+
encodingLength = 0;
|
|
1013
|
+
encodingHash = 0x811c9dc5;
|
|
1014
|
+
for (let token = arena.firstToken[declaration]; token != 0; token = arena.nextSibling[token]) {
|
|
1015
|
+
encodeToken(arena, token);
|
|
1016
|
+
}
|
|
1017
|
+
const cached = findValidation(arena, syntaxes);
|
|
1018
|
+
if (cached != null) {
|
|
1019
|
+
return cached.valid;
|
|
1020
|
+
}
|
|
1021
|
+
// the encoding is copied before the validation, which may encode other values
|
|
1022
|
+
const value = encoding.slice(0, encodingLength);
|
|
1023
|
+
const hash = encodingHash;
|
|
1024
|
+
const valid = matchAllSyntaxes(arena, syntaxes, createValidationContext(arena, arena.tokens(declaration)), options).success;
|
|
1025
|
+
// the errors are not needed: they are computed if a declaration with the same value is validated by the parser
|
|
1026
|
+
cacheValidation(arena, syntaxes, value, hash, valid, null);
|
|
1027
|
+
return valid;
|
|
1028
|
+
}
|
|
622
1029
|
/**
|
|
623
1030
|
* matches all syntaxes
|
|
624
1031
|
* @param syntaxes
|
|
@@ -626,11 +1033,19 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
626
1033
|
* @param options
|
|
627
1034
|
* @returns
|
|
628
1035
|
*/
|
|
629
|
-
function matchAllSyntaxes(syntaxes, context, options) {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
1036
|
+
function matchAllSyntaxes(arena, syntaxes, context, options) {
|
|
1037
|
+
// the visited syntaxes are tracked per call. the options are not copied: the previous map is restored
|
|
1038
|
+
const visited = options.visited;
|
|
1039
|
+
// the result object is passed to the matching functions, which fill it
|
|
1040
|
+
const out = createMatch();
|
|
1041
|
+
let result;
|
|
1042
|
+
options.visited = new Map();
|
|
1043
|
+
try {
|
|
1044
|
+
result = matchSyntax(arena, syntaxes, context, options, out);
|
|
1045
|
+
}
|
|
1046
|
+
finally {
|
|
1047
|
+
options.visited = visited;
|
|
1048
|
+
}
|
|
634
1049
|
if (syntaxes != null && result.success && result.syntaxToken != null) {
|
|
635
1050
|
const index = syntaxes.indexOf(result.syntaxToken);
|
|
636
1051
|
if (index != -1) {
|
|
@@ -641,29 +1056,22 @@ function matchAllSyntaxes(syntaxes, context, options) {
|
|
|
641
1056
|
syntaxes[i].match?.min?.val === 0) {
|
|
642
1057
|
continue;
|
|
643
1058
|
}
|
|
644
|
-
return
|
|
645
|
-
...result,
|
|
646
|
-
success: false,
|
|
647
|
-
syntaxToken: syntaxes[i],
|
|
648
|
-
};
|
|
1059
|
+
return setMatch(out, false, result.valid, result.token, result.context, syntaxes[i], ownErrors(result.errors));
|
|
649
1060
|
}
|
|
650
1061
|
}
|
|
651
1062
|
}
|
|
652
|
-
return
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
: result.errors,
|
|
665
|
-
syntaxToken: !result.success ? result.syntaxToken : null,
|
|
666
|
-
};
|
|
1063
|
+
return setMatch(out, result.success, result.valid, result.token, result.context, !result.success ? result.syntaxToken : null, !result.success && result.errors.length === 0
|
|
1064
|
+
? [
|
|
1065
|
+
{
|
|
1066
|
+
action: "drop",
|
|
1067
|
+
message: result.errors[0]?.message || "could not match syntax",
|
|
1068
|
+
node: result.token,
|
|
1069
|
+
syntax: result.syntaxToken,
|
|
1070
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(result.token ?? (context.tokens[context.tokens.length - 1] as Token)))
|
|
1071
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(result.token ?? context.tokens[context.tokens.length - 1]))],
|
|
1072
|
+
},
|
|
1073
|
+
]
|
|
1074
|
+
: ownErrors(result.errors));
|
|
667
1075
|
}
|
|
668
1076
|
/**
|
|
669
1077
|
* matches a list of syntaxes
|
|
@@ -672,7 +1080,7 @@ function matchAllSyntaxes(syntaxes, context, options) {
|
|
|
672
1080
|
* @param options
|
|
673
1081
|
* @returns
|
|
674
1082
|
*/
|
|
675
|
-
function matchListSyntax(syntax, context, options) {
|
|
1083
|
+
function matchListSyntax(arena, syntax, context, options) {
|
|
676
1084
|
const { isList, match, isOptional, ...rest } = syntax;
|
|
677
1085
|
let success = true;
|
|
678
1086
|
let result = null;
|
|
@@ -682,14 +1090,18 @@ function matchListSyntax(syntax, context, options) {
|
|
|
682
1090
|
let done = false;
|
|
683
1091
|
success = false;
|
|
684
1092
|
do {
|
|
685
|
-
range = context.peekRange(EnumToken.CommaTokenType,
|
|
686
|
-
tmpResult = matchSyntax([rest], createValidationContext(
|
|
1093
|
+
range = context.peekRange(EnumToken.CommaTokenType, 1);
|
|
1094
|
+
tmpResult = matchSyntax(arena, [rest], createValidationContext(arena,
|
|
1095
|
+
// inlined: arena.typeOf(range.at(-1))
|
|
1096
|
+
arena.dataTypes[range.at(-1)] === EnumToken.CommaTokenType ? range.slice(0, -1) : range), options);
|
|
687
1097
|
if (tmpResult.success) {
|
|
688
1098
|
count++;
|
|
689
1099
|
success = true;
|
|
690
1100
|
result = tmpResult;
|
|
691
1101
|
if (Number.isFinite(match?.max?.val) && count === match.max.val) {
|
|
692
|
-
context.update(
|
|
1102
|
+
context.update(
|
|
1103
|
+
// inlined: arena.typeOf(range.at(-1))
|
|
1104
|
+
arena.dataTypes[range.at(-1)] === EnumToken.CommaTokenType ? (range.at(-2)) : (range.at(-1)));
|
|
693
1105
|
break;
|
|
694
1106
|
}
|
|
695
1107
|
else {
|
|
@@ -721,13 +1133,13 @@ function matchListSyntax(syntax, context, options) {
|
|
|
721
1133
|
* @param options
|
|
722
1134
|
* @returns
|
|
723
1135
|
*/
|
|
724
|
-
function matchOccurenceSyntax(syntax, context, options) {
|
|
1136
|
+
function matchOccurenceSyntax(arena, syntax, context, options) {
|
|
725
1137
|
const { match, ...rest } = syntax;
|
|
726
1138
|
let result = null;
|
|
727
1139
|
let tmpResult;
|
|
728
1140
|
let count = 0;
|
|
729
1141
|
do {
|
|
730
|
-
tmpResult = matchSyntax([rest], context.slice(), options);
|
|
1142
|
+
tmpResult = matchSyntax(arena, [rest], context.slice(), options);
|
|
731
1143
|
if (tmpResult.success) {
|
|
732
1144
|
count++;
|
|
733
1145
|
result = tmpResult;
|
|
@@ -772,16 +1184,9 @@ function matchOccurenceSyntax(syntax, context, options) {
|
|
|
772
1184
|
* @param options
|
|
773
1185
|
* @returns
|
|
774
1186
|
*/
|
|
775
|
-
function matchSyntax(syntaxes, context, options) {
|
|
1187
|
+
function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
|
|
776
1188
|
if (syntaxes == null) {
|
|
777
|
-
return
|
|
778
|
-
syntaxToken: null,
|
|
779
|
-
token: context.peek(),
|
|
780
|
-
success: true,
|
|
781
|
-
valid: false,
|
|
782
|
-
context,
|
|
783
|
-
errors: [],
|
|
784
|
-
};
|
|
1189
|
+
return setMatch(out, true, false, context.peek(), context, null, noErrors);
|
|
785
1190
|
}
|
|
786
1191
|
let i = -1;
|
|
787
1192
|
let success = false;
|
|
@@ -789,17 +1194,10 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
789
1194
|
let result = null;
|
|
790
1195
|
let isOptional;
|
|
791
1196
|
if (context.tokens.length == 1 &&
|
|
792
|
-
context.tokens[0]
|
|
793
|
-
|
|
1197
|
+
arena.dataTypes[context.tokens[0]] == EnumToken.IdenTokenType &&
|
|
1198
|
+
isCssWideKeyword(arena.strings[arena.stringValue[context.tokens[0]]])) {
|
|
794
1199
|
context.end();
|
|
795
|
-
return
|
|
796
|
-
syntaxToken: null,
|
|
797
|
-
token: context.peek(),
|
|
798
|
-
success: true,
|
|
799
|
-
valid: true,
|
|
800
|
-
context,
|
|
801
|
-
errors: [],
|
|
802
|
-
};
|
|
1200
|
+
return setMatch(out, true, true, context.peek(), context, null, noErrors);
|
|
803
1201
|
}
|
|
804
1202
|
while (++i < syntaxes.length) {
|
|
805
1203
|
if (syntaxes[i].typ == ValidationTokenEnum.Whitespace) {
|
|
@@ -813,26 +1211,19 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
813
1211
|
token = context.peek();
|
|
814
1212
|
if (token == null) {
|
|
815
1213
|
if (!isOptional) {
|
|
816
|
-
return
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
},
|
|
825
|
-
],
|
|
826
|
-
syntaxToken: syntaxes[i],
|
|
827
|
-
valid: true,
|
|
828
|
-
context,
|
|
829
|
-
token: null,
|
|
830
|
-
};
|
|
1214
|
+
return setMatch(out, false, true, null, context, syntaxes[i], [
|
|
1215
|
+
{
|
|
1216
|
+
action: "drop",
|
|
1217
|
+
message: "could not match syntax",
|
|
1218
|
+
node: null,
|
|
1219
|
+
syntax: syntaxes[i],
|
|
1220
|
+
},
|
|
1221
|
+
]);
|
|
831
1222
|
}
|
|
832
1223
|
break;
|
|
833
1224
|
}
|
|
834
|
-
if (token
|
|
835
|
-
result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token
|
|
1225
|
+
if (arena.dataTypes[token] === EnumToken.WildCardFunctionTokenType && arena.strings[arena.stringValue[token]] === "var") {
|
|
1226
|
+
result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi, createValidationContext(arena, arena.tokens(token)), options, out);
|
|
836
1227
|
if (result.success && result.context.done()) {
|
|
837
1228
|
context.next();
|
|
838
1229
|
continue;
|
|
@@ -840,27 +1231,23 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
840
1231
|
}
|
|
841
1232
|
if (
|
|
842
1233
|
// @ts-ignore
|
|
843
|
-
token
|
|
844
|
-
const range = trimArray(context.peekRange());
|
|
845
|
-
result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token
|
|
1234
|
+
arena.dataTypes[token] === EnumToken.WildCardFunctionTokenDefType) {
|
|
1235
|
+
const range = trimArray(arena, context.peekRange());
|
|
1236
|
+
result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi, createValidationContext(arena, range.slice(1, -1)), options, out);
|
|
846
1237
|
if (result.success) {
|
|
847
1238
|
context.update(range.at(-1));
|
|
848
1239
|
if (context.done()) {
|
|
849
|
-
return
|
|
850
|
-
...result,
|
|
851
|
-
context,
|
|
852
|
-
syntaxToken: syntaxes[i + 1],
|
|
853
|
-
};
|
|
1240
|
+
return setMatch(out, result.success, result.valid, result.token, context, syntaxes[i + 1], result.errors);
|
|
854
1241
|
}
|
|
855
1242
|
continue;
|
|
856
1243
|
}
|
|
857
1244
|
}
|
|
858
1245
|
if (syntaxes[i].isRepeatableAtLeastOnce || syntaxes[i].isRepeatable) {
|
|
859
|
-
result = matchRepeatableSyntax(syntaxes[i], context.slice(), options);
|
|
1246
|
+
result = matchRepeatableSyntax(arena, syntaxes[i], context.slice(), options);
|
|
860
1247
|
if (result.success) {
|
|
861
1248
|
if (result.context.done()) {
|
|
862
1249
|
context.end();
|
|
863
|
-
return
|
|
1250
|
+
return setMatch(out, result.success, result.valid, result.token, result.context, syntaxes[i + 1], result.errors);
|
|
864
1251
|
}
|
|
865
1252
|
context.update(result.context.current());
|
|
866
1253
|
continue;
|
|
@@ -871,19 +1258,12 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
871
1258
|
return result;
|
|
872
1259
|
}
|
|
873
1260
|
if (syntaxes[i].isList) {
|
|
874
|
-
result = matchListSyntax(syntaxes[i], context.slice(), options);
|
|
1261
|
+
result = matchListSyntax(arena, syntaxes[i], context.slice(), options);
|
|
875
1262
|
if (result.success) {
|
|
876
1263
|
options.visited.get(token)?.delete?.(syntaxes[i]);
|
|
877
1264
|
if (result.context.done()) {
|
|
878
1265
|
context.end();
|
|
879
|
-
return
|
|
880
|
-
...result,
|
|
881
|
-
success: true,
|
|
882
|
-
valid: true,
|
|
883
|
-
context,
|
|
884
|
-
token: null,
|
|
885
|
-
syntaxToken: syntaxes[i + 1],
|
|
886
|
-
};
|
|
1266
|
+
return setMatch(out, true, true, null, context, syntaxes[i + 1], result.errors);
|
|
887
1267
|
}
|
|
888
1268
|
context.update(result.context.current());
|
|
889
1269
|
continue;
|
|
@@ -891,26 +1271,15 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
891
1271
|
if (isOptional) {
|
|
892
1272
|
continue;
|
|
893
1273
|
}
|
|
894
|
-
return
|
|
895
|
-
success: false,
|
|
896
|
-
valid: true,
|
|
897
|
-
token,
|
|
898
|
-
context,
|
|
899
|
-
syntaxToken: syntaxes[i],
|
|
900
|
-
errors: result.errors,
|
|
901
|
-
};
|
|
1274
|
+
return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
|
|
902
1275
|
}
|
|
903
1276
|
if (syntaxes[i].match != null) {
|
|
904
|
-
result = matchOccurenceSyntax(syntaxes[i], context.slice(), options);
|
|
1277
|
+
result = matchOccurenceSyntax(arena, syntaxes[i], context.slice(), options);
|
|
905
1278
|
if (result.success) {
|
|
906
1279
|
options.visited.get(token).delete(syntaxes[i]);
|
|
907
1280
|
if (result.context.done()) {
|
|
908
1281
|
context.end();
|
|
909
|
-
return
|
|
910
|
-
...result,
|
|
911
|
-
context,
|
|
912
|
-
syntaxToken: syntaxes[++i],
|
|
913
|
-
};
|
|
1282
|
+
return setMatch(out, result.success, result.valid, result.token, context, syntaxes[++i], result.errors);
|
|
914
1283
|
}
|
|
915
1284
|
context.update(result.context.current());
|
|
916
1285
|
continue;
|
|
@@ -918,51 +1287,30 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
918
1287
|
if (isOptional) {
|
|
919
1288
|
continue;
|
|
920
1289
|
}
|
|
921
|
-
return
|
|
922
|
-
success: false,
|
|
923
|
-
valid: true,
|
|
924
|
-
token,
|
|
925
|
-
context,
|
|
926
|
-
syntaxToken: syntaxes[i],
|
|
927
|
-
errors: result.errors,
|
|
928
|
-
};
|
|
1290
|
+
return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
|
|
929
1291
|
}
|
|
930
1292
|
if (!options.visited.has(token)) {
|
|
931
1293
|
options.visited.set(token, new Set());
|
|
932
1294
|
}
|
|
933
1295
|
if (options.visited.get(token).has(syntaxes[i])) {
|
|
934
1296
|
// cyclic definition
|
|
935
|
-
return
|
|
936
|
-
success: false,
|
|
937
|
-
valid: true,
|
|
938
|
-
token,
|
|
939
|
-
context,
|
|
940
|
-
syntaxToken: syntaxes[i],
|
|
941
|
-
errors: [],
|
|
942
|
-
};
|
|
1297
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
943
1298
|
}
|
|
944
1299
|
options.visited.get(token).add(syntaxes[i]);
|
|
945
1300
|
success = false;
|
|
946
1301
|
switch (syntaxes[i].typ) {
|
|
947
1302
|
case ValidationTokenEnum.Comma:
|
|
948
|
-
if (token
|
|
1303
|
+
if (arena.dataTypes[token] == EnumToken.CommaTokenType) {
|
|
949
1304
|
success = true;
|
|
950
1305
|
options.visited.get(token).delete(syntaxes[i]);
|
|
951
1306
|
context.next();
|
|
952
1307
|
break;
|
|
953
1308
|
}
|
|
954
|
-
return
|
|
955
|
-
success: false,
|
|
956
|
-
valid: true,
|
|
957
|
-
token,
|
|
958
|
-
context,
|
|
959
|
-
syntaxToken: syntaxes[i],
|
|
960
|
-
errors: [],
|
|
961
|
-
};
|
|
1309
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
962
1310
|
case ValidationTokenEnum.Keyword:
|
|
963
|
-
if (token
|
|
964
|
-
|
|
965
|
-
syntaxes[i].val
|
|
1311
|
+
if (arena.dataTypes[token] == EnumToken.IdenTokenType &&
|
|
1312
|
+
lowercase(arena.strings[arena.stringValue[token]]) ===
|
|
1313
|
+
lowercase(syntaxes[i].val)) {
|
|
966
1314
|
success = true;
|
|
967
1315
|
options.visited.get(token).delete(syntaxes[i]);
|
|
968
1316
|
context.next();
|
|
@@ -971,27 +1319,15 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
971
1319
|
if (isOptional) {
|
|
972
1320
|
break;
|
|
973
1321
|
}
|
|
974
|
-
return
|
|
975
|
-
success: false,
|
|
976
|
-
valid: true,
|
|
977
|
-
token,
|
|
978
|
-
context,
|
|
979
|
-
syntaxToken: syntaxes[i],
|
|
980
|
-
errors: [],
|
|
981
|
-
};
|
|
1322
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
982
1323
|
case ValidationTokenEnum.DeclarationType:
|
|
983
|
-
result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, syntaxes[i].val), context, options);
|
|
1324
|
+
result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, syntaxes[i].val), context, options, out);
|
|
984
1325
|
if (result.success) {
|
|
985
1326
|
success = true;
|
|
986
1327
|
options.visited.get(token).delete(syntaxes[i]);
|
|
987
1328
|
if (result.context.done()) {
|
|
988
1329
|
context.end();
|
|
989
|
-
return
|
|
990
|
-
...result,
|
|
991
|
-
token,
|
|
992
|
-
context,
|
|
993
|
-
syntaxToken: syntaxes[1 + i],
|
|
994
|
-
};
|
|
1330
|
+
return setMatch(out, result.success, result.valid, token, context, syntaxes[1 + i], result.errors);
|
|
995
1331
|
}
|
|
996
1332
|
else {
|
|
997
1333
|
if (result.context.current() != null) {
|
|
@@ -1002,20 +1338,13 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1002
1338
|
if (success || isOptional) {
|
|
1003
1339
|
break;
|
|
1004
1340
|
}
|
|
1005
|
-
return
|
|
1006
|
-
success: false,
|
|
1007
|
-
valid: true,
|
|
1008
|
-
token,
|
|
1009
|
-
context,
|
|
1010
|
-
syntaxToken: syntaxes[i],
|
|
1011
|
-
errors: result.errors,
|
|
1012
|
-
};
|
|
1341
|
+
return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
|
|
1013
1342
|
case ValidationTokenEnum.OptionalGroupToken: {
|
|
1014
1343
|
//
|
|
1015
1344
|
const tokens = context.split();
|
|
1016
1345
|
let j = 0;
|
|
1017
1346
|
for (; j < tokens.length; j++) {
|
|
1018
|
-
result = matchSyntax(syntaxes[i].chi, context.slice(), options);
|
|
1347
|
+
result = matchSyntax(arena, syntaxes[i].chi, context.slice(), options, out);
|
|
1019
1348
|
if (result.success) {
|
|
1020
1349
|
context.update(tokens[j].at(-1));
|
|
1021
1350
|
}
|
|
@@ -1027,16 +1356,16 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1027
1356
|
break;
|
|
1028
1357
|
}
|
|
1029
1358
|
case ValidationTokenEnum.StringToken:
|
|
1030
|
-
if (token
|
|
1359
|
+
if (arena.dataTypes[token] === EnumToken.Add) {
|
|
1031
1360
|
success = syntaxes[i].val.slice(1, -1) === "+";
|
|
1032
1361
|
}
|
|
1033
|
-
else if (token
|
|
1362
|
+
else if (arena.dataTypes[token] === EnumToken.Sub) {
|
|
1034
1363
|
success = syntaxes[i].val.slice(1, -1) === "-";
|
|
1035
1364
|
}
|
|
1036
|
-
else if (token
|
|
1037
|
-
success = token
|
|
1365
|
+
else if (arena.dataTypes[token] === EnumToken.LiteralTokenType) {
|
|
1366
|
+
success = arena.strings[arena.stringValue[token]] === syntaxes[i].val.slice(1, -1);
|
|
1038
1367
|
}
|
|
1039
|
-
else if (token
|
|
1368
|
+
else if (arena.dataTypes[token] == EnumToken.Plus) {
|
|
1040
1369
|
success = true;
|
|
1041
1370
|
}
|
|
1042
1371
|
if (success) {
|
|
@@ -1046,41 +1375,20 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1046
1375
|
if (isOptional) {
|
|
1047
1376
|
break;
|
|
1048
1377
|
}
|
|
1049
|
-
return
|
|
1050
|
-
success: false,
|
|
1051
|
-
valid: true,
|
|
1052
|
-
token,
|
|
1053
|
-
context,
|
|
1054
|
-
syntaxToken: syntaxes[i],
|
|
1055
|
-
errors: [],
|
|
1056
|
-
};
|
|
1378
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1057
1379
|
case ValidationTokenEnum.PropertyType:
|
|
1058
|
-
result = matchProperty(syntaxes[i], context, options);
|
|
1380
|
+
result = matchProperty(arena, syntaxes[i], context, options);
|
|
1059
1381
|
if (!result.success) {
|
|
1060
1382
|
if (isOptional) {
|
|
1061
1383
|
break;
|
|
1062
1384
|
}
|
|
1063
|
-
return
|
|
1064
|
-
success: false,
|
|
1065
|
-
valid: true,
|
|
1066
|
-
token: context.current() ?? token,
|
|
1067
|
-
context,
|
|
1068
|
-
syntaxToken: syntaxes[i],
|
|
1069
|
-
errors: [],
|
|
1070
|
-
};
|
|
1385
|
+
return setMatch(out, false, true, context.current() ?? token, context, syntaxes[i], noErrors);
|
|
1071
1386
|
}
|
|
1072
1387
|
success = true;
|
|
1073
1388
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1074
1389
|
if (result.context.done()) {
|
|
1075
1390
|
context.end();
|
|
1076
|
-
return
|
|
1077
|
-
success,
|
|
1078
|
-
valid: true,
|
|
1079
|
-
token: null,
|
|
1080
|
-
context,
|
|
1081
|
-
syntaxToken: syntaxes[i + 1],
|
|
1082
|
-
errors: [],
|
|
1083
|
-
};
|
|
1391
|
+
return setMatch(out, success, true, null, context, syntaxes[i + 1], noErrors);
|
|
1084
1392
|
}
|
|
1085
1393
|
else {
|
|
1086
1394
|
context.update(result.context.current());
|
|
@@ -1088,20 +1396,23 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1088
1396
|
break;
|
|
1089
1397
|
case ValidationTokenEnum.PipeToken:
|
|
1090
1398
|
{
|
|
1091
|
-
result
|
|
1399
|
+
// each alternative is matched in the same scratch result, the best match is copied
|
|
1400
|
+
const scratch = createMatch();
|
|
1401
|
+
let best = null;
|
|
1092
1402
|
let tmp = null;
|
|
1093
1403
|
for (const syntax of syntaxes[i].chi) {
|
|
1094
|
-
tmp = matchSyntax(syntax, context.slice(), options);
|
|
1404
|
+
tmp = matchSyntax(arena, syntax, context.slice(), options, scratch);
|
|
1095
1405
|
if (tmp.success) {
|
|
1096
|
-
if (
|
|
1097
|
-
|
|
1406
|
+
if (best == null || tmp.context.index >= best.context.index) {
|
|
1407
|
+
best = copyMatch(best ?? createMatch(), tmp);
|
|
1098
1408
|
}
|
|
1099
1409
|
if (tmp.context.done()) {
|
|
1100
1410
|
context.end();
|
|
1101
|
-
return
|
|
1411
|
+
return setMatch(out, tmp.success, tmp.valid, tmp.token, context, syntaxes[i + 1], tmp.errors);
|
|
1102
1412
|
}
|
|
1103
1413
|
}
|
|
1104
1414
|
}
|
|
1415
|
+
result = best;
|
|
1105
1416
|
if (result?.success) {
|
|
1106
1417
|
success = true;
|
|
1107
1418
|
options.visited.get(token).delete(syntaxes[i]);
|
|
@@ -1109,38 +1420,24 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1109
1420
|
break;
|
|
1110
1421
|
}
|
|
1111
1422
|
}
|
|
1112
|
-
return
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
node: token,
|
|
1123
|
-
// @ts-ignore
|
|
1124
|
-
// location: options.source!.getSourceLocation(token[LOC]?.sta),
|
|
1125
|
-
syntax: syntaxes[i],
|
|
1126
|
-
},
|
|
1127
|
-
],
|
|
1128
|
-
};
|
|
1423
|
+
return setMatch(out, false, true, token, context, syntaxes[i], [
|
|
1424
|
+
{
|
|
1425
|
+
action: "drop",
|
|
1426
|
+
message: "could not match syntax",
|
|
1427
|
+
node: token,
|
|
1428
|
+
// @ts-ignore
|
|
1429
|
+
// location: options.source!.getSourceLocation(token[LOC]?.sta),
|
|
1430
|
+
syntax: syntaxes[i],
|
|
1431
|
+
},
|
|
1432
|
+
]);
|
|
1129
1433
|
case ValidationTokenEnum.Bracket:
|
|
1130
|
-
result = matchSyntax(syntaxes[i].chi, context.slice(), options);
|
|
1434
|
+
result = matchSyntax(arena, syntaxes[i].chi, context.slice(), options, out);
|
|
1131
1435
|
if (result.success) {
|
|
1132
1436
|
success = true;
|
|
1133
1437
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1134
1438
|
if (result.context.done()) {
|
|
1135
1439
|
context.end();
|
|
1136
|
-
return
|
|
1137
|
-
success,
|
|
1138
|
-
valid: true,
|
|
1139
|
-
token: null,
|
|
1140
|
-
context,
|
|
1141
|
-
syntaxToken: syntaxes[1 + i],
|
|
1142
|
-
errors: [],
|
|
1143
|
-
};
|
|
1440
|
+
return setMatch(out, success, true, null, context, syntaxes[1 + i], noErrors);
|
|
1144
1441
|
}
|
|
1145
1442
|
else {
|
|
1146
1443
|
context.update(result.context.current());
|
|
@@ -1150,96 +1447,53 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1150
1447
|
if (isOptional) {
|
|
1151
1448
|
break;
|
|
1152
1449
|
}
|
|
1153
|
-
return
|
|
1154
|
-
success: false,
|
|
1155
|
-
valid: true,
|
|
1156
|
-
token,
|
|
1157
|
-
context,
|
|
1158
|
-
syntaxToken: syntaxes[i],
|
|
1159
|
-
errors: [],
|
|
1160
|
-
};
|
|
1450
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1161
1451
|
case ValidationTokenEnum.ColumnToken:
|
|
1162
|
-
result = matchColumnSyntax(syntaxes[i], context.slice(), options);
|
|
1452
|
+
result = matchColumnSyntax(arena, syntaxes[i], context.slice(), options);
|
|
1163
1453
|
if (result.success) {
|
|
1164
1454
|
success = true;
|
|
1165
1455
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1166
1456
|
if (result.context.done()) {
|
|
1167
1457
|
context.end();
|
|
1168
|
-
return
|
|
1169
|
-
success,
|
|
1170
|
-
valid: true,
|
|
1171
|
-
token: null,
|
|
1172
|
-
context,
|
|
1173
|
-
syntaxToken: syntaxes[1 + i],
|
|
1174
|
-
errors: [],
|
|
1175
|
-
};
|
|
1458
|
+
return setMatch(out, success, true, null, context, syntaxes[1 + i], noErrors);
|
|
1176
1459
|
}
|
|
1177
1460
|
else {
|
|
1178
1461
|
context.update(result.context.current());
|
|
1179
1462
|
}
|
|
1180
1463
|
break;
|
|
1181
1464
|
}
|
|
1182
|
-
return
|
|
1183
|
-
success: false,
|
|
1184
|
-
valid: true,
|
|
1185
|
-
token,
|
|
1186
|
-
context,
|
|
1187
|
-
syntaxToken: syntaxes[i],
|
|
1188
|
-
errors: [],
|
|
1189
|
-
};
|
|
1465
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1190
1466
|
case ValidationTokenEnum.AmpersandToken:
|
|
1191
|
-
result = matchAmpersandSyntax(syntaxes[i], context.slice(), options);
|
|
1467
|
+
result = matchAmpersandSyntax(arena, syntaxes[i], context.slice(), options);
|
|
1192
1468
|
if (result.success) {
|
|
1193
1469
|
success = true;
|
|
1194
1470
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1195
1471
|
if (result.context.done()) {
|
|
1196
1472
|
context.end();
|
|
1197
|
-
return
|
|
1198
|
-
success,
|
|
1199
|
-
valid: true,
|
|
1200
|
-
token: null,
|
|
1201
|
-
context,
|
|
1202
|
-
syntaxToken: syntaxes[1 + i],
|
|
1203
|
-
errors: [],
|
|
1204
|
-
};
|
|
1473
|
+
return setMatch(out, success, true, null, context, syntaxes[1 + i], noErrors);
|
|
1205
1474
|
}
|
|
1206
1475
|
else {
|
|
1207
1476
|
context.update(result.context.current());
|
|
1208
1477
|
}
|
|
1209
1478
|
break;
|
|
1210
1479
|
}
|
|
1211
|
-
return
|
|
1212
|
-
success: false,
|
|
1213
|
-
valid: true,
|
|
1214
|
-
token,
|
|
1215
|
-
context,
|
|
1216
|
-
syntaxToken: syntaxes[i],
|
|
1217
|
-
errors: [],
|
|
1218
|
-
};
|
|
1480
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1219
1481
|
case ValidationTokenEnum.Function:
|
|
1220
|
-
if ((!tokensfuncDefMap.has(token
|
|
1221
|
-
!funcLike.includes(token
|
|
1222
|
-
!funcTypes.includes(token
|
|
1223
|
-
!(
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
errors: [
|
|
1232
|
-
{
|
|
1233
|
-
action: "drop",
|
|
1234
|
-
message: `Expecting a function ${EnumToken[token.typ]}`,
|
|
1235
|
-
node: token,
|
|
1236
|
-
},
|
|
1237
|
-
],
|
|
1238
|
-
};
|
|
1482
|
+
if ((!tokensfuncDefMap.has(arena.dataTypes[token]) &&
|
|
1483
|
+
!funcLike.includes(arena.dataTypes[token]) &&
|
|
1484
|
+
!funcTypes.includes(arena.dataTypes[token])) ||
|
|
1485
|
+
!equalsIgnoreCase(syntaxes[i].val, arena.strings[arena.stringValue[token]].toLowerCase())) {
|
|
1486
|
+
return setMatch(out, false, true, token, context, syntaxes[i], [
|
|
1487
|
+
{
|
|
1488
|
+
action: "drop",
|
|
1489
|
+
message: `Expecting a function ${EnumToken[arena.dataTypes[token]]}`,
|
|
1490
|
+
node: token,
|
|
1491
|
+
},
|
|
1492
|
+
]);
|
|
1239
1493
|
}
|
|
1240
|
-
if (tokensfuncDefMap.has(token
|
|
1494
|
+
if (tokensfuncDefMap.has(arena.dataTypes[token])) {
|
|
1241
1495
|
const range = context.peekRange();
|
|
1242
|
-
result = matchSyntax(syntaxes[i].chi, createValidationContext(range.slice(1, -1)), options);
|
|
1496
|
+
result = matchSyntax(arena, syntaxes[i].chi, createValidationContext(arena, range.slice(1, -1)), options, out);
|
|
1243
1497
|
if (result.success && result.context.done()) {
|
|
1244
1498
|
context.update(range.at(-1));
|
|
1245
1499
|
options.visited.get(token).delete(syntaxes[i]);
|
|
@@ -1247,7 +1501,7 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1247
1501
|
}
|
|
1248
1502
|
}
|
|
1249
1503
|
else {
|
|
1250
|
-
result = matchSyntax(syntaxes[i].chi, createValidationContext(token
|
|
1504
|
+
result = matchSyntax(arena, syntaxes[i].chi, createValidationContext(arena, arena.tokens(token)), options, out);
|
|
1251
1505
|
if (result.success && result.context.done()) {
|
|
1252
1506
|
success = true;
|
|
1253
1507
|
options.visited.get(token).delete(syntaxes[i]);
|
|
@@ -1255,34 +1509,20 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1255
1509
|
break;
|
|
1256
1510
|
}
|
|
1257
1511
|
}
|
|
1258
|
-
return
|
|
1259
|
-
success: false,
|
|
1260
|
-
valid: true,
|
|
1261
|
-
token,
|
|
1262
|
-
context,
|
|
1263
|
-
syntaxToken: syntaxes[i],
|
|
1264
|
-
errors: result.errors,
|
|
1265
|
-
};
|
|
1512
|
+
return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
|
|
1266
1513
|
case ValidationTokenEnum.Separator:
|
|
1267
|
-
if (token
|
|
1514
|
+
if (arena.dataTypes[token] === EnumToken.LiteralTokenType && arena.strings[arena.stringValue[token]] === "/") {
|
|
1268
1515
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1269
1516
|
context.next();
|
|
1270
1517
|
break;
|
|
1271
1518
|
}
|
|
1272
|
-
return
|
|
1273
|
-
success: false,
|
|
1274
|
-
valid: true,
|
|
1275
|
-
token,
|
|
1276
|
-
context,
|
|
1277
|
-
syntaxToken: syntaxes[i],
|
|
1278
|
-
errors: [],
|
|
1279
|
-
};
|
|
1519
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1280
1520
|
case ValidationTokenEnum.FunctionDefinition:
|
|
1281
|
-
if (token
|
|
1282
|
-
equalsIgnoreCase(token
|
|
1283
|
-
if (tokensfuncDefMap.has(token
|
|
1284
|
-
const children = trimArray(context.peekRange());
|
|
1285
|
-
result = matchSyntax((getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(children.slice(1, -1)), options);
|
|
1521
|
+
if (arena.strings[arena.stringValue[token]] &&
|
|
1522
|
+
equalsIgnoreCase(arena.strings[arena.stringValue[token]], syntaxes[i].val)) {
|
|
1523
|
+
if (tokensfuncDefMap.has(arena.dataTypes[token])) {
|
|
1524
|
+
const children = trimArray(arena, context.peekRange());
|
|
1525
|
+
result = matchSyntax(arena, (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(arena, children.slice(1, -1)), options, out);
|
|
1286
1526
|
if (result.success && result.context.done()) {
|
|
1287
1527
|
success = true;
|
|
1288
1528
|
options.visited.get(token).delete(syntaxes[i]);
|
|
@@ -1290,8 +1530,8 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1290
1530
|
break;
|
|
1291
1531
|
}
|
|
1292
1532
|
}
|
|
1293
|
-
else if (tokensfuncSet.has(token
|
|
1294
|
-
result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()") ?? [], createValidationContext([token]), options);
|
|
1533
|
+
else if (tokensfuncSet.has(arena.dataTypes[token])) {
|
|
1534
|
+
result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()") ?? [], createValidationContext(arena, [token]), options, out);
|
|
1295
1535
|
if (result.success && result.context.done()) {
|
|
1296
1536
|
success = true;
|
|
1297
1537
|
options.visited.get(token).delete(syntaxes[i]);
|
|
@@ -1300,72 +1540,44 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1300
1540
|
}
|
|
1301
1541
|
}
|
|
1302
1542
|
}
|
|
1303
|
-
return
|
|
1304
|
-
success: false,
|
|
1305
|
-
valid: true,
|
|
1306
|
-
token,
|
|
1307
|
-
context,
|
|
1308
|
-
syntaxToken: syntaxes[i],
|
|
1309
|
-
errors: [],
|
|
1310
|
-
};
|
|
1543
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1311
1544
|
case ValidationTokenEnum.OpenParenthesis:
|
|
1312
|
-
if (token
|
|
1545
|
+
if (arena.dataTypes[token] === EnumToken.StartParensTokenType) {
|
|
1313
1546
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1314
1547
|
context.next();
|
|
1315
1548
|
break;
|
|
1316
1549
|
}
|
|
1317
|
-
return
|
|
1318
|
-
success: false,
|
|
1319
|
-
valid: true,
|
|
1320
|
-
token,
|
|
1321
|
-
context,
|
|
1322
|
-
syntaxToken: syntaxes[i],
|
|
1323
|
-
errors: [],
|
|
1324
|
-
};
|
|
1550
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1325
1551
|
case ValidationTokenEnum.OpenCurlyBrace:
|
|
1326
|
-
if (token
|
|
1552
|
+
if (arena.dataTypes[token] === EnumToken.BlockStartTokenType) {
|
|
1327
1553
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1328
1554
|
context.next();
|
|
1329
1555
|
break;
|
|
1330
1556
|
}
|
|
1331
|
-
return
|
|
1332
|
-
success: false,
|
|
1333
|
-
valid: true,
|
|
1334
|
-
token,
|
|
1335
|
-
context,
|
|
1336
|
-
syntaxToken: syntaxes[i],
|
|
1337
|
-
errors: [],
|
|
1338
|
-
};
|
|
1557
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1339
1558
|
case ValidationTokenEnum.CloseParenthesis:
|
|
1340
|
-
if (token
|
|
1559
|
+
if (arena.dataTypes[token] === EnumToken.EndParensTokenType) {
|
|
1341
1560
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1342
1561
|
context.next();
|
|
1343
1562
|
break;
|
|
1344
1563
|
}
|
|
1345
|
-
return
|
|
1346
|
-
success: false,
|
|
1347
|
-
valid: true,
|
|
1348
|
-
token,
|
|
1349
|
-
context,
|
|
1350
|
-
syntaxToken: syntaxes[i],
|
|
1351
|
-
errors: [],
|
|
1352
|
-
};
|
|
1564
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1353
1565
|
default:
|
|
1354
1566
|
throw new Error(`Unexpected syntax ${ValidationTokenEnum[syntaxes[i].typ]}`);
|
|
1355
1567
|
}
|
|
1356
1568
|
if (success &&
|
|
1357
1569
|
"range" in syntaxes[i] &&
|
|
1358
|
-
!(token
|
|
1359
|
-
token
|
|
1360
|
-
token
|
|
1570
|
+
!(arena.dataTypes[token] === EnumToken.MathFunctionTokenType ||
|
|
1571
|
+
arena.dataTypes[token] === EnumToken.MathFunctionTokenDefType ||
|
|
1572
|
+
arena.dataTypes[token] === EnumToken.WildCardFunctionTokenDefType)) {
|
|
1361
1573
|
let success = false;
|
|
1362
1574
|
success =
|
|
1363
|
-
|
|
1364
|
-
token
|
|
1575
|
+
!arena.hasFraction(token) &&
|
|
1576
|
+
arena.numericValue[token] >=
|
|
1365
1577
|
syntaxes[i].range.min.val;
|
|
1366
1578
|
if (syntaxes[i].range.min.typ === ValidationTokenEnum.Dimension) {
|
|
1367
1579
|
success =
|
|
1368
|
-
token
|
|
1580
|
+
arena.dataTypes[token] ===
|
|
1369
1581
|
EnumToken[
|
|
1370
1582
|
// @ts-expect-error
|
|
1371
1583
|
syntaxes[i].range.min
|
|
@@ -1374,31 +1586,15 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1374
1586
|
if (success &&
|
|
1375
1587
|
syntaxes[i].range.max != null) {
|
|
1376
1588
|
success =
|
|
1377
|
-
token
|
|
1589
|
+
arena.numericValue[token] <=
|
|
1378
1590
|
syntaxes[i].range.max.val;
|
|
1379
1591
|
}
|
|
1380
1592
|
if (!success) {
|
|
1381
|
-
return
|
|
1382
|
-
success: false,
|
|
1383
|
-
valid: true,
|
|
1384
|
-
token,
|
|
1385
|
-
context,
|
|
1386
|
-
syntaxToken: syntaxes[i],
|
|
1387
|
-
errors: [],
|
|
1388
|
-
};
|
|
1593
|
+
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
1389
1594
|
}
|
|
1390
1595
|
}
|
|
1391
1596
|
}
|
|
1392
|
-
return result?.success
|
|
1393
|
-
? result
|
|
1394
|
-
: {
|
|
1395
|
-
success: true,
|
|
1396
|
-
context,
|
|
1397
|
-
syntaxToken: syntaxes[i] ?? null,
|
|
1398
|
-
token,
|
|
1399
|
-
valid: true,
|
|
1400
|
-
errors: [],
|
|
1401
|
-
};
|
|
1597
|
+
return result?.success ? result : setMatch(out, true, true, token, context, syntaxes[i] ?? null, noErrors);
|
|
1402
1598
|
}
|
|
1403
1599
|
/**
|
|
1404
1600
|
* matches a column of syntaxes
|
|
@@ -1407,14 +1603,14 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1407
1603
|
* @param options
|
|
1408
1604
|
* @returns
|
|
1409
1605
|
*/
|
|
1410
|
-
function matchColumnSyntax(syntax, context, options) {
|
|
1606
|
+
function matchColumnSyntax(arena, syntax, context, options) {
|
|
1411
1607
|
let syntaxes = syntax.chi.slice();
|
|
1412
1608
|
let i = 0;
|
|
1413
1609
|
let success = false;
|
|
1414
1610
|
let result;
|
|
1415
1611
|
syntaxes = syntaxes.slice();
|
|
1416
1612
|
for (; i < syntaxes.length; i++) {
|
|
1417
|
-
result = matchSyntax(syntaxes[i], context.slice(), options);
|
|
1613
|
+
result = matchSyntax(arena, syntaxes[i], context.slice(), options);
|
|
1418
1614
|
if (result.success) {
|
|
1419
1615
|
const curr = result.context.current();
|
|
1420
1616
|
if (curr == null && !result.context.done()) {
|
|
@@ -1450,12 +1646,12 @@ function matchColumnSyntax(syntax, context, options) {
|
|
|
1450
1646
|
* @param options
|
|
1451
1647
|
* @returns
|
|
1452
1648
|
*/
|
|
1453
|
-
function matchAmpersandSyntax(syntax, context, options) {
|
|
1649
|
+
function matchAmpersandSyntax(arena, syntax, context, options) {
|
|
1454
1650
|
const syntaxes = [syntax.l, syntax.r];
|
|
1455
1651
|
let result;
|
|
1456
1652
|
let i;
|
|
1457
1653
|
for (i = 0; i < syntaxes.length; i++) {
|
|
1458
|
-
result = matchSyntax(syntaxes[i], context.slice(), options);
|
|
1654
|
+
result = matchSyntax(arena, syntaxes[i], context.slice(), options);
|
|
1459
1655
|
if (result.success) {
|
|
1460
1656
|
if (result.context.done()) {
|
|
1461
1657
|
context.end();
|
|
@@ -1475,10 +1671,11 @@ function matchAmpersandSyntax(syntax, context, options) {
|
|
|
1475
1671
|
* @param options
|
|
1476
1672
|
* @returns
|
|
1477
1673
|
*/
|
|
1478
|
-
function matchProperty(property, context, options) {
|
|
1674
|
+
function matchProperty(arena, property, context, options) {
|
|
1479
1675
|
let success = false;
|
|
1480
1676
|
const token = context.peek();
|
|
1481
|
-
|
|
1677
|
+
// inlined: arena.typeOf(token)
|
|
1678
|
+
let t = (token == null ? null : arena.dataTypes[token]);
|
|
1482
1679
|
let checkCalc = (t == EnumToken.MathFunctionTokenDefType || t == EnumToken.MathFunctionTokenType) &&
|
|
1483
1680
|
[
|
|
1484
1681
|
"number",
|
|
@@ -1493,13 +1690,13 @@ function matchProperty(property, context, options) {
|
|
|
1493
1690
|
"calc-product",
|
|
1494
1691
|
].includes(property.val);
|
|
1495
1692
|
if (checkCalc && !["number", "zero", "integer", "percentage", "length-percentage"].includes(property.val)) {
|
|
1496
|
-
checkCalc = token
|
|
1693
|
+
checkCalc = arena.strings[arena.stringValue[token]] === "calc";
|
|
1497
1694
|
}
|
|
1498
1695
|
if (checkCalc) {
|
|
1499
1696
|
let result;
|
|
1500
|
-
const syntax = getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token
|
|
1697
|
+
const syntax = getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi;
|
|
1501
1698
|
if (t === EnumToken.MathFunctionTokenType) {
|
|
1502
|
-
result = matchSyntax(syntax, createValidationContext(token
|
|
1699
|
+
result = matchSyntax(arena, syntax, createValidationContext(arena, arena.tokens(token)), options);
|
|
1503
1700
|
if (result.success && result.context.done()) {
|
|
1504
1701
|
context.next();
|
|
1505
1702
|
return {
|
|
@@ -1514,13 +1711,13 @@ function matchProperty(property, context, options) {
|
|
|
1514
1711
|
}
|
|
1515
1712
|
else {
|
|
1516
1713
|
const range = context.peekRange();
|
|
1517
|
-
result = matchSyntax(syntax, createValidationContext(range.slice(1, -1)), options);
|
|
1714
|
+
result = matchSyntax(arena, syntax, createValidationContext(arena, range.slice(1, -1)), options);
|
|
1518
1715
|
if (result.success) {
|
|
1519
1716
|
context.update(range.at(-1));
|
|
1520
1717
|
return {
|
|
1521
1718
|
success: true,
|
|
1522
1719
|
valid: true,
|
|
1523
|
-
token: range.
|
|
1720
|
+
token: range[range.length - 1] ?? null,
|
|
1524
1721
|
context,
|
|
1525
1722
|
syntaxToken: null,
|
|
1526
1723
|
errors: [],
|
|
@@ -1552,16 +1749,16 @@ function matchProperty(property, context, options) {
|
|
|
1552
1749
|
if (token != null) {
|
|
1553
1750
|
success = false;
|
|
1554
1751
|
while ((token = context.peek()) != null) {
|
|
1555
|
-
if (token
|
|
1752
|
+
if (arena.dataTypes[token] == EnumToken.StartParensTokenType || tokensfuncDefMap.has(arena.dataTypes[token])) {
|
|
1556
1753
|
stack.push(token);
|
|
1557
1754
|
}
|
|
1558
1755
|
if (expectToken) {
|
|
1559
1756
|
expectToken = false;
|
|
1560
1757
|
}
|
|
1561
|
-
if (token
|
|
1758
|
+
if (arena.dataTypes[token] == EnumToken.CommaTokenType) {
|
|
1562
1759
|
expectToken = true;
|
|
1563
1760
|
}
|
|
1564
|
-
if (token
|
|
1761
|
+
if (arena.dataTypes[token] == EnumToken.EndParensTokenType) {
|
|
1565
1762
|
if (stack.length > 0) {
|
|
1566
1763
|
stack.pop();
|
|
1567
1764
|
}
|
|
@@ -1588,15 +1785,16 @@ function matchProperty(property, context, options) {
|
|
|
1588
1785
|
break;
|
|
1589
1786
|
case "calc-sum": {
|
|
1590
1787
|
const token = context.peek();
|
|
1591
|
-
|
|
1592
|
-
|
|
1788
|
+
// inlined: arena.typeOf(token)
|
|
1789
|
+
if (arena.dataTypes[token] === EnumToken.BinaryExpressionTokenType) {
|
|
1790
|
+
let result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc-sum"), createValidationContext(arena, [arena.field(token, TokenField.L)]), options);
|
|
1593
1791
|
if (result.success) {
|
|
1594
|
-
result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc-sum"), createValidationContext([token.
|
|
1792
|
+
result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc-sum"), createValidationContext(arena, [arena.field(token, TokenField.R)]), options);
|
|
1595
1793
|
}
|
|
1596
1794
|
success = result.success;
|
|
1597
1795
|
break;
|
|
1598
1796
|
}
|
|
1599
|
-
const result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc-sum"), context.slice(), options);
|
|
1797
|
+
const result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc-sum"), context.slice(), options);
|
|
1600
1798
|
success = result.success;
|
|
1601
1799
|
if (success) {
|
|
1602
1800
|
if (result.context.done()) {
|
|
@@ -1619,31 +1817,39 @@ function matchProperty(property, context, options) {
|
|
|
1619
1817
|
case "an+b":
|
|
1620
1818
|
{
|
|
1621
1819
|
let token = context.peek();
|
|
1622
|
-
if (
|
|
1623
|
-
|
|
1820
|
+
if (
|
|
1821
|
+
// inlined: arena.typeOf(token)
|
|
1822
|
+
arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
1823
|
+
("even" === arena.strings[arena.stringValue[token]] ||
|
|
1824
|
+
"odd" === arena.strings[arena.stringValue[token]])) {
|
|
1624
1825
|
success = true;
|
|
1625
1826
|
break;
|
|
1626
1827
|
}
|
|
1627
|
-
if (
|
|
1628
|
-
|
|
1629
|
-
|
|
1828
|
+
if (
|
|
1829
|
+
// inlined: arena.typeOf(token)
|
|
1830
|
+
arena.dataTypes[token] === EnumToken.NumberTokenType &&
|
|
1831
|
+
Number.isInteger(arena.numericValue[token])) {
|
|
1630
1832
|
success = true;
|
|
1631
1833
|
break;
|
|
1632
1834
|
}
|
|
1633
|
-
|
|
1634
|
-
|
|
1835
|
+
// inlined: arena.typeOf(token)
|
|
1836
|
+
if (arena.dataTypes[token] === EnumToken.LiteralTokenType || arena.dataTypes[token] === EnumToken.IdenTokenType) {
|
|
1837
|
+
let match = /^(([+-]?[0-9]*)?n)?([+-]?[0-9]+)?$/.exec(arena.strings[arena.stringValue[token]]);
|
|
1635
1838
|
success = match != null;
|
|
1636
1839
|
if (match?.[3] == null) {
|
|
1637
1840
|
token = context.peek(1);
|
|
1638
|
-
if (
|
|
1639
|
-
|
|
1640
|
-
|
|
1841
|
+
if (
|
|
1842
|
+
// inlined: arena.typeOf(token)
|
|
1843
|
+
arena.dataTypes[token] === EnumToken.Add ||
|
|
1844
|
+
// inlined: arena.typeOf(token)
|
|
1845
|
+
arena.dataTypes[token] === EnumToken.NextSiblingCombinatorTokenType ||
|
|
1846
|
+
// inlined: arena.typeOf(token)
|
|
1847
|
+
arena.dataTypes[token] === EnumToken.Sub) {
|
|
1641
1848
|
token = context.peek(2);
|
|
1642
1849
|
success =
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
token.sign == null;
|
|
1850
|
+
// inlined: arena.typeOf(token)
|
|
1851
|
+
arena.dataTypes[token] === EnumToken.NumberTokenType &&
|
|
1852
|
+
Number.isInteger(arena.numericValue[token]);
|
|
1647
1853
|
}
|
|
1648
1854
|
if (success) {
|
|
1649
1855
|
context.update(token);
|
|
@@ -1659,31 +1865,27 @@ function matchProperty(property, context, options) {
|
|
|
1659
1865
|
}
|
|
1660
1866
|
break;
|
|
1661
1867
|
}
|
|
1662
|
-
if (
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1868
|
+
if (
|
|
1869
|
+
// inlined: arena.typeOf(token)
|
|
1870
|
+
arena.dataTypes[token] === EnumToken.DimensionTokenType &&
|
|
1871
|
+
arena.strings[arena.unit[token]] === "n") {
|
|
1872
|
+
success = Number.isInteger(arena.numericValue[token]);
|
|
1666
1873
|
token = context.peek(1);
|
|
1667
1874
|
if (token == null) {
|
|
1668
1875
|
break;
|
|
1669
1876
|
}
|
|
1670
|
-
if (token
|
|
1671
|
-
|
|
1672
|
-
!token.toString().includes(".") &&
|
|
1673
|
-
["+", "-"].includes(token.sign)) {
|
|
1674
|
-
success = true;
|
|
1675
|
-
context.next();
|
|
1676
|
-
}
|
|
1877
|
+
if (arena.dataTypes[token] === EnumToken.NumberTokenType) {
|
|
1878
|
+
// the sign of the number is not tracked by the tokenizer
|
|
1677
1879
|
break;
|
|
1678
1880
|
}
|
|
1679
|
-
if (token
|
|
1680
|
-
|
|
1881
|
+
if (arena.dataTypes[token] === EnumToken.NextSiblingCombinatorTokenType) {
|
|
1882
|
+
arena.dataTypes[token] = EnumToken.Add;
|
|
1681
1883
|
}
|
|
1682
1884
|
token = context.peek(2);
|
|
1683
|
-
if (
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
token
|
|
1885
|
+
if (
|
|
1886
|
+
// inlined: arena.typeOf(token)
|
|
1887
|
+
arena.dataTypes[token] === EnumToken.NumberTokenType &&
|
|
1888
|
+
Number.isInteger(arena.numericValue[token])) {
|
|
1687
1889
|
success = true;
|
|
1688
1890
|
context.next();
|
|
1689
1891
|
context.next();
|
|
@@ -1704,21 +1906,24 @@ function matchProperty(property, context, options) {
|
|
|
1704
1906
|
values = new Set(config.syntaxes[property.val].syntax.split(/[\s|]+/));
|
|
1705
1907
|
propertyKeywordValues.set(property.val, values);
|
|
1706
1908
|
}
|
|
1707
|
-
|
|
1909
|
+
// inlined: arena.typeOf(token)
|
|
1910
|
+
success = arena.dataTypes[token] == EnumToken.IdenTokenType && values.has(arena.strings[arena.stringValue[token]].toLowerCase());
|
|
1708
1911
|
break;
|
|
1709
1912
|
}
|
|
1710
1913
|
case "mf-name":
|
|
1711
1914
|
{
|
|
1712
1915
|
const token = context.peek();
|
|
1713
1916
|
success =
|
|
1714
|
-
|
|
1715
|
-
|
|
1917
|
+
// inlined: arena.typeOf(token)
|
|
1918
|
+
arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
1919
|
+
arena.strings[arena.stringValue[token]].toLowerCase() in config.mediaFeatures;
|
|
1716
1920
|
}
|
|
1717
1921
|
break;
|
|
1718
1922
|
case "dashed-ident":
|
|
1719
1923
|
case "extension-name":
|
|
1720
1924
|
case "custom-property-name":
|
|
1721
|
-
|
|
1925
|
+
// inlined: arena.typeOf(context.peek())
|
|
1926
|
+
success = arena.dataTypes[context.peek()] == EnumToken.DashedIdenTokenType;
|
|
1722
1927
|
break;
|
|
1723
1928
|
case "namespace-prefix":
|
|
1724
1929
|
case "ident":
|
|
@@ -1726,9 +1931,11 @@ function matchProperty(property, context, options) {
|
|
|
1726
1931
|
case "custom-ident":
|
|
1727
1932
|
case "counter-name":
|
|
1728
1933
|
case "counter-style-name":
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1934
|
+
// inlined: arena.typeOf(token)
|
|
1935
|
+
success = arena.dataTypes[token] == EnumToken.IdenTokenType || arena.dataTypes[token] == EnumToken.DashedIdenTokenType;
|
|
1936
|
+
// inlined: arena.typeOf(token)
|
|
1937
|
+
if (success && arena.dataTypes[token] === EnumToken.IdenTokenType) {
|
|
1938
|
+
const val = arena.strings[arena.stringValue[token]].toLowerCase();
|
|
1732
1939
|
success = "none" !== val && !allValues.includes(val);
|
|
1733
1940
|
}
|
|
1734
1941
|
break;
|
|
@@ -1748,16 +1955,18 @@ function matchProperty(property, context, options) {
|
|
|
1748
1955
|
EnumToken.TimingFunctionTokenType,
|
|
1749
1956
|
EnumToken.TimelineFunctionTokenType,
|
|
1750
1957
|
EnumToken.TransformFunctionTokenType,
|
|
1751
|
-
].includes(token
|
|
1958
|
+
].includes(arena.dataTypes[token]);
|
|
1752
1959
|
break;
|
|
1753
1960
|
}
|
|
1754
1961
|
case "string": {
|
|
1755
1962
|
const token = context.peek();
|
|
1756
|
-
|
|
1963
|
+
// inlined: arena.typeOf(token)
|
|
1964
|
+
success = arena.dataTypes[token] === EnumToken.StringTokenType;
|
|
1757
1965
|
break;
|
|
1758
1966
|
}
|
|
1759
1967
|
case "wq-name": {
|
|
1760
|
-
|
|
1968
|
+
// inlined: arena.typeOf(context.peek())
|
|
1969
|
+
const success = arena.dataTypes[context.peek()] == EnumToken.IdenTokenType;
|
|
1761
1970
|
return {
|
|
1762
1971
|
success,
|
|
1763
1972
|
valid: true,
|
|
@@ -1770,45 +1979,59 @@ function matchProperty(property, context, options) {
|
|
|
1770
1979
|
case "number":
|
|
1771
1980
|
{
|
|
1772
1981
|
const token = context.peek();
|
|
1773
|
-
|
|
1982
|
+
// inlined: arena.typeOf(token)
|
|
1983
|
+
success = arena.dataTypes[token] == EnumToken.NumberTokenType;
|
|
1774
1984
|
}
|
|
1775
1985
|
break;
|
|
1776
1986
|
case "zero": {
|
|
1777
1987
|
const token = context.peek();
|
|
1778
|
-
|
|
1988
|
+
// inlined: arena.typeOf(token)
|
|
1989
|
+
success = arena.dataTypes[token] == EnumToken.NumberTokenType && arena.numericValue[token] === 0;
|
|
1779
1990
|
break;
|
|
1780
1991
|
}
|
|
1781
1992
|
case "integer":
|
|
1782
1993
|
{
|
|
1783
1994
|
const token = context.peek();
|
|
1784
1995
|
success =
|
|
1785
|
-
|
|
1996
|
+
// inlined: arena.typeOf(token)
|
|
1997
|
+
arena.dataTypes[token] == EnumToken.NumberTokenType && Number.isInteger(Number(arena.numericValue[token]));
|
|
1786
1998
|
}
|
|
1787
1999
|
break;
|
|
1788
2000
|
case "dimension": {
|
|
1789
2001
|
const token = context.peek();
|
|
1790
2002
|
success =
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
token
|
|
1795
|
-
|
|
1796
|
-
token
|
|
1797
|
-
|
|
1798
|
-
token
|
|
1799
|
-
|
|
2003
|
+
// inlined: arena.typeOf(token)
|
|
2004
|
+
arena.dataTypes[token] == EnumToken.DimensionTokenType ||
|
|
2005
|
+
// inlined: arena.typeOf(token)
|
|
2006
|
+
arena.dataTypes[token] == EnumToken.AngleTokenType ||
|
|
2007
|
+
// inlined: arena.typeOf(token)
|
|
2008
|
+
arena.dataTypes[token] == EnumToken.LengthTokenType ||
|
|
2009
|
+
// inlined: arena.typeOf(token)
|
|
2010
|
+
arena.dataTypes[token] == EnumToken.PercentageTokenType ||
|
|
2011
|
+
// inlined: arena.typeOf(token)
|
|
2012
|
+
arena.dataTypes[token] == EnumToken.ResolutionTokenType ||
|
|
2013
|
+
// inlined: arena.typeOf(token)
|
|
2014
|
+
arena.dataTypes[token] == EnumToken.TimeTokenType ||
|
|
2015
|
+
// inlined: arena.typeOf(token)
|
|
2016
|
+
arena.dataTypes[token] == EnumToken.FrequencyTokenType ||
|
|
2017
|
+
// inlined: arena.typeOf(token)
|
|
2018
|
+
arena.dataTypes[token] == EnumToken.UserDefinedDimensionTokenType ||
|
|
2019
|
+
// inlined: arena.typeOf(token)
|
|
2020
|
+
arena.dataTypes[token] == EnumToken.FlexTokenType;
|
|
1800
2021
|
break;
|
|
1801
2022
|
}
|
|
1802
2023
|
case "angle":
|
|
1803
2024
|
{
|
|
1804
2025
|
const token = context.peek();
|
|
1805
|
-
|
|
2026
|
+
// inlined: arena.typeOf(token)
|
|
2027
|
+
success = arena.dataTypes[token] === EnumToken.AngleTokenType || arena.dataTypes[token] === EnumToken.UserDefinedDimensionTokenType;
|
|
1806
2028
|
}
|
|
1807
2029
|
break;
|
|
1808
2030
|
case "angle-percentage":
|
|
1809
2031
|
{
|
|
1810
2032
|
const token = context.peek();
|
|
1811
|
-
|
|
2033
|
+
// inlined: arena.typeOf(token)
|
|
2034
|
+
success = arena.dataTypes[token] === EnumToken.AngleTokenType || arena.dataTypes[token] === EnumToken.UserDefinedDimensionTokenType || arena.dataTypes[token] === EnumToken.PercentageTokenType;
|
|
1812
2035
|
}
|
|
1813
2036
|
break;
|
|
1814
2037
|
case "percentage":
|
|
@@ -1817,28 +2040,36 @@ function matchProperty(property, context, options) {
|
|
|
1817
2040
|
if (token == null) {
|
|
1818
2041
|
break;
|
|
1819
2042
|
}
|
|
1820
|
-
success = token
|
|
2043
|
+
success = arena.dataTypes[token] === EnumToken.PercentageTokenType;
|
|
1821
2044
|
}
|
|
1822
2045
|
break;
|
|
1823
2046
|
case "length-percentage":
|
|
1824
2047
|
{
|
|
1825
2048
|
const token = context.peek();
|
|
1826
2049
|
success =
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
2050
|
+
// inlined: arena.typeOf(token)
|
|
2051
|
+
arena.dataTypes[token] == EnumToken.PercentageTokenType ||
|
|
2052
|
+
// inlined: arena.typeOf(token)
|
|
2053
|
+
arena.dataTypes[token] == EnumToken.LengthTokenType ||
|
|
2054
|
+
// inlined: arena.typeOf(token)
|
|
2055
|
+
arena.dataTypes[token] == EnumToken.UserDefinedDimensionTokenType ||
|
|
2056
|
+
// inlined: arena.typeOf(token)
|
|
2057
|
+
(arena.dataTypes[token] == EnumToken.NumberTokenType && arena.numericValue[token] === 0);
|
|
1831
2058
|
}
|
|
1832
2059
|
break;
|
|
1833
2060
|
case "flex":
|
|
1834
|
-
|
|
2061
|
+
// inlined: arena.typeOf(context.peek())
|
|
2062
|
+
success = arena.dataTypes[context.peek()] == EnumToken.FlexTokenType || arena.dataTypes[context.peek()] == EnumToken.UserDefinedDimensionTokenType;
|
|
1835
2063
|
break;
|
|
1836
2064
|
case "length": {
|
|
1837
2065
|
const token = context.peek();
|
|
1838
2066
|
success =
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
2067
|
+
// inlined: arena.typeOf(token)
|
|
2068
|
+
arena.dataTypes[token] == EnumToken.LengthTokenType ||
|
|
2069
|
+
// inlined: arena.typeOf(token)
|
|
2070
|
+
arena.dataTypes[token] == EnumToken.UserDefinedDimensionTokenType ||
|
|
2071
|
+
// inlined: arena.typeOf(token)
|
|
2072
|
+
(arena.dataTypes[token] == EnumToken.NumberTokenType && arena.numericValue[token] === 0);
|
|
1842
2073
|
break;
|
|
1843
2074
|
}
|
|
1844
2075
|
case "time":
|
|
@@ -1847,7 +2078,7 @@ function matchProperty(property, context, options) {
|
|
|
1847
2078
|
if (token == null) {
|
|
1848
2079
|
break;
|
|
1849
2080
|
}
|
|
1850
|
-
success = token
|
|
2081
|
+
success = arena.dataTypes[token] == EnumToken.TimeTokenType || arena.dataTypes[token] == EnumToken.UserDefinedDimensionTokenType;
|
|
1851
2082
|
}
|
|
1852
2083
|
break;
|
|
1853
2084
|
case "color":
|
|
@@ -1855,13 +2086,12 @@ function matchProperty(property, context, options) {
|
|
|
1855
2086
|
{
|
|
1856
2087
|
const token = context.peek();
|
|
1857
2088
|
const errors = [];
|
|
1858
|
-
|
|
2089
|
+
// inlined: arena.typeOf(token)
|
|
2090
|
+
if (tokensfuncDefMap.has((token == null ? null : arena.dataTypes[token]))) {
|
|
1859
2091
|
const range = context.peekRange();
|
|
1860
|
-
const newRange = range.map((t) =>
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
// @ts-ignore
|
|
1864
|
-
success = newRange.length == 1 && isColor(newRange[0], errors);
|
|
2092
|
+
const newRange = range.map((t) => arena.clone(t, true));
|
|
2093
|
+
parseTokens(arena, newRange, { parseColor: true }, errors);
|
|
2094
|
+
success = newRange.length == 1 && isColor(arena, newRange[0], errors);
|
|
1865
2095
|
if (success) {
|
|
1866
2096
|
context.update(range.at(-1));
|
|
1867
2097
|
return {
|
|
@@ -1882,11 +2112,7 @@ function matchProperty(property, context, options) {
|
|
|
1882
2112
|
errors,
|
|
1883
2113
|
};
|
|
1884
2114
|
}
|
|
1885
|
-
|
|
1886
|
-
else if ("chi" in token) {
|
|
1887
|
-
success = isColor(token, errors);
|
|
1888
|
-
}
|
|
1889
|
-
success = token != null && isColor(token, errors);
|
|
2115
|
+
success = token != null && isColor(arena, token, errors);
|
|
1890
2116
|
if (!success) {
|
|
1891
2117
|
return {
|
|
1892
2118
|
success,
|
|
@@ -1909,7 +2135,7 @@ function matchProperty(property, context, options) {
|
|
|
1909
2135
|
case "forgiving-relative-selector-list":
|
|
1910
2136
|
case "complex-selector-list": {
|
|
1911
2137
|
const tokens = context.getRemainingTokens();
|
|
1912
|
-
const result = matchSelectorSyntax(tokens, [], options, property.val.startsWith("forgiving-relative-selector-list"));
|
|
2138
|
+
const result = matchSelectorSyntax(arena, tokens, [], options, property.val.startsWith("forgiving-relative-selector-list"));
|
|
1913
2139
|
if (result.success || property.val == "forgiving-relative-selector-list") {
|
|
1914
2140
|
context.update(tokens.at(-1));
|
|
1915
2141
|
}
|
|
@@ -1923,7 +2149,8 @@ function matchProperty(property, context, options) {
|
|
|
1923
2149
|
};
|
|
1924
2150
|
}
|
|
1925
2151
|
case "function-token":
|
|
1926
|
-
|
|
2152
|
+
// inlined: arena.typeOf(context.peek()). the type of a null id is undefined: not a key of the map either
|
|
2153
|
+
if (tokensfuncDefMap.has(arena.dataTypes[context.peek()])) {
|
|
1927
2154
|
success = true;
|
|
1928
2155
|
context.next();
|
|
1929
2156
|
break;
|
|
@@ -1939,18 +2166,19 @@ function matchProperty(property, context, options) {
|
|
|
1939
2166
|
case "language-code": {
|
|
1940
2167
|
const token = context.peek();
|
|
1941
2168
|
success =
|
|
1942
|
-
|
|
2169
|
+
// inlined: arena.typeOf(token)
|
|
2170
|
+
arena.dataTypes[token] == EnumToken.IdenTokenType &&
|
|
1943
2171
|
// @ts-expect-error
|
|
1944
|
-
config.languages.some((t) => t === token
|
|
2172
|
+
config.languages.some((t) => t === arena.strings[arena.stringValue[token]] || arena.strings[arena.stringValue[token]].startsWith(t + "-"));
|
|
1945
2173
|
break;
|
|
1946
2174
|
}
|
|
1947
2175
|
case "size-feature": {
|
|
1948
2176
|
const range = context.peekRange();
|
|
1949
|
-
const filteredRange = range.filter((token) => token
|
|
2177
|
+
const filteredRange = range.filter((token) => arena.dataTypes[token] !== EnumToken.WhitespaceTokenType && arena.dataTypes[token] !== EnumToken.CommentTokenType);
|
|
1950
2178
|
if (filteredRange.length === 1) {
|
|
1951
2179
|
success =
|
|
1952
|
-
filteredRange[0]
|
|
1953
|
-
filteredRange[0]
|
|
2180
|
+
arena.dataTypes[filteredRange[0]] === EnumToken.IdenTokenType ||
|
|
2181
|
+
arena.dataTypes[filteredRange[0]] === EnumToken.DashedIdenTokenType;
|
|
1954
2182
|
context.update(filteredRange[0]);
|
|
1955
2183
|
return {
|
|
1956
2184
|
success,
|
|
@@ -1961,10 +2189,10 @@ function matchProperty(property, context, options) {
|
|
|
1961
2189
|
errors: [],
|
|
1962
2190
|
};
|
|
1963
2191
|
}
|
|
1964
|
-
if (!mFLT.has(filteredRange[1]
|
|
1965
|
-
!mFGT.has(filteredRange[1]
|
|
1966
|
-
filteredRange[1]
|
|
1967
|
-
filteredRange[1]
|
|
2192
|
+
if (!mFLT.has(arena.dataTypes[filteredRange[1]]) &&
|
|
2193
|
+
!mFGT.has(arena.dataTypes[filteredRange[1]]) &&
|
|
2194
|
+
arena.dataTypes[filteredRange[1]] !== EnumToken.ColonTokenType &&
|
|
2195
|
+
arena.dataTypes[filteredRange[1]] !== EnumToken.DelimTokenType) {
|
|
1968
2196
|
return {
|
|
1969
2197
|
success: false,
|
|
1970
2198
|
valid: true,
|
|
@@ -1982,11 +2210,11 @@ function matchProperty(property, context, options) {
|
|
|
1982
2210
|
// match <style-feature-boolean>
|
|
1983
2211
|
// match <style-range>
|
|
1984
2212
|
const range = context.peekRange();
|
|
1985
|
-
const filteredRange = range.filter((token) => token
|
|
2213
|
+
const filteredRange = range.filter((token) => arena.dataTypes[token] !== EnumToken.WhitespaceTokenType && arena.dataTypes[token] !== EnumToken.CommentTokenType);
|
|
1986
2214
|
if (filteredRange.length === 1) {
|
|
1987
2215
|
success =
|
|
1988
|
-
filteredRange[0]
|
|
1989
|
-
filteredRange[0]
|
|
2216
|
+
arena.dataTypes[filteredRange[0]] === EnumToken.IdenTokenType ||
|
|
2217
|
+
arena.dataTypes[filteredRange[0]] === EnumToken.DashedIdenTokenType;
|
|
1990
2218
|
context.update(filteredRange[0]);
|
|
1991
2219
|
return {
|
|
1992
2220
|
success,
|
|
@@ -2009,24 +2237,26 @@ function matchProperty(property, context, options) {
|
|
|
2009
2237
|
case "url": {
|
|
2010
2238
|
const token = context.peek();
|
|
2011
2239
|
let l;
|
|
2012
|
-
|
|
2240
|
+
// inlined: arena.typeOf(token)
|
|
2241
|
+
if (arena.dataTypes[token] == EnumToken.UrlFunctionTokenDefType) {
|
|
2013
2242
|
l = 0;
|
|
2014
2243
|
let token;
|
|
2015
2244
|
while ((token = context.peek(++l))) {
|
|
2016
|
-
if (token
|
|
2245
|
+
if (arena.dataTypes[token] !== EnumToken.WhitespaceTokenType && arena.dataTypes[token] !== EnumToken.CommentTokenType) {
|
|
2017
2246
|
break;
|
|
2018
2247
|
}
|
|
2019
2248
|
}
|
|
2020
2249
|
if (token != null &&
|
|
2021
|
-
(token
|
|
2022
|
-
token
|
|
2023
|
-
token
|
|
2250
|
+
(arena.dataTypes[token] == EnumToken.StringTokenType ||
|
|
2251
|
+
arena.dataTypes[token] == EnumToken.IdenTokenType ||
|
|
2252
|
+
arena.dataTypes[token] == EnumToken.UrlTokenTokenType)) {
|
|
2024
2253
|
while ((token = context.peek(++l))) {
|
|
2025
|
-
if (token
|
|
2254
|
+
if (arena.dataTypes[token] !== EnumToken.WhitespaceTokenType && arena.dataTypes[token] !== EnumToken.CommentTokenType) {
|
|
2026
2255
|
break;
|
|
2027
2256
|
}
|
|
2028
2257
|
}
|
|
2029
|
-
|
|
2258
|
+
// inlined: arena.typeOf(token)
|
|
2259
|
+
if (arena.dataTypes[token] == EnumToken.EndParensTokenType) {
|
|
2030
2260
|
success = true;
|
|
2031
2261
|
context.update(token);
|
|
2032
2262
|
return {
|
|
@@ -2041,22 +2271,24 @@ function matchProperty(property, context, options) {
|
|
|
2041
2271
|
}
|
|
2042
2272
|
break;
|
|
2043
2273
|
}
|
|
2044
|
-
|
|
2274
|
+
// inlined: arena.typeOf(token)
|
|
2275
|
+
if (arena.dataTypes[token] != EnumToken.UrlFunctionTokenType) {
|
|
2045
2276
|
success = false;
|
|
2046
2277
|
break;
|
|
2047
2278
|
}
|
|
2048
2279
|
l = -1;
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2280
|
+
const urlTokens = arena.tokens(token);
|
|
2281
|
+
while (++l < urlTokens.length) {
|
|
2282
|
+
if (arena.dataTypes[urlTokens[l]] !== EnumToken.WhitespaceTokenType &&
|
|
2283
|
+
arena.dataTypes[urlTokens[l]] !== EnumToken.CommentTokenType) {
|
|
2052
2284
|
break;
|
|
2053
2285
|
}
|
|
2054
2286
|
}
|
|
2055
|
-
if (l <
|
|
2287
|
+
if (l < urlTokens.length) {
|
|
2056
2288
|
success =
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2289
|
+
arena.dataTypes[urlTokens[l]] == EnumToken.StringTokenType ||
|
|
2290
|
+
arena.dataTypes[urlTokens[l]] == EnumToken.IdenTokenType ||
|
|
2291
|
+
arena.dataTypes[urlTokens[l]] == EnumToken.UrlTokenTokenType;
|
|
2060
2292
|
context.next();
|
|
2061
2293
|
return {
|
|
2062
2294
|
success: true,
|
|
@@ -2070,7 +2302,8 @@ function matchProperty(property, context, options) {
|
|
|
2070
2302
|
break;
|
|
2071
2303
|
}
|
|
2072
2304
|
case "css-type": {
|
|
2073
|
-
|
|
2305
|
+
// inlined: arena.typeOf(context.peek())
|
|
2306
|
+
success = arena.dataTypes[context.peek()] == EnumToken.CssTypeTokenType;
|
|
2074
2307
|
if (success) {
|
|
2075
2308
|
context.next();
|
|
2076
2309
|
return {
|
|
@@ -2086,7 +2319,8 @@ function matchProperty(property, context, options) {
|
|
|
2086
2319
|
}
|
|
2087
2320
|
case "dashed-function": {
|
|
2088
2321
|
const token = context.peek();
|
|
2089
|
-
|
|
2322
|
+
// inlined: arena.typeOf(token)
|
|
2323
|
+
success = arena.dataTypes[token] == EnumToken.CustomFunctionTokenDefType;
|
|
2090
2324
|
if (success) {
|
|
2091
2325
|
context.next();
|
|
2092
2326
|
return {
|
|
@@ -2101,7 +2335,8 @@ function matchProperty(property, context, options) {
|
|
|
2101
2335
|
break;
|
|
2102
2336
|
}
|
|
2103
2337
|
case "block-contents":
|
|
2104
|
-
|
|
2338
|
+
// inlined: arena.typeOf(context.peek())
|
|
2339
|
+
success = arena.dataTypes[context.peek()] == EnumToken.StartParensTokenType;
|
|
2105
2340
|
if (success) {
|
|
2106
2341
|
context.next();
|
|
2107
2342
|
return {
|
|
@@ -2126,11 +2361,12 @@ function matchProperty(property, context, options) {
|
|
|
2126
2361
|
console.debug("Unknown syntax", context.peek(), property);
|
|
2127
2362
|
throw new Error(`Unexpected validation property ${property.val}`);
|
|
2128
2363
|
}
|
|
2129
|
-
return matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, property.val), context, options);
|
|
2364
|
+
return matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, property.val), context, options);
|
|
2130
2365
|
}
|
|
2131
2366
|
if (!success &&
|
|
2132
|
-
context.peek()
|
|
2133
|
-
|
|
2367
|
+
// inlined: arena.typeOf(context.peek())
|
|
2368
|
+
arena.dataTypes[context.peek()] == EnumToken.IdenTokenType &&
|
|
2369
|
+
allValues.includes(arena.strings[arena.stringValue[context.peek()]])) {
|
|
2134
2370
|
success = true;
|
|
2135
2371
|
}
|
|
2136
2372
|
if (success) {
|
|
@@ -2160,13 +2396,13 @@ function matchProperty(property, context, options) {
|
|
|
2160
2396
|
* @param options
|
|
2161
2397
|
* @returns
|
|
2162
2398
|
*/
|
|
2163
|
-
function matchRepeatableSyntax(syntax, context, options) {
|
|
2399
|
+
function matchRepeatableSyntax(arena, syntax, context, options) {
|
|
2164
2400
|
const { isRepeatable, isOptional, isMandatatoryGroup, isRepeatableAtLeastOnce, ...rest } = syntax;
|
|
2165
2401
|
let result = null;
|
|
2166
2402
|
let tmpResult;
|
|
2167
2403
|
let success = !!isRepeatable;
|
|
2168
2404
|
do {
|
|
2169
|
-
tmpResult = matchSyntax([rest], context.slice(), options);
|
|
2405
|
+
tmpResult = matchSyntax(arena, [rest], context.slice(), options);
|
|
2170
2406
|
if (tmpResult.success) {
|
|
2171
2407
|
result = tmpResult;
|
|
2172
2408
|
success = true;
|
|
@@ -2190,4 +2426,4 @@ function matchRepeatableSyntax(syntax, context, options) {
|
|
|
2190
2426
|
};
|
|
2191
2427
|
}
|
|
2192
2428
|
|
|
2193
|
-
export { createValidationContext, funcTypes, getMFInfo, isMFValue, matchAllSyntaxes, matchOccurenceSyntax, matchSelectorSyntax, trimArray };
|
|
2429
|
+
export { createValidationContext, funcTypes, getMFInfo, isMFValue, isValidDeclarationValue, matchAllSyntaxes, matchDeclarationSyntax, matchOccurenceSyntax, matchSelectorSyntax, trimArray };
|