@xano/xanoscript-language-server 11.12.0 → 11.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.claude/memory/feedback_no_git.md +11 -0
  2. package/.claude/settings.local.json +13 -28
  3. package/lexer/cast.js +3 -3
  4. package/lexer/control.js +0 -2
  5. package/lexer/literal.js +2 -2
  6. package/lexer/security.js +2 -2
  7. package/package.json +1 -1
  8. package/parser/attributes/columnDefaultValueAttribute.js +10 -3
  9. package/parser/attributes/inputFilterFn.js +11 -4
  10. package/parser/clauses/flexibleStringClause.js +2 -2
  11. package/parser/clauses/nakedStackFn.js +43 -36
  12. package/parser/clauses/nakedStackFn.spec.js +10 -0
  13. package/parser/clauses/responseClause.spec.js +5 -0
  14. package/parser/definitions/columnDefinition.js +7 -2
  15. package/parser/functions/array/arrayNoValueAs.js +1 -1
  16. package/parser/functions/array/arrayPopFn.js +1 -3
  17. package/parser/functions/controls/forEachFn.spec.js +8 -0
  18. package/parser/functions/controls/preconditionFn.js +3 -0
  19. package/parser/functions/db/dbExternalDirectQueryFn.js +1 -0
  20. package/parser/functions/db/dbQueryFn.spec.js +31 -0
  21. package/parser/functions/schema/schemaParseConstantFn.js +11 -10
  22. package/parser/functions/varFn.js +14 -2
  23. package/parser/functions/varFn.spec.js +20 -12
  24. package/parser/generic/asVariable.spec.js +12 -8
  25. package/parser/generic/assignableVariableAs.js +50 -11
  26. package/parser/generic/assignableVariableAs.spec.js +29 -7
  27. package/parser/generic/assignableVariableProperty.js +22 -10
  28. package/parser/generic/assignableVariableProperty.spec.js +21 -12
  29. package/parser/generic/expressionFn.js +9 -2
  30. package/parser/generic/expressionFn.spec.js +5 -0
  31. package/parser/generic/filterNames.js +9 -0
  32. package/parser/multidoc.js +38 -17
  33. package/parser/multidoc.spec.js +7 -1
  34. package/parser/query_parser.js +11 -3
  35. package/parser/query_parser.spec.js +0 -3
  36. package/parser/tests/function/function_parser.spec.js +4 -4
  37. package/parser/tests/multidoc/multidoc_parser.spec.js +55 -0
  38. package/parser/tests/multidoc/valid_sources/function_stack.xs +130603 -0
  39. package/parser/tests/query/query_parser.spec.js +3 -3
  40. package/parser/tool_parser.js +12 -3
  41. package/parser/tool_parser.spec.js +19 -6
@@ -44,8 +44,9 @@ describe("asVariable", () => {
44
44
  for (const name of shortFormBlacklisted) {
45
45
  it(`rejects as $${name} (short form)`, () => {
46
46
  const parser = parse(`as $${name}`);
47
- expect(parser.errors).to.not.be.empty;
48
- expect(parser.errors[0].message).to.include("reserved");
47
+ expect(parser.errors).to.be.empty;
48
+ expect(parser.warnings).to.not.be.empty;
49
+ expect(parser.warnings[0].message).to.include("reserved");
49
50
  });
50
51
  }
51
52
 
@@ -62,14 +63,16 @@ describe("asVariable", () => {
62
63
  for (const name of separateTokenBlacklisted) {
63
64
  it(`rejects as $${name} (separate token)`, () => {
64
65
  const parser = parse(`as $${name}`);
65
- expect(parser.errors).to.not.be.empty;
66
+ expect(parser.warnings).to.not.be.empty;
66
67
  });
67
68
  }
68
69
 
69
70
  // $var is the LongFormVariable prefix, parser expects a dot after it
71
+ // FIXME: shoud be a warning, not an error, since it's still a valid variable name (albeit confusing)
70
72
  it("rejects as $var (long form prefix)", () => {
71
73
  const parser = parse("as $var");
72
- expect(parser.errors).to.not.be.empty;
74
+ expect(parser.errors).to.be.empty;
75
+ expect(parser.warnings).to.not.be.empty;
73
76
  });
74
77
 
75
78
  // All blacklisted names should be rejected in long form ($var.name)
@@ -89,25 +92,26 @@ describe("asVariable", () => {
89
92
  for (const name of allBlacklisted) {
90
93
  it(`rejects as $var.${name} (long form)`, () => {
91
94
  const parser = parse(`as $var.${name}`);
92
- expect(parser.errors).to.not.be.empty;
93
- expect(parser.errors[0].message).to.include("reserved");
95
+ expect(parser.warnings).to.not.be.empty;
96
+ expect(parser.warnings[0].message).to.include("reserved");
94
97
  });
95
98
  }
96
99
 
97
100
  // Ensure valid names still work
98
101
  it("accepts as $user", () => {
99
102
  const parser = parse("as $user");
100
- expect(parser.errors).to.be.empty;
103
+ expect(parser.warnings).to.be.empty;
101
104
  });
102
105
 
103
106
  it("accepts as $my_input", () => {
104
107
  const parser = parse("as $my_input");
105
108
  expect(parser.errors).to.be.empty;
109
+ expect(parser.warnings).to.be.empty;
106
110
  });
107
111
 
108
112
  it("accepts as $var.my_var", () => {
109
113
  const parser = parse("as $var.my_var");
110
- expect(parser.errors).to.be.empty;
114
+ expect(parser.warnings).to.be.empty;
111
115
  });
112
116
  });
113
117
  });
@@ -1,6 +1,12 @@
1
- import { MismatchedTokenException } from "chevrotain";
2
1
  import { DotToken, Identifier } from "../../lexer/tokens.js";
3
- import { LongFormVariable, ShortFormVariable } from "../../lexer/variables.js";
2
+ import {
3
+ AuthVariable,
4
+ EnvVariable,
5
+ ErrorVariable,
6
+ InputVariable,
7
+ LongFormVariable,
8
+ ShortFormVariable,
9
+ } from "../../lexer/variables.js";
4
10
  import { isBlacklistedVariableName } from "./assignableVariableProperty.js";
5
11
 
6
12
  /**
@@ -23,10 +29,45 @@ export function assignableVariableAs($) {
23
29
  // "$var.users"
24
30
  {
25
31
  ALT: () => {
26
- $.CONSUME(LongFormVariable);
27
- $.CONSUME(DotToken);
28
- const variable = $.CONSUME(Identifier);
29
- variableName = `$${variable.image}`;
32
+ const variable = $.CONSUME(LongFormVariable);
33
+ variableName = variable.image;
34
+ variableToken = variable;
35
+
36
+ // Handle optional property access, e.g., "$var.users" because "$var" is a valid
37
+ // variable name even if it's not recommended and confusing
38
+ $.OPTION(() => {
39
+ $.CONSUME(DotToken);
40
+ const variable = $.CONSUME(Identifier);
41
+ variableName = `$${variable.image}`;
42
+ variableToken = variable;
43
+ });
44
+ },
45
+ },
46
+ {
47
+ ALT: () => {
48
+ const variable = $.CONSUME(EnvVariable);
49
+ variableName = variable.image;
50
+ variableToken = variable;
51
+ },
52
+ },
53
+ {
54
+ ALT: () => {
55
+ const variable = $.CONSUME(AuthVariable);
56
+ variableName = variable.image;
57
+ variableToken = variable;
58
+ },
59
+ },
60
+ {
61
+ ALT: () => {
62
+ const variable = $.CONSUME(InputVariable);
63
+ variableName = variable.image;
64
+ variableToken = variable;
65
+ },
66
+ },
67
+ {
68
+ ALT: () => {
69
+ const variable = $.CONSUME(ErrorVariable);
70
+ variableName = variable.image;
30
71
  variableToken = variable;
31
72
  },
32
73
  },
@@ -38,11 +79,9 @@ export function assignableVariableAs($) {
38
79
  ? variableName.slice(1)
39
80
  : variableName;
40
81
  if (isBlacklistedVariableName(nameWithoutPrefix)) {
41
- $.SAVE_ERROR(
42
- new MismatchedTokenException(
43
- `'${variableName}' is a reserved variable name and cannot be used`,
44
- variableToken
45
- )
82
+ $.addWarning(
83
+ `'${variableToken.image}' is a reserved variable name and should not be used as a variable.`,
84
+ variableToken,
46
85
  );
47
86
  }
48
87
  $.addVariable(variableName, "unknown", variableToken);
@@ -25,6 +25,12 @@ describe("assignableVariableAs", () => {
25
25
  expect(parser.errors).to.not.be.empty;
26
26
  });
27
27
 
28
+ it("assignableVariableAs should warn on $var reserved variable names", () => {
29
+ const parser = parse("$var");
30
+ expect(parser.errors).to.be.empty;
31
+ expect(parser.warnings).to.not.be.empty;
32
+ });
33
+
28
34
  it("assignableVariableAs cannot be a short named variable with sub props", () => {
29
35
  const parser = parse("$users.x.y[1].z");
30
36
  expect(parser.errors).to.not.be.empty;
@@ -53,13 +59,28 @@ describe("assignableVariableAs", () => {
53
59
  // Blacklisted variable names - used in loop contexts (each as $variable)
54
60
  describe("blacklisted variable names", () => {
55
61
  // These are lexed as ShortFormVariable and need explicit blacklisting
56
- const shortFormBlacklisted = ["output", "db", "toolset"];
62
+ const shortFormBlacklisted = [
63
+ "output",
64
+ "db",
65
+ "toolset",
66
+ "auth",
67
+ "input",
68
+ "env",
69
+ "response",
70
+ "output",
71
+ "var",
72
+ "db",
73
+ "error",
74
+ "toolset",
75
+ "this",
76
+ ];
57
77
 
58
78
  for (const name of shortFormBlacklisted) {
59
- it(`rejects $${name} (short form)`, () => {
79
+ it(`warns on $${name} (short form)`, () => {
60
80
  const parser = parse(`$${name}`);
61
- expect(parser.errors).to.not.be.empty;
62
- expect(parser.errors[0].message).to.include("reserved");
81
+ expect(parser.errors).to.be.empty;
82
+ expect(parser.warnings).to.not.be.empty;
83
+ expect(parser.warnings[0].message).to.include("reserved");
63
84
  });
64
85
  }
65
86
 
@@ -78,10 +99,11 @@ describe("assignableVariableAs", () => {
78
99
  ];
79
100
 
80
101
  for (const name of allBlacklisted) {
81
- it(`rejects $var.${name} (long form)`, () => {
102
+ it(`warns on $var.${name} (long form)`, () => {
82
103
  const parser = parse(`$var.${name}`);
83
- expect(parser.errors).to.not.be.empty;
84
- expect(parser.errors[0].message).to.include("reserved");
104
+ expect(parser.errors).to.be.empty;
105
+ expect(parser.warnings).to.not.be.empty;
106
+ expect(parser.warnings[0].message).to.include("reserved");
85
107
  });
86
108
  }
87
109
 
@@ -1,11 +1,14 @@
1
- import { MismatchedTokenException } from "chevrotain";
2
1
  import { PipeToken } from "../../lexer/control.js";
3
2
  import { DotToken, Identifier, NewlineToken } from "../../lexer/tokens.js";
4
3
  import {
5
4
  ApiBaseUrlVariable,
5
+ AuthVariable,
6
6
  BranchVariable,
7
7
  DatasourceVariable,
8
+ EnvVariable,
9
+ ErrorVariable,
8
10
  HttpHeadersVariable,
11
+ InputVariable,
9
12
  LongFormVariable,
10
13
  RemoteHostVariable,
11
14
  RemoteIpVariable,
@@ -78,6 +81,11 @@ export function assignableVariableProperty($) {
78
81
  { ALT: () => $.CONSUME(RequestUriVariable) },
79
82
  { ALT: () => $.CONSUME(TenantVariable) },
80
83
  { ALT: () => $.CONSUME(WebflowVariable) },
84
+ // Not recommended but still valid
85
+ { ALT: () => $.CONSUME(EnvVariable) },
86
+ { ALT: () => $.CONSUME(AuthVariable) },
87
+ { ALT: () => $.CONSUME(InputVariable) },
88
+ { ALT: () => $.CONSUME(ErrorVariable) },
81
89
  ]);
82
90
  variableName = variable.image;
83
91
  variableToken = variable;
@@ -86,11 +94,17 @@ export function assignableVariableProperty($) {
86
94
  // "$var.users"
87
95
  {
88
96
  ALT: () => {
89
- $.CONSUME(LongFormVariable);
90
- $.CONSUME(DotToken);
91
- const variable = $.CONSUME(Identifier);
92
- variableName = `$${variable.image}`;
97
+ const variable = $.CONSUME(LongFormVariable);
98
+ variableName = variable.image;
93
99
  variableToken = variable;
100
+
101
+ // because we want to allow "$var" we need to optionally consume a dot and an identifier
102
+ $.OPTION(() => {
103
+ $.CONSUME(DotToken);
104
+ const variable = $.CONSUME(Identifier);
105
+ variableName = `$${variable.image}`;
106
+ variableToken = variable;
107
+ });
94
108
  },
95
109
  },
96
110
  ],
@@ -104,11 +118,9 @@ export function assignableVariableProperty($) {
104
118
  ? variableName.slice(1)
105
119
  : variableName;
106
120
  if (isBlacklistedVariableName(nameWithoutPrefix)) {
107
- $.SAVE_ERROR(
108
- new MismatchedTokenException(
109
- `'${variableName}' is a reserved variable name and cannot be used`,
110
- variableToken
111
- )
121
+ $.addWarning(
122
+ `'${variableName}' is a reserved variable name and should not be used`,
123
+ variableToken,
112
124
  );
113
125
  }
114
126
  }
@@ -30,17 +30,21 @@ describe("assignableVariableProperty", () => {
30
30
  expect(parser.errors).to.be.empty;
31
31
  });
32
32
 
33
- it("assignableVariableProperty cannot be an env variable", () => {
33
+ it("assignableVariableProperty should warn on $env variable", () => {
34
34
  const parser = parse("$env.my_api_key");
35
- expect(parser.errors).to.not.be.empty;
35
+ expect(parser.errors).to.be.empty;
36
+ expect(parser.warnings).to.not.be.empty;
37
+ expect(parser.warnings[0].message).to.include("reserved");
36
38
  });
37
39
 
38
- it("assignableVariableProperty cannot be an input variable", () => {
40
+ it("assignableVariableProperty should warn on $input variable", () => {
39
41
  const parser = parse("$input.remote_ip");
40
- expect(parser.errors).to.not.be.empty;
42
+ expect(parser.errors).to.be.empty;
43
+ expect(parser.warnings).to.not.be.empty;
44
+ expect(parser.warnings[0].message).to.include("reserved");
41
45
  });
42
46
 
43
- it("assignableVariableProperty cannot be a string", () => {
47
+ it("assignableVariableProperty cannot be an indentifier", () => {
44
48
  const parser = parse(`"someting"`);
45
49
  expect(parser.errors).to.not.be.empty;
46
50
  });
@@ -59,8 +63,9 @@ describe("assignableVariableProperty", () => {
59
63
  for (const name of shortFormBlacklisted) {
60
64
  it(`rejects $${name} as assignable variable (short form)`, () => {
61
65
  const parser = parse(`$${name}`);
62
- expect(parser.errors).to.not.be.empty;
63
- expect(parser.errors[0].message).to.include("reserved");
66
+ expect(parser.errors).to.be.empty;
67
+ expect(parser.warnings).to.not.be.empty;
68
+ expect(parser.warnings[0].message).to.include("reserved");
64
69
  });
65
70
  }
66
71
 
@@ -78,14 +83,17 @@ describe("assignableVariableProperty", () => {
78
83
  for (const name of separateTokenBlacklisted) {
79
84
  it(`rejects $${name} as assignable variable (separate token)`, () => {
80
85
  const parser = parse(`$${name}`);
81
- expect(parser.errors).to.not.be.empty;
86
+ expect(parser.errors).to.be.empty;
87
+ expect(parser.warnings).to.not.be.empty;
88
+ expect(parser.warnings[0].message).to.include("reserved");
82
89
  });
83
90
  }
84
91
 
85
92
  // $var is the LongFormVariable prefix, parser expects a dot after it
86
- it("rejects $var as assignable variable (long form prefix)", () => {
93
+ it("warns when using $var as assignable variable (long form prefix)", () => {
87
94
  const parser = parse("$var");
88
- expect(parser.errors).to.not.be.empty;
95
+ expect(parser.errors).to.be.empty;
96
+ expect(parser.warnings).to.not.be.empty;
89
97
  });
90
98
 
91
99
  // All blacklisted names should be rejected in long form ($var.name)
@@ -105,8 +113,9 @@ describe("assignableVariableProperty", () => {
105
113
  for (const name of allBlacklisted) {
106
114
  it(`rejects $var.${name} as assignable variable (long form)`, () => {
107
115
  const parser = parse(`$var.${name}`);
108
- expect(parser.errors).to.not.be.empty;
109
- expect(parser.errors[0].message).to.include("reserved");
116
+ expect(parser.errors).to.be.empty;
117
+ expect(parser.warnings).to.not.be.empty;
118
+ expect(parser.warnings[0].message).to.include("reserved");
110
119
  });
111
120
  }
112
121
 
@@ -366,8 +366,15 @@ export function simpleExpressionFn($) {
366
366
  // Group 1: Literals (fast path - most common, distinct tokens)
367
367
  { ALT: () => $.CONSUME(StringLiteral) },
368
368
  { ALT: () => $.CONSUME(SingleQuotedStringLiteral) },
369
- { ALT: () => $.CONSUME(IntegerLiteral) },
370
- { ALT: () => $.CONSUME(FloatLiteral) },
369
+ {
370
+ ALT: () => {
371
+ $.OPTION(() => $.CONSUME(Minus));
372
+ $.OR1([
373
+ { ALT: () => $.CONSUME(IntegerLiteral) },
374
+ { ALT: () => $.CONSUME(FloatLiteral) },
375
+ ]);
376
+ },
377
+ },
371
378
  { ALT: () => $.CONSUME(TrueToken) },
372
379
  { ALT: () => $.CONSUME(FalseToken) },
373
380
  { ALT: () => $.CONSUME(NullToken) },
@@ -570,6 +570,11 @@ describe("expressionFn", () => {
570
570
  expect(parser.errors).to.be.empty;
571
571
  });
572
572
 
573
+ it("expressionFn accept parenthesis for priority for math", () => {
574
+ const parser = parse(`(1+2+4)*5-2`);
575
+ expect(parser.errors).to.be.empty;
576
+ });
577
+
573
578
  it("expressionFn accept math with variable", () => {
574
579
  const parser = parse(`2 * $input.a + 2 / $input.b - 2`);
575
580
  expect(parser.errors).to.be.empty;
@@ -286,6 +286,15 @@ export const filterNames = [
286
286
  "sql_esc",
287
287
  "sql_alias",
288
288
  "is_uuid",
289
+ "count_distinct",
290
+ "median",
291
+ "to_list",
292
+ "to_list_asc",
293
+ "to_list_desc",
294
+ "to_distinct_list",
295
+ "to_distinct_list_asc",
296
+ "to_distinct_list_desc",
297
+ "lambda",
289
298
  ];
290
299
 
291
300
  // List of input filters allowed for each input type
@@ -6,6 +6,7 @@ import { validateVariables } from "./variableValidator.js";
6
6
 
7
7
  const SEPARATOR = "\n---\n";
8
8
  const SEPARATOR_LENGTH = 5;
9
+ const SEPARATOR_NEWLINES = 2; // number of \n characters in SEPARATOR
9
10
 
10
11
  /**
11
12
  * Find the segment that contains the given global offset.
@@ -38,6 +39,23 @@ export function findSegmentAtOffset(parserResult, offset) {
38
39
  return null;
39
40
  }
40
41
 
42
+ /**
43
+ * Snapshot a Chevrotain token (or minimal token-like object) into a plain object.
44
+ * @param {Object|null} token
45
+ * @returns {Object|null}
46
+ */
47
+ function snapshotToken(token) {
48
+ if (!token) return null;
49
+ return {
50
+ startOffset: token.startOffset,
51
+ endOffset: token.endOffset,
52
+ startLine: token.startLine,
53
+ startColumn: token.startColumn,
54
+ image: token.image,
55
+ tokenTypeName: token.tokenType?.name,
56
+ };
57
+ }
58
+
41
59
  /**
42
60
  * Snapshot parser state into a plain object.
43
61
  * Must be called immediately after xanoscriptParser() before parsing next segment,
@@ -49,28 +67,22 @@ function snapshotParser(parser) {
49
67
  return {
50
68
  errors: parser.errors.map((e) => ({
51
69
  message: e.message,
52
- token: e.token
53
- ? { startOffset: e.token.startOffset, endOffset: e.token.endOffset }
54
- : null,
70
+ token: snapshotToken(e.token),
71
+ previousToken: snapshotToken(e.previousToken),
55
72
  })),
56
73
  warnings: parser.warnings.map((w) => ({
57
74
  message: w.message,
58
- token: w.token
59
- ? { startOffset: w.token.startOffset, endOffset: w.token.endOffset }
60
- : null,
75
+ token: snapshotToken(w.token),
61
76
  })),
62
77
  informations: parser.informations.map((i) => ({
63
78
  message: i.message,
64
- token: i.token
65
- ? { startOffset: i.token.startOffset, endOffset: i.token.endOffset }
66
- : null,
79
+ token: snapshotToken(i.token),
67
80
  })),
68
81
  hints: parser.hints.map((h) => ({
69
82
  message: h.message,
70
- token: h.token
71
- ? { startOffset: h.token.startOffset, endOffset: h.token.endOffset }
72
- : null,
83
+ token: snapshotToken(h.token),
73
84
  })),
85
+ sectionStack: [...parser.sectionStack],
74
86
  __symbolTable: parser.__symbolTable
75
87
  ? {
76
88
  input: { ...parser.__symbolTable.input },
@@ -94,17 +106,24 @@ function snapshotParser(parser) {
94
106
  * Apply a global offset to all position-bearing fields in a parser snapshot.
95
107
  * @param {Object} snapshot - The parser state snapshot
96
108
  * @param {number} globalOffset - The character offset to add
109
+ * @param {number} lineOffset - The line number offset to add
97
110
  */
98
- function offsetResult(snapshot, globalOffset) {
111
+ function offsetResult(snapshot, globalOffset, lineOffset) {
99
112
  if (globalOffset === 0) return;
100
113
 
101
114
  const offsetToken = (token) => {
102
115
  if (!token) return;
103
116
  token.startOffset += globalOffset;
104
117
  token.endOffset += globalOffset;
118
+ if (token.startLine != null) {
119
+ token.startLine += lineOffset;
120
+ }
105
121
  };
106
122
 
107
- for (const err of snapshot.errors) offsetToken(err.token);
123
+ for (const err of snapshot.errors) {
124
+ offsetToken(err.token);
125
+ offsetToken(err.previousToken);
126
+ }
108
127
  for (const warn of snapshot.warnings) offsetToken(warn.token);
109
128
  for (const info of snapshot.informations) offsetToken(info.token);
110
129
  for (const hint of snapshot.hints) offsetToken(hint.token);
@@ -161,6 +180,7 @@ export function multidocParser(text) {
161
180
  const segments = text.split(SEPARATOR);
162
181
  const results = [];
163
182
  let globalOffset = 0;
183
+ let lineOffset = 0;
164
184
 
165
185
  for (const segmentText of segments) {
166
186
  const parser = xanoscriptParser(segmentText);
@@ -199,8 +219,9 @@ export function multidocParser(text) {
199
219
  : null;
200
220
  // Deep-copy the snapshot before offsetResult mutates it (needed for hover providers)
201
221
  const localSnapshot = JSON.parse(JSON.stringify(snapshot));
202
- results.push({ snapshot, localSnapshot, segmentText, segmentSymbolTable, globalOffset });
222
+ results.push({ snapshot, localSnapshot, segmentText, segmentSymbolTable, globalOffset, lineOffset });
203
223
  globalOffset += segmentText.length + SEPARATOR_LENGTH;
224
+ lineOffset += (segmentText.match(/\n/g) || []).length + SEPARATOR_NEWLINES;
204
225
  }
205
226
 
206
227
  // For now, merge without offsetting (next task)
@@ -221,8 +242,8 @@ export function multidocParser(text) {
221
242
  segmentCount: segments.length,
222
243
  };
223
244
 
224
- for (const { snapshot, globalOffset } of results) {
225
- offsetResult(snapshot, globalOffset);
245
+ for (const { snapshot, globalOffset, lineOffset } of results) {
246
+ offsetResult(snapshot, globalOffset, lineOffset);
226
247
  merged.errors.push(...snapshot.errors);
227
248
  merged.warnings.push(...snapshot.warnings);
228
249
  merged.informations.push(...snapshot.informations);
@@ -299,6 +299,10 @@ function bar {
299
299
  var.update $x {
300
300
  value = 2
301
301
  }
302
+
303
+ var $y {
304
+ value = 2
305
+ }
302
306
  }
303
307
 
304
308
  response = null
@@ -691,7 +695,9 @@ function bar {
691
695
  // The error must be within seg3's global range
692
696
  const error = result.errors[0];
693
697
  expect(error.token.startOffset).to.be.at.least(expectedSeg3Start);
694
- expect(error.token.startOffset).to.be.lessThan(expectedSeg3Start + seg3.length);
698
+ expect(error.token.startOffset).to.be.lessThan(
699
+ expectedSeg3Start + seg3.length,
700
+ );
695
701
  });
696
702
 
697
703
  it("should isolate errors — bad seg1 should not prevent seg2 from parsing", () => {
@@ -30,6 +30,7 @@ export function queryDeclaration($) {
30
30
  let hasTags = false;
31
31
  let hasApiGroup = false;
32
32
  let hasResponseType = false;
33
+ let responseType = "standard";
33
34
 
34
35
  const testNames = [];
35
36
 
@@ -80,8 +81,8 @@ export function queryDeclaration($) {
80
81
  $.CONSUME(ResponseTypeToken);
81
82
  $.CONSUME8(EqualToken);
82
83
  const valueToken = $.CONSUME2(StringLiteral);
83
- const value = getVarName(valueToken);
84
- if (!["stream", "standard"].includes(value)) {
84
+ responseType = getVarName(valueToken);
85
+ if (!["stream", "standard"].includes(responseType)) {
85
86
  $.addInvalidValueError(
86
87
  valueToken,
87
88
  "response_type must be either 'stream' or 'standard'",
@@ -193,10 +194,17 @@ export function queryDeclaration($) {
193
194
  $.addMissingError(parent, "{} is missing a stack clause");
194
195
  }
195
196
 
196
- if (!hasResponse) {
197
+ if (!hasResponse && responseType === "standard") {
197
198
  $.addMissingError(parent, "{} is missing a response clause");
198
199
  }
199
200
 
201
+ if (hasResponse && responseType === "stream") {
202
+ $.addInvalidValueError(
203
+ parent,
204
+ "response clause is not allowed when response_type is 'stream'",
205
+ );
206
+ }
207
+
200
208
  $.MANY1(() => $.CONSUME1(NewlineToken)); // optional new line
201
209
  $.CONSUME(RCurly); // "}"
202
210
  $.MANY2(() => $.CONSUME2(NewlineToken)); // optional new line
@@ -74,7 +74,6 @@ describe("query_parser", () => {
74
74
  expect(parser.errors).to.be.empty;
75
75
 
76
76
  parser = xanoscriptParser(`query foo verb=GET {
77
-
78
77
  response_type = "stream"
79
78
 
80
79
  input {
@@ -82,8 +81,6 @@ describe("query_parser", () => {
82
81
 
83
82
  stack {
84
83
  }
85
-
86
- response = null
87
84
  }`);
88
85
  expect(parser.errors).to.be.empty;
89
86
  });
@@ -9,12 +9,12 @@ describe("Xanoscript Function Parser", () => {
9
9
  it("parses all the valid sources", () => {
10
10
  const errors = [];
11
11
  const files = readdirSync(
12
- join(dirname("./"), "parser/tests/function/valid_sources")
12
+ join(dirname("./"), "parser/tests/function/valid_sources"),
13
13
  );
14
14
  files.forEach((file) => {
15
15
  const source = readFileSync(
16
16
  join(dirname("./"), "parser/tests/function/valid_sources", file),
17
- "utf8"
17
+ "utf8",
18
18
  );
19
19
  const parser = xanoscriptParser(source);
20
20
 
@@ -26,7 +26,7 @@ describe("Xanoscript Function Parser", () => {
26
26
  error.previousToken.image,
27
27
  {
28
28
  length: 20,
29
- }
29
+ },
30
30
  )})`
31
31
  : "N/A",
32
32
  file: `parser/tests/function/valid_sources/${file}:${error.token.startLine}:${error.token.startColumn}`,
@@ -36,7 +36,7 @@ describe("Xanoscript Function Parser", () => {
36
36
  error.token.image,
37
37
  {
38
38
  length: 20,
39
- }
39
+ },
40
40
  )})`,
41
41
  });
42
42
  });
@@ -0,0 +1,55 @@
1
+ import { expect } from "chai";
2
+ import { readdirSync, readFileSync } from "fs";
3
+ import { truncate } from "lodash-es";
4
+ import { describe, it } from "mocha";
5
+ import { dirname, join } from "path";
6
+ import { multidocParser } from "../../multidoc.js";
7
+
8
+ describe("Xanoscript multidoc Parser", () => {
9
+ it("parses all the valid sources", () => {
10
+ const errors = [];
11
+ const files = readdirSync(
12
+ join(dirname("./"), "parser/tests/multidoc/valid_sources"),
13
+ );
14
+
15
+ files.forEach((file) => {
16
+ const source = readFileSync(
17
+ join(dirname("./"), "parser/tests/multidoc/valid_sources", file),
18
+ "utf8",
19
+ );
20
+ const parser = multidocParser(source);
21
+
22
+ if (parser.errors.length > 0) {
23
+ parser.errors.forEach((error) => {
24
+ errors.push({
25
+ previous: error.previousToken
26
+ ? `${error.previousToken.tokenTypeName} (${truncate(
27
+ error.previousToken.image,
28
+ {
29
+ length: 20,
30
+ },
31
+ )})`
32
+ : "N/A",
33
+ file: error.token
34
+ ? `parser/tests/multidoc/valid_sources/${file}:${error.token.startLine}:${error.token.startColumn}`
35
+ : `parser/tests/multidoc/valid_sources/${file}`,
36
+ stack:
37
+ parser.sectionStack?.[parser.sectionStack.length - 1] ?? "N/A",
38
+ message: truncate(error.message, { length: 50 }),
39
+ token: error.token
40
+ ? `${error.token.tokenTypeName} (${truncate(error.token.image, {
41
+ length: 20,
42
+ })})`
43
+ : "N/A",
44
+ });
45
+ });
46
+ }
47
+ });
48
+
49
+ if (errors.length > 0) {
50
+ console.table(errors);
51
+ }
52
+
53
+ expect(errors).to.be.empty;
54
+ });
55
+ });