@xano/xanoscript-language-server 11.6.0 → 11.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +3 -1
- package/lexer/literal.js +1 -1
- package/onDidChangeContent/onDidChangeContent.js +4 -4
- package/onHover/onHoverDocument.js +3 -3
- package/onSemanticCheck/highlight.js +3 -3
- package/onSemanticCheck/onSemanticCheck.js +1 -1
- package/package.json +1 -1
- package/parser/functions/controls/switchCaseFn.js +1 -0
- package/parser/functions/controls/switchFn.spec.js +14 -0
- package/parser/functions/util/utilGetRawInputFn.js +1 -1
- package/parser/functions/util/utilGetRawInputFn.spec.js +7 -0
- package/parser/functions/varFn.js +50 -2
- package/parser/functions/varFn.spec.js +122 -0
- package/parser/generic/asVariable.spec.js +76 -0
- package/parser/generic/assignableVariableAs.js +26 -3
- package/parser/generic/assignableVariableAs.spec.js +52 -0
- package/parser/generic/assignableVariableProperty.js +86 -3
- package/parser/generic/assignableVariableProperty.spec.js +77 -0
- package/parser/generic/completeEnvVariable.js +1 -1
- package/parser/generic/completeEnvVariable.spec.js +5 -0
- package/parser/generic/expressionFn.spec.js +9 -4
- package/parser/tests/function/valid_sources/ledash_ends_with.xs +1 -1
- package/parser/tests/query/valid_sources/all_zip.xs +1 -1
- package/server.js +2 -2
package/lexer/literal.js
CHANGED
|
@@ -24,7 +24,7 @@ export const SingleQuotedStringLiteral = createUniqToken({
|
|
|
24
24
|
export const FloatLiteral = createUniqToken({
|
|
25
25
|
name: "FloatLiteral",
|
|
26
26
|
label: "floating point number",
|
|
27
|
-
pattern: /-?\d+\.\d
|
|
27
|
+
pattern: /-?\d+\.\d+([eE][+-]?\d+)?/,
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
export const IntegerLiteral = createUniqToken({
|
|
@@ -62,7 +62,7 @@ export function onDidChangeContent(params, connection) {
|
|
|
62
62
|
if (!document) {
|
|
63
63
|
console.error(
|
|
64
64
|
"onDidChangeContent(): Document not found for URI:",
|
|
65
|
-
params.textDocument.uri
|
|
65
|
+
params.textDocument.uri,
|
|
66
66
|
);
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
@@ -74,7 +74,7 @@ export function onDidChangeContent(params, connection) {
|
|
|
74
74
|
const { parser, scheme } = documentCache.getOrParse(
|
|
75
75
|
document.uri,
|
|
76
76
|
document.version,
|
|
77
|
-
text
|
|
77
|
+
text,
|
|
78
78
|
);
|
|
79
79
|
|
|
80
80
|
if (parser.errors.length === 0) {
|
|
@@ -84,7 +84,7 @@ export function onDidChangeContent(params, connection) {
|
|
|
84
84
|
|
|
85
85
|
for (const error of parser.errors) {
|
|
86
86
|
console.error(
|
|
87
|
-
`onDidChangeContent(): Error parsing document: ${error.name}
|
|
87
|
+
`onDidChangeContent(): Error parsing document: ${error.name}`,
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -93,7 +93,7 @@ export function onDidChangeContent(params, connection) {
|
|
|
93
93
|
|
|
94
94
|
console.log(
|
|
95
95
|
`onDidChangeContent(): sending diagnostic (${parser.errors.length} errors) for scheme:`,
|
|
96
|
-
scheme
|
|
96
|
+
scheme,
|
|
97
97
|
);
|
|
98
98
|
|
|
99
99
|
connection.sendDiagnostics({
|
|
@@ -39,7 +39,7 @@ export function onHoverDocument(params, documents, hoverProviders = []) {
|
|
|
39
39
|
if (!document) {
|
|
40
40
|
console.error(
|
|
41
41
|
"onHover(): Document not found for URI:",
|
|
42
|
-
params.textDocument.uri
|
|
42
|
+
params.textDocument.uri,
|
|
43
43
|
);
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
@@ -51,7 +51,7 @@ export function onHoverDocument(params, documents, hoverProviders = []) {
|
|
|
51
51
|
const { lexResult, parser } = documentCache.getOrParse(
|
|
52
52
|
params.textDocument.uri,
|
|
53
53
|
document.version,
|
|
54
|
-
text
|
|
54
|
+
text,
|
|
55
55
|
);
|
|
56
56
|
|
|
57
57
|
if (lexResult.errors.length > 0) return null;
|
|
@@ -67,7 +67,7 @@ export function onHoverDocument(params, documents, hoverProviders = []) {
|
|
|
67
67
|
|
|
68
68
|
// Find the hover provider that matches the token
|
|
69
69
|
const messageProvider = hoverProviders.find((provider) =>
|
|
70
|
-
provider.isMatch(tokenIdx, tokens, parser)
|
|
70
|
+
provider.isMatch(tokenIdx, tokens, parser),
|
|
71
71
|
);
|
|
72
72
|
|
|
73
73
|
if (messageProvider) {
|
|
@@ -30,13 +30,13 @@ function higlightDefault(text, SemanticTokensBuilder) {
|
|
|
30
30
|
character,
|
|
31
31
|
token.image.length, // Length of the token
|
|
32
32
|
encodeTokenType(tokenType), // Numeric ID for the token type
|
|
33
|
-
0 // No modifiers for now
|
|
33
|
+
0, // No modifiers for now
|
|
34
34
|
);
|
|
35
35
|
} else if (tokenType === undefined) {
|
|
36
36
|
console.log(
|
|
37
37
|
`token type not mapped to a type: ${JSON.stringify(
|
|
38
|
-
token.tokenType.name
|
|
39
|
-
)}
|
|
38
|
+
token.tokenType.name,
|
|
39
|
+
)}`,
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
});
|
package/package.json
CHANGED
|
@@ -101,4 +101,18 @@ describe("switchFn", () => {
|
|
|
101
101
|
}`);
|
|
102
102
|
expect(parser.errors).to.not.be.empty;
|
|
103
103
|
});
|
|
104
|
+
|
|
105
|
+
it("switchFn accepts comments on case", () => {
|
|
106
|
+
const parser = parse(`switch ("myvar") {
|
|
107
|
+
// a comment for this case
|
|
108
|
+
case (1) break
|
|
109
|
+
|
|
110
|
+
default {
|
|
111
|
+
debug.stop {
|
|
112
|
+
value = "do something"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}`);
|
|
116
|
+
expect(parser.errors).to.be.empty;
|
|
117
|
+
});
|
|
104
118
|
});
|
|
@@ -12,7 +12,7 @@ export function utilGetRawInputFn($) {
|
|
|
12
12
|
ARGS: [
|
|
13
13
|
fnToken,
|
|
14
14
|
{
|
|
15
|
-
"encoding?": ["json", "yaml", "x-www-form-urlencoded", ""],
|
|
15
|
+
"encoding?": ["json", "none", "yaml", "x-www-form-urlencoded", ""],
|
|
16
16
|
"description?": "[string]",
|
|
17
17
|
"disabled?": "[boolean]",
|
|
18
18
|
"exclude_middleware?": "[boolean]",
|
|
@@ -19,6 +19,13 @@ describe("utilGetRawInputFn", () => {
|
|
|
19
19
|
expect(parser.errors).to.be.empty;
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
it("utilGetRawInputFn accepts none as an encoding attribute", () => {
|
|
23
|
+
const parser = parse(`get_raw_input {
|
|
24
|
+
encoding = "none"
|
|
25
|
+
} as $x4`);
|
|
26
|
+
expect(parser.errors).to.be.empty;
|
|
27
|
+
});
|
|
28
|
+
|
|
22
29
|
it("utilGetRawInputFn encoding attribute is optional", () => {
|
|
23
30
|
const parser = parse(`get_raw_input as $x4`);
|
|
24
31
|
expect(parser.errors).to.be.empty;
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { DotToken } from "../../lexer/tokens.js";
|
|
2
2
|
import { UpdateToken, VarToken } from "../../lexer/var.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ApiBaseUrlVariable,
|
|
5
|
+
BranchVariable,
|
|
6
|
+
DatasourceVariable,
|
|
7
|
+
HttpHeadersVariable,
|
|
8
|
+
RemoteHostVariable,
|
|
9
|
+
RemoteIpVariable,
|
|
10
|
+
RemotePasswordVariable,
|
|
11
|
+
RemotePortVariable,
|
|
12
|
+
RemoteUserVariable,
|
|
13
|
+
RequestAuthTokenVariable,
|
|
14
|
+
RequestMethod,
|
|
15
|
+
RequestQuerystringVariable,
|
|
16
|
+
RequestUriVariable,
|
|
17
|
+
ShortFormVariable,
|
|
18
|
+
TenantVariable,
|
|
19
|
+
WebflowVariable,
|
|
20
|
+
} from "../../lexer/variables.js";
|
|
21
|
+
import { isBlacklistedVariableName } from "../generic/assignableVariableProperty.js";
|
|
4
22
|
|
|
5
23
|
/**
|
|
6
24
|
* represent $var.x or $x, the only format accepting an assigment
|
|
@@ -15,8 +33,38 @@ export function varFn($) {
|
|
|
15
33
|
{
|
|
16
34
|
// "var $users"
|
|
17
35
|
ALT: () => {
|
|
18
|
-
|
|
36
|
+
// "$users" or env property tokens like "$http_headers"
|
|
37
|
+
// TODO: probably a good idea to add a warning when an reserved env property
|
|
38
|
+
// token is used as a variable name
|
|
39
|
+
const variable = $.OR1([
|
|
40
|
+
{ ALT: () => $.CONSUME(ShortFormVariable) },
|
|
41
|
+
{ ALT: () => $.CONSUME(ApiBaseUrlVariable) },
|
|
42
|
+
{ ALT: () => $.CONSUME(BranchVariable) },
|
|
43
|
+
{ ALT: () => $.CONSUME(DatasourceVariable) },
|
|
44
|
+
{ ALT: () => $.CONSUME(HttpHeadersVariable) },
|
|
45
|
+
{ ALT: () => $.CONSUME(RemoteHostVariable) },
|
|
46
|
+
{ ALT: () => $.CONSUME(RemoteIpVariable) },
|
|
47
|
+
{ ALT: () => $.CONSUME(RemotePasswordVariable) },
|
|
48
|
+
{ ALT: () => $.CONSUME(RemotePortVariable) },
|
|
49
|
+
{ ALT: () => $.CONSUME(RemoteUserVariable) },
|
|
50
|
+
{ ALT: () => $.CONSUME(RequestAuthTokenVariable) },
|
|
51
|
+
{ ALT: () => $.CONSUME(RequestMethod) },
|
|
52
|
+
{ ALT: () => $.CONSUME(RequestQuerystringVariable) },
|
|
53
|
+
{ ALT: () => $.CONSUME(RequestUriVariable) },
|
|
54
|
+
{ ALT: () => $.CONSUME(TenantVariable) },
|
|
55
|
+
{ ALT: () => $.CONSUME(WebflowVariable) },
|
|
56
|
+
]);
|
|
19
57
|
if (variable.image) {
|
|
58
|
+
// Check for blacklisted variable names
|
|
59
|
+
const nameWithoutPrefix = variable.image.startsWith("$")
|
|
60
|
+
? variable.image.slice(1)
|
|
61
|
+
: variable.image;
|
|
62
|
+
if (isBlacklistedVariableName(nameWithoutPrefix)) {
|
|
63
|
+
$.addInvalidValueError(
|
|
64
|
+
variable,
|
|
65
|
+
`'${variable.image}' is a reserved variable name and should not be used as a variable.`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
20
68
|
// we can directly add the variable here but
|
|
21
69
|
// not necessary for the `assignableVariableProperty` below
|
|
22
70
|
// which will add it on its own
|
|
@@ -84,6 +84,13 @@ describe("varFn", () => {
|
|
|
84
84
|
expect(parser.errors).to.be.empty;
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
+
it("varFn accept scientific notation", () => {
|
|
88
|
+
const parser = parse(` var $x1 {
|
|
89
|
+
value = 4.21E-6
|
|
90
|
+
}`);
|
|
91
|
+
expect(parser.errors).to.be.empty;
|
|
92
|
+
});
|
|
93
|
+
|
|
87
94
|
it("varFn expect a variable name", () => {
|
|
88
95
|
const parser = parse(`var {
|
|
89
96
|
value = "email"
|
|
@@ -92,6 +99,13 @@ describe("varFn", () => {
|
|
|
92
99
|
expect(parser.errors).to.not.be.empty;
|
|
93
100
|
});
|
|
94
101
|
|
|
102
|
+
it("varFn accepts an $env.$http_headers object as the value", () => {
|
|
103
|
+
const parser = parse(`var $http_headers {
|
|
104
|
+
value = $env.$http_headers
|
|
105
|
+
}`);
|
|
106
|
+
expect(parser.errors).to.be.empty;
|
|
107
|
+
});
|
|
108
|
+
|
|
95
109
|
it("varFn expect an as variable to be an identifier", () => {
|
|
96
110
|
const parser = parse(`var "user" {
|
|
97
111
|
value = "email"
|
|
@@ -107,6 +121,13 @@ describe("varFn", () => {
|
|
|
107
121
|
expect(parser.errors).to.be.empty;
|
|
108
122
|
});
|
|
109
123
|
|
|
124
|
+
it("varFn can update a value", () => {
|
|
125
|
+
const parser = parse(`var.update $http_headers.Referer {
|
|
126
|
+
value = "example.com"
|
|
127
|
+
}`);
|
|
128
|
+
expect(parser.errors).to.be.empty;
|
|
129
|
+
});
|
|
130
|
+
|
|
110
131
|
it("should allow accessing a property from an object defined in place", () => {
|
|
111
132
|
let parser = parse(`var $config {
|
|
112
133
|
value = {
|
|
@@ -170,4 +191,105 @@ describe("varFn", () => {
|
|
|
170
191
|
}`);
|
|
171
192
|
expect(parser.errors).to.be.empty;
|
|
172
193
|
});
|
|
194
|
+
|
|
195
|
+
// Blacklisted variable names - these conflict with built-in variables
|
|
196
|
+
// Some are blocked at lexer level (separate tokens), others at parser level
|
|
197
|
+
describe("blacklisted variable names", () => {
|
|
198
|
+
// These are lexed as ShortFormVariable and need explicit blacklisting
|
|
199
|
+
const shortFormBlacklisted = ["output", "db", "toolset"];
|
|
200
|
+
|
|
201
|
+
for (const name of shortFormBlacklisted) {
|
|
202
|
+
it(`rejects var $${name} as variable name (short form)`, () => {
|
|
203
|
+
const parser = parse(`var $${name} {
|
|
204
|
+
value = "test"
|
|
205
|
+
}`);
|
|
206
|
+
expect(parser.errors).to.not.be.empty;
|
|
207
|
+
expect(parser.errors[0].message).to.include("reserved");
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it(`rejects var.update $${name} as variable name (short form)`, () => {
|
|
211
|
+
const parser = parse(`var.update $${name} {
|
|
212
|
+
value = "test"
|
|
213
|
+
}`);
|
|
214
|
+
expect(parser.errors).to.not.be.empty;
|
|
215
|
+
expect(parser.errors[0].message).to.include("reserved");
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// These are separate tokens and already rejected by the parser
|
|
220
|
+
const separateTokenBlacklisted = [
|
|
221
|
+
"auth",
|
|
222
|
+
"input",
|
|
223
|
+
"env",
|
|
224
|
+
"response",
|
|
225
|
+
"error",
|
|
226
|
+
"this",
|
|
227
|
+
];
|
|
228
|
+
|
|
229
|
+
for (const name of separateTokenBlacklisted) {
|
|
230
|
+
it(`rejects var $${name} as variable name (separate token)`, () => {
|
|
231
|
+
const parser = parse(`var $${name} {
|
|
232
|
+
value = "test"
|
|
233
|
+
}`);
|
|
234
|
+
if (parser.errors.length === 0) {
|
|
235
|
+
console.log(parser.errors, name);
|
|
236
|
+
}
|
|
237
|
+
expect(parser.errors).to.not.be.empty;
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it(`rejects var.update $${name} as variable name (separate token)`, () => {
|
|
241
|
+
const parser = parse(`var.update $${name} {
|
|
242
|
+
value = "test"
|
|
243
|
+
}`);
|
|
244
|
+
expect(parser.errors).to.not.be.empty;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// $var is the LongFormVariable prefix, parser expects a dot after it
|
|
249
|
+
it("rejects var $var as variable name (long form prefix)", () => {
|
|
250
|
+
const parser = parse(`var $var {
|
|
251
|
+
value = "test"
|
|
252
|
+
}`);
|
|
253
|
+
expect(parser.errors).to.not.be.empty;
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// All blacklisted names should be rejected in long form via var.update
|
|
257
|
+
const allBlacklisted = [
|
|
258
|
+
"auth",
|
|
259
|
+
"input",
|
|
260
|
+
"env",
|
|
261
|
+
"response",
|
|
262
|
+
"output",
|
|
263
|
+
"var",
|
|
264
|
+
"db",
|
|
265
|
+
"error",
|
|
266
|
+
"toolset",
|
|
267
|
+
"this",
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
for (const name of allBlacklisted) {
|
|
271
|
+
it(`rejects var.update $var.${name} as variable name (long form)`, () => {
|
|
272
|
+
const parser = parse(`var.update $var.${name} {
|
|
273
|
+
value = "test"
|
|
274
|
+
}`);
|
|
275
|
+
expect(parser.errors).to.not.be.empty;
|
|
276
|
+
expect(parser.errors[0].message).to.include("reserved");
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Ensure valid names still work
|
|
281
|
+
it("accepts var $user as variable name", () => {
|
|
282
|
+
const parser = parse(`var $user {
|
|
283
|
+
value = "test"
|
|
284
|
+
}`);
|
|
285
|
+
expect(parser.errors).to.be.empty;
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("accepts var $my_input as variable name", () => {
|
|
289
|
+
const parser = parse(`var $my_input {
|
|
290
|
+
value = "test"
|
|
291
|
+
}`);
|
|
292
|
+
expect(parser.errors).to.be.empty;
|
|
293
|
+
});
|
|
294
|
+
});
|
|
173
295
|
});
|
|
@@ -34,4 +34,80 @@ describe("asVariable", () => {
|
|
|
34
34
|
const parser = parse("as $$clients");
|
|
35
35
|
expect(parser.errors).to.not.be.empty;
|
|
36
36
|
});
|
|
37
|
+
|
|
38
|
+
// Blacklisted variable names - these conflict with built-in variables
|
|
39
|
+
// Some are blocked at lexer level (separate tokens), others at parser level
|
|
40
|
+
describe("blacklisted variable names", () => {
|
|
41
|
+
// These are lexed as ShortFormVariable and need explicit blacklisting
|
|
42
|
+
const shortFormBlacklisted = ["output", "db", "toolset"];
|
|
43
|
+
|
|
44
|
+
for (const name of shortFormBlacklisted) {
|
|
45
|
+
it(`rejects as $${name} (short form)`, () => {
|
|
46
|
+
const parser = parse(`as $${name}`);
|
|
47
|
+
expect(parser.errors).to.not.be.empty;
|
|
48
|
+
expect(parser.errors[0].message).to.include("reserved");
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// These are separate tokens and already rejected by the parser
|
|
53
|
+
const separateTokenBlacklisted = [
|
|
54
|
+
"auth",
|
|
55
|
+
"input",
|
|
56
|
+
"env",
|
|
57
|
+
"response",
|
|
58
|
+
"error",
|
|
59
|
+
"this",
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
for (const name of separateTokenBlacklisted) {
|
|
63
|
+
it(`rejects as $${name} (separate token)`, () => {
|
|
64
|
+
const parser = parse(`as $${name}`);
|
|
65
|
+
expect(parser.errors).to.not.be.empty;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// $var is the LongFormVariable prefix, parser expects a dot after it
|
|
70
|
+
it("rejects as $var (long form prefix)", () => {
|
|
71
|
+
const parser = parse("as $var");
|
|
72
|
+
expect(parser.errors).to.not.be.empty;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// All blacklisted names should be rejected in long form ($var.name)
|
|
76
|
+
const allBlacklisted = [
|
|
77
|
+
"auth",
|
|
78
|
+
"input",
|
|
79
|
+
"env",
|
|
80
|
+
"response",
|
|
81
|
+
"output",
|
|
82
|
+
"var",
|
|
83
|
+
"db",
|
|
84
|
+
"error",
|
|
85
|
+
"toolset",
|
|
86
|
+
"this",
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
for (const name of allBlacklisted) {
|
|
90
|
+
it(`rejects as $var.${name} (long form)`, () => {
|
|
91
|
+
const parser = parse(`as $var.${name}`);
|
|
92
|
+
expect(parser.errors).to.not.be.empty;
|
|
93
|
+
expect(parser.errors[0].message).to.include("reserved");
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Ensure valid names still work
|
|
98
|
+
it("accepts as $user", () => {
|
|
99
|
+
const parser = parse("as $user");
|
|
100
|
+
expect(parser.errors).to.be.empty;
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("accepts as $my_input", () => {
|
|
104
|
+
const parser = parse("as $my_input");
|
|
105
|
+
expect(parser.errors).to.be.empty;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("accepts as $var.my_var", () => {
|
|
109
|
+
const parser = parse("as $var.my_var");
|
|
110
|
+
expect(parser.errors).to.be.empty;
|
|
111
|
+
});
|
|
112
|
+
});
|
|
37
113
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { MismatchedTokenException } from "chevrotain";
|
|
1
2
|
import { DotToken, Identifier } from "../../lexer/tokens.js";
|
|
2
|
-
import { LongFormVariable,ShortFormVariable } from "../../lexer/variables.js";
|
|
3
|
+
import { LongFormVariable, ShortFormVariable } from "../../lexer/variables.js";
|
|
4
|
+
import { isBlacklistedVariableName } from "./assignableVariableProperty.js";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* represent $var.x or $x, the only format accepting an assigment
|
|
@@ -7,11 +9,15 @@ import { LongFormVariable,ShortFormVariable } from "../../lexer/variables.js";
|
|
|
7
9
|
*/
|
|
8
10
|
export function assignableVariableAs($) {
|
|
9
11
|
return () => {
|
|
12
|
+
let variableName = "";
|
|
13
|
+
let variableToken = null;
|
|
10
14
|
$.OR([
|
|
11
15
|
// "$users"
|
|
12
16
|
{
|
|
13
17
|
ALT: () => {
|
|
14
|
-
$.CONSUME(ShortFormVariable);
|
|
18
|
+
const variable = $.CONSUME(ShortFormVariable);
|
|
19
|
+
variableName = variable.image;
|
|
20
|
+
variableToken = variable;
|
|
15
21
|
},
|
|
16
22
|
},
|
|
17
23
|
// "$var.users"
|
|
@@ -19,9 +25,26 @@ export function assignableVariableAs($) {
|
|
|
19
25
|
ALT: () => {
|
|
20
26
|
$.CONSUME(LongFormVariable);
|
|
21
27
|
$.CONSUME(DotToken);
|
|
22
|
-
$.CONSUME(Identifier);
|
|
28
|
+
const variable = $.CONSUME(Identifier);
|
|
29
|
+
variableName = `$${variable.image}`;
|
|
30
|
+
variableToken = variable;
|
|
23
31
|
},
|
|
24
32
|
},
|
|
25
33
|
]);
|
|
34
|
+
|
|
35
|
+
// Check for blacklisted variable names
|
|
36
|
+
if (variableName && variableToken) {
|
|
37
|
+
const nameWithoutPrefix = variableName.startsWith("$")
|
|
38
|
+
? variableName.slice(1)
|
|
39
|
+
: variableName;
|
|
40
|
+
if (isBlacklistedVariableName(nameWithoutPrefix)) {
|
|
41
|
+
$.SAVE_ERROR(
|
|
42
|
+
new MismatchedTokenException(
|
|
43
|
+
`'${variableName}' is a reserved variable name and cannot be used`,
|
|
44
|
+
variableToken
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
26
49
|
};
|
|
27
50
|
}
|
|
@@ -49,4 +49,56 @@ describe("assignableVariableAs", () => {
|
|
|
49
49
|
const parser = parse(`"someting"`);
|
|
50
50
|
expect(parser.errors).to.not.be.empty;
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
// Blacklisted variable names - used in loop contexts (each as $variable)
|
|
54
|
+
describe("blacklisted variable names", () => {
|
|
55
|
+
// These are lexed as ShortFormVariable and need explicit blacklisting
|
|
56
|
+
const shortFormBlacklisted = ["output", "db", "toolset"];
|
|
57
|
+
|
|
58
|
+
for (const name of shortFormBlacklisted) {
|
|
59
|
+
it(`rejects $${name} (short form)`, () => {
|
|
60
|
+
const parser = parse(`$${name}`);
|
|
61
|
+
expect(parser.errors).to.not.be.empty;
|
|
62
|
+
expect(parser.errors[0].message).to.include("reserved");
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// All blacklisted names should be rejected in long form ($var.name)
|
|
67
|
+
const allBlacklisted = [
|
|
68
|
+
"auth",
|
|
69
|
+
"input",
|
|
70
|
+
"env",
|
|
71
|
+
"response",
|
|
72
|
+
"output",
|
|
73
|
+
"var",
|
|
74
|
+
"db",
|
|
75
|
+
"error",
|
|
76
|
+
"toolset",
|
|
77
|
+
"this",
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
for (const name of allBlacklisted) {
|
|
81
|
+
it(`rejects $var.${name} (long form)`, () => {
|
|
82
|
+
const parser = parse(`$var.${name}`);
|
|
83
|
+
expect(parser.errors).to.not.be.empty;
|
|
84
|
+
expect(parser.errors[0].message).to.include("reserved");
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Ensure valid names still work
|
|
89
|
+
it("accepts $item", () => {
|
|
90
|
+
const parser = parse("$item");
|
|
91
|
+
expect(parser.errors).to.be.empty;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("accepts $i", () => {
|
|
95
|
+
const parser = parse("$i");
|
|
96
|
+
expect(parser.errors).to.be.empty;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("accepts $var.my_var", () => {
|
|
100
|
+
const parser = parse("$var.my_var");
|
|
101
|
+
expect(parser.errors).to.be.empty;
|
|
102
|
+
});
|
|
103
|
+
});
|
|
52
104
|
});
|
|
@@ -1,6 +1,50 @@
|
|
|
1
|
+
import { MismatchedTokenException } from "chevrotain";
|
|
1
2
|
import { PipeToken } from "../../lexer/control.js";
|
|
2
3
|
import { DotToken, Identifier, NewlineToken } from "../../lexer/tokens.js";
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ApiBaseUrlVariable,
|
|
6
|
+
BranchVariable,
|
|
7
|
+
DatasourceVariable,
|
|
8
|
+
HttpHeadersVariable,
|
|
9
|
+
LongFormVariable,
|
|
10
|
+
RemoteHostVariable,
|
|
11
|
+
RemoteIpVariable,
|
|
12
|
+
RemotePasswordVariable,
|
|
13
|
+
RemotePortVariable,
|
|
14
|
+
RemoteUserVariable,
|
|
15
|
+
RequestAuthTokenVariable,
|
|
16
|
+
RequestMethod,
|
|
17
|
+
RequestQuerystringVariable,
|
|
18
|
+
RequestUriVariable,
|
|
19
|
+
ShortFormVariable,
|
|
20
|
+
TenantVariable,
|
|
21
|
+
WebflowVariable,
|
|
22
|
+
} from "../../lexer/variables.js";
|
|
23
|
+
|
|
24
|
+
// Blacklisted variable names that conflict with built-in variables
|
|
25
|
+
// These names cannot be used for user-defined variables because they
|
|
26
|
+
// would conflict with their shorthand form (e.g., $var.input -> $input)
|
|
27
|
+
export const BLACKLISTED_VARIABLE_NAMES = [
|
|
28
|
+
"auth",
|
|
29
|
+
"input",
|
|
30
|
+
"env",
|
|
31
|
+
"response",
|
|
32
|
+
"output",
|
|
33
|
+
"var",
|
|
34
|
+
"db",
|
|
35
|
+
"error",
|
|
36
|
+
"toolset",
|
|
37
|
+
"this",
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if a variable name is blacklisted
|
|
42
|
+
* @param {string} name - Variable name without $ prefix
|
|
43
|
+
* @returns {boolean}
|
|
44
|
+
*/
|
|
45
|
+
export function isBlacklistedVariableName(name) {
|
|
46
|
+
return BLACKLISTED_VARIABLE_NAMES.includes(name);
|
|
47
|
+
}
|
|
4
48
|
|
|
5
49
|
/**
|
|
6
50
|
* represent $var.x or $x, the only format accepting an assigment
|
|
@@ -9,13 +53,34 @@ import { LongFormVariable, ShortFormVariable } from "../../lexer/variables.js";
|
|
|
9
53
|
export function assignableVariableProperty($) {
|
|
10
54
|
return () => {
|
|
11
55
|
let variableName = "";
|
|
56
|
+
let variableToken = null;
|
|
12
57
|
$.OR({
|
|
13
58
|
DEF: [
|
|
14
|
-
// "$users"
|
|
59
|
+
// "$users" or env property tokens like "$http_headers"
|
|
60
|
+
// TODO: probably a good idea to add a warning when an reserved env property
|
|
61
|
+
// token is used as a variable name
|
|
15
62
|
{
|
|
16
63
|
ALT: () => {
|
|
17
|
-
const variable = $.
|
|
64
|
+
const variable = $.OR1([
|
|
65
|
+
{ ALT: () => $.CONSUME(ShortFormVariable) },
|
|
66
|
+
{ ALT: () => $.CONSUME(ApiBaseUrlVariable) },
|
|
67
|
+
{ ALT: () => $.CONSUME(BranchVariable) },
|
|
68
|
+
{ ALT: () => $.CONSUME(DatasourceVariable) },
|
|
69
|
+
{ ALT: () => $.CONSUME(HttpHeadersVariable) },
|
|
70
|
+
{ ALT: () => $.CONSUME(RemoteHostVariable) },
|
|
71
|
+
{ ALT: () => $.CONSUME(RemoteIpVariable) },
|
|
72
|
+
{ ALT: () => $.CONSUME(RemotePasswordVariable) },
|
|
73
|
+
{ ALT: () => $.CONSUME(RemotePortVariable) },
|
|
74
|
+
{ ALT: () => $.CONSUME(RemoteUserVariable) },
|
|
75
|
+
{ ALT: () => $.CONSUME(RequestAuthTokenVariable) },
|
|
76
|
+
{ ALT: () => $.CONSUME(RequestMethod) },
|
|
77
|
+
{ ALT: () => $.CONSUME(RequestQuerystringVariable) },
|
|
78
|
+
{ ALT: () => $.CONSUME(RequestUriVariable) },
|
|
79
|
+
{ ALT: () => $.CONSUME(TenantVariable) },
|
|
80
|
+
{ ALT: () => $.CONSUME(WebflowVariable) },
|
|
81
|
+
]);
|
|
18
82
|
variableName = variable.image;
|
|
83
|
+
variableToken = variable;
|
|
19
84
|
},
|
|
20
85
|
},
|
|
21
86
|
// "$var.users"
|
|
@@ -25,11 +90,29 @@ export function assignableVariableProperty($) {
|
|
|
25
90
|
$.CONSUME(DotToken);
|
|
26
91
|
const variable = $.CONSUME(Identifier);
|
|
27
92
|
variableName = `$${variable.image}`;
|
|
93
|
+
variableToken = variable;
|
|
28
94
|
},
|
|
29
95
|
},
|
|
30
96
|
],
|
|
31
97
|
ERR_MSG: "expecting variable (e.g. $variable or $var.variable)",
|
|
32
98
|
});
|
|
99
|
+
|
|
100
|
+
// Check for blacklisted variable names
|
|
101
|
+
if (variableName && variableToken) {
|
|
102
|
+
// Extract the name without $ prefix for checking
|
|
103
|
+
const nameWithoutPrefix = variableName.startsWith("$")
|
|
104
|
+
? variableName.slice(1)
|
|
105
|
+
: variableName;
|
|
106
|
+
if (isBlacklistedVariableName(nameWithoutPrefix)) {
|
|
107
|
+
$.SAVE_ERROR(
|
|
108
|
+
new MismatchedTokenException(
|
|
109
|
+
`'${variableName}' is a reserved variable name and cannot be used`,
|
|
110
|
+
variableToken
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
33
116
|
$.SUBRULE($.chainedIdentifier);
|
|
34
117
|
|
|
35
118
|
$.MANY({
|
|
@@ -49,4 +49,81 @@ describe("assignableVariableProperty", () => {
|
|
|
49
49
|
const parser = parse(`$users|trim`);
|
|
50
50
|
expect(parser.errors).to.be.empty;
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
// Blacklisted variable names - these conflict with built-in variables
|
|
54
|
+
// Some are blocked at lexer level (separate tokens), others at parser level
|
|
55
|
+
describe("blacklisted variable names", () => {
|
|
56
|
+
// These are lexed as ShortFormVariable and need explicit blacklisting
|
|
57
|
+
const shortFormBlacklisted = ["output", "db", "toolset"];
|
|
58
|
+
|
|
59
|
+
for (const name of shortFormBlacklisted) {
|
|
60
|
+
it(`rejects $${name} as assignable variable (short form)`, () => {
|
|
61
|
+
const parser = parse(`$${name}`);
|
|
62
|
+
expect(parser.errors).to.not.be.empty;
|
|
63
|
+
expect(parser.errors[0].message).to.include("reserved");
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// These are separate tokens and already rejected by the parser
|
|
68
|
+
// (not in the OR alternatives of assignableVariableProperty)
|
|
69
|
+
const separateTokenBlacklisted = [
|
|
70
|
+
"auth",
|
|
71
|
+
"input",
|
|
72
|
+
"env",
|
|
73
|
+
"response",
|
|
74
|
+
"error",
|
|
75
|
+
"this",
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
for (const name of separateTokenBlacklisted) {
|
|
79
|
+
it(`rejects $${name} as assignable variable (separate token)`, () => {
|
|
80
|
+
const parser = parse(`$${name}`);
|
|
81
|
+
expect(parser.errors).to.not.be.empty;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// $var is the LongFormVariable prefix, parser expects a dot after it
|
|
86
|
+
it("rejects $var as assignable variable (long form prefix)", () => {
|
|
87
|
+
const parser = parse("$var");
|
|
88
|
+
expect(parser.errors).to.not.be.empty;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// All blacklisted names should be rejected in long form ($var.name)
|
|
92
|
+
const allBlacklisted = [
|
|
93
|
+
"auth",
|
|
94
|
+
"input",
|
|
95
|
+
"env",
|
|
96
|
+
"response",
|
|
97
|
+
"output",
|
|
98
|
+
"var",
|
|
99
|
+
"db",
|
|
100
|
+
"error",
|
|
101
|
+
"toolset",
|
|
102
|
+
"this",
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
for (const name of allBlacklisted) {
|
|
106
|
+
it(`rejects $var.${name} as assignable variable (long form)`, () => {
|
|
107
|
+
const parser = parse(`$var.${name}`);
|
|
108
|
+
expect(parser.errors).to.not.be.empty;
|
|
109
|
+
expect(parser.errors[0].message).to.include("reserved");
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Ensure valid names still work
|
|
114
|
+
it("accepts $user as assignable variable", () => {
|
|
115
|
+
const parser = parse("$user");
|
|
116
|
+
expect(parser.errors).to.be.empty;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("accepts $my_input as assignable variable", () => {
|
|
120
|
+
const parser = parse("$my_input");
|
|
121
|
+
expect(parser.errors).to.be.empty;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("accepts $var.my_var as assignable variable", () => {
|
|
125
|
+
const parser = parse("$var.my_var");
|
|
126
|
+
expect(parser.errors).to.be.empty;
|
|
127
|
+
});
|
|
128
|
+
});
|
|
52
129
|
});
|
|
@@ -62,6 +62,11 @@ describe("completeEnvVariable", () => {
|
|
|
62
62
|
expect(parser.errors).to.be.empty;
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
+
it("completeEnvVariable accepts $http_headers without property access", () => {
|
|
66
|
+
const parser = parse("$env.$http_headers");
|
|
67
|
+
expect(parser.errors).to.be.empty;
|
|
68
|
+
});
|
|
69
|
+
|
|
65
70
|
it("completeEnvVariable warn when using env variable starting with $", () => {
|
|
66
71
|
const parser = parse("$env.$my_custom_variable");
|
|
67
72
|
expect(parser.errors).to.be.empty;
|
|
@@ -187,6 +187,11 @@ describe("expressionFn", () => {
|
|
|
187
187
|
expect(parser.errors).to.be.empty;
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
+
it("expressionFn can be a scientific notation", () => {
|
|
191
|
+
const parser = parse("4.21E-6");
|
|
192
|
+
expect(parser.errors).to.be.empty;
|
|
193
|
+
});
|
|
194
|
+
|
|
190
195
|
it("expressionFn accepts a JSON", () => {
|
|
191
196
|
const parser = parse(`[
|
|
192
197
|
{
|
|
@@ -270,7 +275,7 @@ describe("expressionFn", () => {
|
|
|
270
275
|
|
|
271
276
|
it("expressionFn accepts a rich boolean test expression", () => {
|
|
272
277
|
const parser = parse(
|
|
273
|
-
`($event_type == "app_mention") || (($event_type == "message") && ($channel_type == "im")) || $thread_replies.ai_bot_thread
|
|
278
|
+
`($event_type == "app_mention") || (($event_type == "message") && ($channel_type == "im")) || $thread_replies.ai_bot_thread`,
|
|
274
279
|
);
|
|
275
280
|
expect(parser.errors).to.be.empty;
|
|
276
281
|
});
|
|
@@ -323,7 +328,7 @@ describe("expressionFn", () => {
|
|
|
323
328
|
|
|
324
329
|
it("expressionFn allow concat operator", () => {
|
|
325
330
|
const parser = parse(
|
|
326
|
-
`"Given the conversation history and the latest message:\\n\\"" ~ $latestMessage ~ "\\"\\n\\nWho should act next? Or should we FINISH? Select one of: " ~ ($memberOptions|join:", ") ~ "."
|
|
331
|
+
`"Given the conversation history and the latest message:\\n\\"" ~ $latestMessage ~ "\\"\\n\\nWho should act next? Or should we FINISH? Select one of: " ~ ($memberOptions|join:", ") ~ "."`,
|
|
327
332
|
);
|
|
328
333
|
expect(parser.errors).to.be.empty;
|
|
329
334
|
});
|
|
@@ -374,14 +379,14 @@ describe("expressionFn", () => {
|
|
|
374
379
|
|
|
375
380
|
it("expressionFn should accept chained filters in parenthesis", () => {
|
|
376
381
|
const parser = parse(
|
|
377
|
-
`(now|to_timestamp|add:2:2|add:2|transform_timestamp:"24 hours ago":"UTC")
|
|
382
|
+
`(now|to_timestamp|add:2:2|add:2|transform_timestamp:"24 hours ago":"UTC")`,
|
|
378
383
|
);
|
|
379
384
|
expect(parser.errors).to.be.empty;
|
|
380
385
|
});
|
|
381
386
|
|
|
382
387
|
it("expressionFn should accept chained filters with comparison", () => {
|
|
383
388
|
const parser = parse(
|
|
384
|
-
`(now|to_timestamp|transform_timestamp:"24 hours ago":"UTC") > (335|add:2)
|
|
389
|
+
`(now|to_timestamp|transform_timestamp:"24 hours ago":"UTC") > (335|add:2)`,
|
|
385
390
|
);
|
|
386
391
|
expect(parser.errors).to.be.empty;
|
|
387
392
|
});
|
|
@@ -75,7 +75,7 @@ function "ledash/ends_with" {
|
|
|
75
75
|
each as $index {
|
|
76
76
|
conditional {
|
|
77
77
|
description = "compare every element using position as an offset on the string"
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
if (($text|get:$position - $index - 1:null) !== ($target|get:($target|count) - $index - 1:null)) {
|
|
80
80
|
return {
|
|
81
81
|
value = false
|
package/server.js
CHANGED
|
@@ -44,10 +44,10 @@ connection.onInitialize(() => {
|
|
|
44
44
|
connection.onHover((params) => onHover(params, documents));
|
|
45
45
|
connection.onCompletion((params) => onCompletion(params, documents));
|
|
46
46
|
connection.onRequest("textDocument/semanticTokens/full", (params) =>
|
|
47
|
-
onSemanticCheck(params, documents, SemanticTokensBuilder)
|
|
47
|
+
onSemanticCheck(params, documents, SemanticTokensBuilder),
|
|
48
48
|
);
|
|
49
49
|
documents.onDidChangeContent((params) =>
|
|
50
|
-
onDidChangeContent(params, connection)
|
|
50
|
+
onDidChangeContent(params, connection),
|
|
51
51
|
);
|
|
52
52
|
connection.onDidOpenTextDocument((params) => {
|
|
53
53
|
console.log("Document opened:", params.textDocument.uri);
|