clarity-pattern-parser 8.4.14 → 9.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/TODO.md +4 -1
- package/dist/grammar/Grammar.d.ts +18 -10
- package/dist/grammar/patterns/andLiteral.d.ts +2 -0
- package/dist/grammar/patterns/anonymousPattern.d.ts +2 -0
- package/dist/grammar/patterns/inlinePattern.d.ts +1 -0
- package/dist/grammar/patterns/literals.d.ts +3 -0
- package/dist/grammar/patterns/pattern.d.ts +2 -2
- package/dist/grammar/patterns.d.ts +2 -0
- package/dist/index.browser.js +472 -185
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.esm.js +471 -186
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +472 -185
- package/dist/index.js.map +1 -1
- package/dist/patterns/And.d.ts +4 -1
- package/dist/patterns/Cursor.d.ts +5 -0
- package/dist/patterns/CursorHistory.d.ts +7 -0
- package/dist/patterns/FiniteRepeat.d.ts +4 -1
- package/dist/patterns/InfiniteRepeat.d.ts +5 -4
- package/dist/patterns/Literal.d.ts +6 -5
- package/dist/patterns/Not.d.ts +5 -4
- package/dist/patterns/Or.d.ts +5 -4
- package/dist/patterns/Pattern.d.ts +4 -2
- package/dist/patterns/Reference.d.ts +5 -4
- package/dist/patterns/Regex.d.ts +5 -4
- package/dist/patterns/Repeat.d.ts +3 -0
- package/dist/patterns/arePatternsEqual.d.ts +2 -0
- package/package.json +1 -1
- package/src/grammar/Grammar.test.ts +126 -72
- package/src/grammar/Grammar.ts +241 -158
- package/src/grammar/patterns/anonymousPattern.ts +23 -0
- package/src/grammar/patterns/body.ts +9 -6
- package/src/grammar/patterns/comment.ts +3 -2
- package/src/grammar/patterns/grammar.ts +15 -12
- package/src/grammar/patterns/import.ts +18 -12
- package/src/grammar/patterns/literal.ts +2 -3
- package/src/grammar/patterns/literals.ts +20 -0
- package/src/grammar/patterns/optionsLiteral.ts +19 -0
- package/src/grammar/patterns/pattern.ts +23 -9
- package/src/grammar/patterns/regexLiteral.ts +1 -0
- package/src/grammar/patterns/repeatLiteral.ts +30 -25
- package/src/grammar/patterns/sequenceLiteral.ts +24 -0
- package/src/grammar/patterns/spaces.ts +8 -6
- package/src/grammar/patterns/statement.ts +8 -20
- package/src/grammar/patterns.test.ts +38 -0
- package/src/grammar/patterns.ts +24 -0
- package/src/grammar/spec.md +4 -12
- package/src/index.ts +11 -5
- package/src/intellisense/AutoComplete.test.ts +41 -40
- package/src/intellisense/css/method.ts +2 -2
- package/src/intellisense/css/unit.ts +2 -2
- package/src/intellisense/css/value.ts +1 -1
- package/src/intellisense/javascript/Javascript.test.ts +31 -32
- package/src/intellisense/javascript/arrayLiteral.ts +7 -6
- package/src/intellisense/javascript/assignment.ts +6 -6
- package/src/intellisense/javascript/deleteStatement.ts +2 -2
- package/src/intellisense/javascript/escapedCharacter.ts +6 -6
- package/src/intellisense/javascript/exponent.ts +6 -6
- package/src/intellisense/javascript/expression.ts +18 -17
- package/src/intellisense/javascript/fraction.ts +3 -3
- package/src/intellisense/javascript/infixOperator.ts +10 -10
- package/src/intellisense/javascript/integer.ts +1 -1
- package/src/intellisense/javascript/invocation.ts +8 -7
- package/src/intellisense/javascript/literal.ts +3 -3
- package/src/intellisense/javascript/numberLiteral.ts +5 -4
- package/src/intellisense/javascript/objectAccess.ts +2 -3
- package/src/intellisense/javascript/objectLiteral.ts +8 -7
- package/src/intellisense/javascript/optionalSpaces.ts +2 -1
- package/src/intellisense/javascript/parameters.ts +5 -5
- package/src/intellisense/javascript/prefixOperator.ts +3 -4
- package/src/intellisense/javascript/propertyAccess.ts +9 -8
- package/src/intellisense/javascript/stringLiteral.ts +14 -15
- package/src/patterns/Cursor.ts +42 -4
- package/src/patterns/CursorHistory.ts +20 -4
- package/src/patterns/FiniteRepeat.test.ts +52 -51
- package/src/patterns/FiniteRepeat.ts +60 -38
- package/src/patterns/InfiniteRepeat.test.ts +36 -49
- package/src/patterns/InfiniteRepeat.ts +70 -37
- package/src/patterns/Literal.test.ts +16 -27
- package/src/patterns/Literal.ts +34 -27
- package/src/patterns/Not.test.ts +7 -7
- package/src/patterns/Not.ts +24 -6
- package/src/patterns/Optional.test.ts +164 -0
- package/src/patterns/Optional.ts +143 -0
- package/src/patterns/{Or.test.ts → Options.test.ts} +51 -49
- package/src/patterns/{Or.ts → Options.ts} +32 -23
- package/src/patterns/Pattern.ts +6 -5
- package/src/patterns/Reference.test.ts +21 -22
- package/src/patterns/Reference.ts +26 -15
- package/src/patterns/Regex.test.ts +15 -15
- package/src/patterns/Regex.ts +29 -19
- package/src/patterns/Repeat.test.ts +12 -22
- package/src/patterns/Repeat.ts +22 -21
- package/src/patterns/{And.test.ts → Sequence.test.ts} +78 -78
- package/src/patterns/{And.ts → Sequence.ts} +40 -29
- package/src/patterns/arePatternsEqual.ts +12 -0
- package/src/patterns/clonePatterns.ts +2 -2
- package/src/grammar/patterns/andLiteral.ts +0 -8
- package/src/grammar/patterns/orLiteral.ts +0 -8
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sequence } from "../patterns/Sequence";
|
|
2
2
|
import { Literal } from "../patterns/Literal";
|
|
3
|
-
import {
|
|
3
|
+
import { Options } from "../patterns/Options";
|
|
4
4
|
import { Pattern } from "../patterns/Pattern";
|
|
5
5
|
import { Reference } from "../patterns/Reference";
|
|
6
6
|
import { Regex } from "../patterns/Regex";
|
|
7
7
|
import { Repeat } from "../patterns/Repeat";
|
|
8
8
|
import { AutoComplete, AutoCompleteOptions } from "./AutoComplete";
|
|
9
|
+
import { Optional } from "../patterns/Optional";
|
|
9
10
|
|
|
10
11
|
function generateFlagFromList(flagNames: string[]) {
|
|
11
12
|
return flagNames.map(flagName => {
|
|
@@ -19,7 +20,7 @@ function generateFlagPattern(flagNames: string[]): Pattern {
|
|
|
19
20
|
return new Literal('flag-name', singleFlagOption);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
const flagPattern = new
|
|
23
|
+
const flagPattern = new Options('flags', generateFlagFromList(flagNames));
|
|
23
24
|
return flagPattern;
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -40,25 +41,25 @@ export function generateExpression(flagNames: string[]): Repeat {
|
|
|
40
41
|
const openParen = new Literal('open-paren', '(');
|
|
41
42
|
const closeParen = new Literal('close-paren', ')');
|
|
42
43
|
const space = new Regex('[space]', '\\s');
|
|
43
|
-
const and = new Literal('
|
|
44
|
-
const or = new Literal('
|
|
44
|
+
const and = new Literal('sequence-literal', 'AND');
|
|
45
|
+
const or = new Literal('options-literal', 'OR');
|
|
45
46
|
const not = new Literal('not', 'NOT ');
|
|
46
|
-
const booleanOperator = new
|
|
47
|
-
const operatorWithSpaces = new
|
|
47
|
+
const booleanOperator = new Options('booleanOperator', [and, or]);
|
|
48
|
+
const operatorWithSpaces = new Sequence('operator-with-spaces', [
|
|
48
49
|
space,
|
|
49
50
|
booleanOperator,
|
|
50
51
|
space,
|
|
51
52
|
]);
|
|
52
53
|
const flag = generateFlagPattern(flagNames);
|
|
53
|
-
const group = new
|
|
54
|
+
const group = new Sequence('group', [
|
|
54
55
|
openParen,
|
|
55
56
|
new Reference('flag-expression'),
|
|
56
57
|
closeParen,
|
|
57
58
|
]);
|
|
58
|
-
const
|
|
59
|
-
const expressionBody = new
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const flagOptionsGroup = new Options('flag-or-group', [flag, group]);
|
|
60
|
+
const expressionBody = new Sequence('flag-body', [
|
|
61
|
+
new Optional("optional-not", not),
|
|
62
|
+
flagOptionsGroup,
|
|
62
63
|
]);
|
|
63
64
|
const flagExpression = new Repeat(
|
|
64
65
|
'flag-expression',
|
|
@@ -85,7 +86,7 @@ describe("AutoComplete", () => {
|
|
|
85
86
|
const space = new Literal("space", " ");
|
|
86
87
|
const doe = new Literal("doe", "Doe");
|
|
87
88
|
const smith = new Literal("smith", "Smith");
|
|
88
|
-
const name = new
|
|
89
|
+
const name = new Sequence("name", [john, space, new Options("last-name", [smith, doe])]);
|
|
89
90
|
|
|
90
91
|
const autoComplete = new AutoComplete(name);
|
|
91
92
|
const result = autoComplete.suggestFor("John Doe");
|
|
@@ -102,7 +103,7 @@ describe("AutoComplete", () => {
|
|
|
102
103
|
const space = new Literal("space", " ");
|
|
103
104
|
const doe = new Literal("doe", "Doe");
|
|
104
105
|
const smith = new Literal("smith", "Smith");
|
|
105
|
-
const name = new
|
|
106
|
+
const name = new Sequence("name", [john, space, new Options("last-name", [smith, doe])]);
|
|
106
107
|
|
|
107
108
|
const text = "John "
|
|
108
109
|
const autoComplete = new AutoComplete(name);
|
|
@@ -127,7 +128,7 @@ describe("AutoComplete", () => {
|
|
|
127
128
|
const space = new Literal("space", " ");
|
|
128
129
|
const doe = new Literal("doe", "Doe");
|
|
129
130
|
const smith = new Literal("smith", "Smith");
|
|
130
|
-
const name = new
|
|
131
|
+
const name = new Sequence("name", [john, space, new Options("last-name", [smith, doe])]);
|
|
131
132
|
const divider = new Regex("divider", "\\s+,\\s+");
|
|
132
133
|
|
|
133
134
|
divider.setTokens([", "])
|
|
@@ -207,9 +208,9 @@ describe("AutoComplete", () => {
|
|
|
207
208
|
const space = new Literal("space", " ");
|
|
208
209
|
const doe = new Literal("doe", "Doe");
|
|
209
210
|
const smith = new Literal("smith", "Smith");
|
|
210
|
-
const firstName = new
|
|
211
|
-
const lastName = new
|
|
212
|
-
const fullName = new
|
|
211
|
+
const firstName = new Options("first-name", [jack, john]);
|
|
212
|
+
const lastName = new Options("last-name", [doe, smith]);
|
|
213
|
+
const fullName = new Sequence("full-name", [firstName, space, lastName]);
|
|
213
214
|
|
|
214
215
|
const text = "Jack";
|
|
215
216
|
const autoComplete = new AutoComplete(fullName, autoCompleteOptions);
|
|
@@ -248,9 +249,9 @@ describe("AutoComplete", () => {
|
|
|
248
249
|
const space = new Literal("space", " ");
|
|
249
250
|
const doe = new Literal("doe", "Doe");
|
|
250
251
|
const smith = new Literal("smith", "Smith");
|
|
251
|
-
const firstName = new
|
|
252
|
-
const lastName = new
|
|
253
|
-
const fullName = new
|
|
252
|
+
const firstName = new Options("first-name", [jack, john]);
|
|
253
|
+
const lastName = new Options("last-name", [doe, smith]);
|
|
254
|
+
const fullName = new Sequence("full-name", [firstName, space, lastName]);
|
|
254
255
|
|
|
255
256
|
const text = "Jack";
|
|
256
257
|
const autoComplete = new AutoComplete(fullName, autoCompleteOptions);
|
|
@@ -282,10 +283,10 @@ describe("AutoComplete", () => {
|
|
|
282
283
|
const a = new Literal("a", "a bank.");
|
|
283
284
|
const the = new Literal("the", "the store.");
|
|
284
285
|
|
|
285
|
-
const first = new
|
|
286
|
-
const second = new
|
|
286
|
+
const first = new Sequence("first", [start, a]);
|
|
287
|
+
const second = new Sequence("second", [start, the]);
|
|
287
288
|
|
|
288
|
-
const both = new
|
|
289
|
+
const both = new Options("both", [first, second]);
|
|
289
290
|
|
|
290
291
|
const autoComplete = new AutoComplete(both);
|
|
291
292
|
const result = autoComplete.suggestFor("John went to a gas station.");
|
|
@@ -297,7 +298,7 @@ describe("AutoComplete", () => {
|
|
|
297
298
|
});
|
|
298
299
|
|
|
299
300
|
test("Options on errors because of string ending, with match", () => {
|
|
300
|
-
const smalls = new
|
|
301
|
+
const smalls = new Options("kahns", [
|
|
301
302
|
new Literal("large", "kahnnnnnn"),
|
|
302
303
|
new Literal("medium", "kahnnnnn"),
|
|
303
304
|
new Literal("small", "kahn"),
|
|
@@ -316,7 +317,7 @@ describe("AutoComplete", () => {
|
|
|
316
317
|
});
|
|
317
318
|
|
|
318
319
|
test("Options on errors because of string ending, between matches", () => {
|
|
319
|
-
const smalls = new
|
|
320
|
+
const smalls = new Options("kahns", [
|
|
320
321
|
new Literal("large", "kahnnnnnn"),
|
|
321
322
|
new Literal("medium", "kahnnnnn"),
|
|
322
323
|
new Literal("small", "kahn"),
|
|
@@ -335,7 +336,7 @@ describe("AutoComplete", () => {
|
|
|
335
336
|
});
|
|
336
337
|
|
|
337
338
|
test("Options on errors because of string ending, match middle", () => {
|
|
338
|
-
const smalls = new
|
|
339
|
+
const smalls = new Options("kahns", [
|
|
339
340
|
new Literal("large", "kahnnnnnn"),
|
|
340
341
|
new Literal("medium", "kahnnnnn"),
|
|
341
342
|
new Literal("small", "kahn"),
|
|
@@ -354,7 +355,7 @@ describe("AutoComplete", () => {
|
|
|
354
355
|
|
|
355
356
|
|
|
356
357
|
test("Options on errors because of string ending on a variety, with match", () => {
|
|
357
|
-
const smalls = new
|
|
358
|
+
const smalls = new Options("kahns", [
|
|
358
359
|
new Literal("different-3", "kahnnnnnnn3"),
|
|
359
360
|
new Literal("different-21", "kahnnnnnn21"),
|
|
360
361
|
new Literal("different-22", "kahnnnnnn22"),
|
|
@@ -382,10 +383,10 @@ describe("AutoComplete", () => {
|
|
|
382
383
|
});
|
|
383
384
|
|
|
384
385
|
test("Options on errors because of string ending on different branches, with match", () => {
|
|
385
|
-
const smalls = new
|
|
386
|
-
new
|
|
387
|
-
new
|
|
388
|
-
new
|
|
386
|
+
const smalls = new Options("kahns", [
|
|
387
|
+
new Sequence("kahn-combo-3", [new Literal("kah", "kah"), new Sequence('partial', [new Literal("n", "n"), new Literal("three", "3")])]),
|
|
388
|
+
new Sequence("kahn-combo", [new Literal("kahn", "kahn"), new Literal("one", "1")]),
|
|
389
|
+
new Sequence("kahn-combo-2", [new Literal("kahn", "kahn"), new Literal("two", "2")]),
|
|
389
390
|
new Literal("small", "kahn"),
|
|
390
391
|
]);
|
|
391
392
|
|
|
@@ -436,19 +437,19 @@ describe("AutoComplete", () => {
|
|
|
436
437
|
expect(result.errorAtIndex).toBe(15);
|
|
437
438
|
});
|
|
438
439
|
|
|
439
|
-
test("Greedy
|
|
440
|
+
test("Greedy Options", () => {
|
|
440
441
|
const john = new Literal("john", "John");
|
|
441
442
|
const doe = new Literal("doe", "Doe");
|
|
442
443
|
const jane = new Literal("jane", "Jane");
|
|
443
444
|
const smith = new Literal("smith", "Smith");
|
|
444
445
|
const space = new Literal("space", " ");
|
|
445
446
|
|
|
446
|
-
const firstName = new
|
|
447
|
-
const lastName = new
|
|
447
|
+
const firstName = new Options("first-name", [john, jane], true);
|
|
448
|
+
const lastName = new Options("last-name", [doe, smith], true);
|
|
448
449
|
const johnJohnson = new Literal("john-johnson", "John Johnson");
|
|
449
450
|
const johnStockton = new Literal("john-stockton", "John Stockton");
|
|
450
|
-
const fullName = new
|
|
451
|
-
const names = new
|
|
451
|
+
const fullName = new Sequence("full-name", [firstName, space, lastName]);
|
|
452
|
+
const names = new Options("names", [johnStockton, johnJohnson, fullName], true);
|
|
452
453
|
|
|
453
454
|
const autoComplete = new AutoComplete(names);
|
|
454
455
|
const results = autoComplete.suggestFor("John ");
|
|
@@ -476,9 +477,9 @@ describe("AutoComplete", () => {
|
|
|
476
477
|
});
|
|
477
478
|
|
|
478
479
|
test("Dedup suggestions", () => {
|
|
479
|
-
const branchOne = new
|
|
480
|
-
const branchTwo = new
|
|
481
|
-
const eitherBranch = new
|
|
480
|
+
const branchOne = new Sequence("branch-1", [new Literal("space", " "), new Literal("A", "A")]);
|
|
481
|
+
const branchTwo = new Sequence("branch-2", [new Literal("space", " "), new Literal("B", "B")]);
|
|
482
|
+
const eitherBranch = new Options("either-branch", [branchOne, branchTwo]);
|
|
482
483
|
|
|
483
484
|
const autoComplete = new AutoComplete(eitherBranch);
|
|
484
485
|
const results = autoComplete.suggestFor("");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Reference } from "../../patterns/Reference";
|
|
2
2
|
import { Literal } from "../../patterns/Literal";
|
|
3
3
|
import { Repeat } from "../../patterns/Repeat";
|
|
4
|
-
import {
|
|
4
|
+
import { Sequence } from "../../patterns/Sequence";
|
|
5
5
|
import name from "./name";
|
|
6
6
|
import optionalSpaces from "./optionalSpaces";
|
|
7
7
|
import divider from "./divider";
|
|
@@ -13,7 +13,7 @@ const args = new Repeat("arguments", values, { divider, min: 0 });
|
|
|
13
13
|
const methodName = name.clone("method-name");
|
|
14
14
|
methodName.setTokens(["rgba", "radial-gradient", "linear-gradient"]);
|
|
15
15
|
|
|
16
|
-
const method = new
|
|
16
|
+
const method = new Sequence("method", [
|
|
17
17
|
methodName,
|
|
18
18
|
openParen,
|
|
19
19
|
optionalSpaces,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sequence } from "../../patterns/Sequence";
|
|
2
2
|
import { Regex } from "../../patterns/Regex";
|
|
3
3
|
import number from "./number";
|
|
4
4
|
|
|
5
5
|
const unitType = new Regex("unit-type", "[a-zA-Z%]+");
|
|
6
6
|
unitType.setTokens(["px", "%", "em", "rem", "vh", "vw"]);
|
|
7
7
|
|
|
8
|
-
const unit = new
|
|
8
|
+
const unit = new Sequence("unit", [number, unitType]);
|
|
9
9
|
|
|
10
10
|
export default unit;
|
|
@@ -3,7 +3,7 @@ import hex from "./hex";
|
|
|
3
3
|
import number from "./number";
|
|
4
4
|
import method from "./method";
|
|
5
5
|
import name from "./name"
|
|
6
|
-
import {
|
|
6
|
+
import { Options } from "../../patterns/Options";
|
|
7
7
|
|
|
8
8
|
const value = new Or("value", [hex, method, unit, number, name]);
|
|
9
9
|
|
|
@@ -12,45 +12,45 @@ import { prefixOperator } from "./prefixOperator";
|
|
|
12
12
|
describe("Ecmascript 3", () => {
|
|
13
13
|
test("Escaped Character", () => {
|
|
14
14
|
let result = escapedCharacter.exec(`\\"`);
|
|
15
|
-
expect(result.ast?.value).toBe(`\\"`)
|
|
15
|
+
expect(result.ast?.value).toBe(`\\"`);
|
|
16
16
|
|
|
17
|
-
result = escapedCharacter.exec(`\\'`)
|
|
18
|
-
expect(result.ast?.value).toBe(`\\'`)
|
|
17
|
+
result = escapedCharacter.exec(`\\'`);
|
|
18
|
+
expect(result.ast?.value).toBe(`\\'`);
|
|
19
19
|
|
|
20
|
-
result = escapedCharacter.exec(`\\\\`)
|
|
21
|
-
expect(result.ast?.value).toBe(`\\\\`)
|
|
20
|
+
result = escapedCharacter.exec(`\\\\`);
|
|
21
|
+
expect(result.ast?.value).toBe(`\\\\`);
|
|
22
22
|
|
|
23
|
-
result = escapedCharacter.exec(`\\/`)
|
|
24
|
-
expect(result.ast?.value).toBe(`\\/`)
|
|
23
|
+
result = escapedCharacter.exec(`\\/`);
|
|
24
|
+
expect(result.ast?.value).toBe(`\\/`);
|
|
25
25
|
|
|
26
|
-
result = escapedCharacter.exec(`\\f`)
|
|
27
|
-
expect(result.ast?.value).toBe(`\\f`)
|
|
26
|
+
result = escapedCharacter.exec(`\\f`);
|
|
27
|
+
expect(result.ast?.value).toBe(`\\f`);
|
|
28
28
|
|
|
29
|
-
result = escapedCharacter.exec(`\\t`)
|
|
30
|
-
expect(result.ast?.value).toBe(`\\t`)
|
|
29
|
+
result = escapedCharacter.exec(`\\t`);
|
|
30
|
+
expect(result.ast?.value).toBe(`\\t`);
|
|
31
31
|
|
|
32
|
-
result = escapedCharacter.exec(`\\u00E9`)
|
|
33
|
-
expect(result.ast?.value).toBe(`\\u00E9`)
|
|
32
|
+
result = escapedCharacter.exec(`\\u00E9`);
|
|
33
|
+
expect(result.ast?.value).toBe(`\\u00E9`);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test("Exponent", () => {
|
|
37
37
|
let result = exponent.exec("e+1");
|
|
38
|
-
expect(result.ast?.value).toBe("e+1")
|
|
38
|
+
expect(result.ast?.value).toBe("e+1");
|
|
39
39
|
|
|
40
40
|
result = exponent.exec("e-1");
|
|
41
|
-
expect(result.ast?.value).toBe("e-1")
|
|
41
|
+
expect(result.ast?.value).toBe("e-1");
|
|
42
42
|
|
|
43
43
|
result = exponent.exec("E+1");
|
|
44
|
-
expect(result.ast?.value).toBe("E+1")
|
|
44
|
+
expect(result.ast?.value).toBe("E+1");
|
|
45
45
|
|
|
46
46
|
result = exponent.exec("E-1");
|
|
47
|
-
expect(result.ast?.value).toBe("E-1")
|
|
47
|
+
expect(result.ast?.value).toBe("E-1");
|
|
48
48
|
|
|
49
49
|
result = exponent.exec("e+11");
|
|
50
|
-
expect(result.ast?.value).toBe("e+11")
|
|
50
|
+
expect(result.ast?.value).toBe("e+11");
|
|
51
51
|
|
|
52
52
|
result = exponent.exec("11");
|
|
53
|
-
expect(result.ast).toBeNull()
|
|
53
|
+
expect(result.ast).toBeNull();
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
test("Integer", () => {
|
|
@@ -155,35 +155,35 @@ describe("Ecmascript 3", () => {
|
|
|
155
155
|
});
|
|
156
156
|
|
|
157
157
|
test("Object Literal", () => {
|
|
158
|
-
let result = expression.exec(`{}
|
|
158
|
+
let result = expression.exec(`{}`, true);
|
|
159
159
|
expect(result.ast?.value).toBe("{}");
|
|
160
160
|
|
|
161
|
-
result = expression.exec(`{prop:{}}`)
|
|
161
|
+
result = expression.exec(`{prop:{}}`);
|
|
162
162
|
expect(result.ast?.value).toBe("{prop:{}}");
|
|
163
163
|
|
|
164
|
-
result = expression.exec(`{prop:"value"}`)
|
|
164
|
+
result = expression.exec(`{prop:"value"}`);
|
|
165
165
|
expect(result.ast?.value).toBe(`{prop:"value"}`);
|
|
166
166
|
|
|
167
|
-
result = expression.exec(`{prop:0.9}`)
|
|
167
|
+
result = expression.exec(`{prop:0.9}`);
|
|
168
168
|
expect(result.ast?.value).toBe(`{prop:0.9}`);
|
|
169
169
|
|
|
170
|
-
result = expression.exec(`{prop:1}`)
|
|
170
|
+
result = expression.exec(`{prop:1}`);
|
|
171
171
|
expect(result.ast?.value).toBe(`{prop:1}`);
|
|
172
172
|
|
|
173
|
-
result = expression.exec(`{"prop":1}`)
|
|
173
|
+
result = expression.exec(`{"prop":1}`);
|
|
174
174
|
expect(result.ast?.value).toBe(`{"prop":1}`);
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
test("Expression", () => {
|
|
178
178
|
|
|
179
|
-
let result = expression.exec("[]")
|
|
179
|
+
let result = expression.exec("[]");
|
|
180
180
|
expect(result.ast?.value).toBe("[]");
|
|
181
181
|
|
|
182
182
|
result = expression.exec("[{}, 9, 0.9e-10, [1, 2]]")
|
|
183
183
|
expect(result.ast?.value).toBe("[{}, 9, 0.9e-10, [1, 2]]");
|
|
184
184
|
|
|
185
185
|
result = expression.exec(`"John"`);
|
|
186
|
-
expect(result.ast?.value).toBe(`"John"`)
|
|
186
|
+
expect(result.ast?.value).toBe(`"John"`);
|
|
187
187
|
|
|
188
188
|
result = expression.exec(`variableName.property`);
|
|
189
189
|
expect(result.ast?.value).toBe(`variableName.property`);
|
|
@@ -193,20 +193,19 @@ describe("Ecmascript 3", () => {
|
|
|
193
193
|
|
|
194
194
|
const cursor = new Cursor(`name() == name.property === name2 ? {prop: name, blah: [ 0.9e-10 ]} : name`);
|
|
195
195
|
cursor.startRecording();
|
|
196
|
-
|
|
197
|
-
})
|
|
196
|
+
});
|
|
198
197
|
|
|
199
198
|
test("Expression Statement", () => {
|
|
200
199
|
let result = assignment.exec(`name = "John"`);
|
|
201
200
|
expect(result.ast?.value).toBe(`name = "John"`);
|
|
202
201
|
|
|
203
|
-
result = assignment.exec(`name = othername = "John"`)
|
|
202
|
+
result = assignment.exec(`name = othername = "John"`);
|
|
204
203
|
expect(result.ast?.value).toBe(`name = othername = "John"`);
|
|
205
204
|
|
|
206
|
-
result = assignment.exec(`name = othername.prop = "John"`)
|
|
205
|
+
result = assignment.exec(`name = othername.prop = "John"`);
|
|
207
206
|
expect(result.ast?.value).toBe(`name = othername.prop = "John"`);
|
|
208
207
|
|
|
209
|
-
result = assignment.exec(`name = othername.prop += 2`)
|
|
208
|
+
result = assignment.exec(`name = othername.prop += 2`);
|
|
210
209
|
expect(result.ast?.value).toBe(`name = othername.prop += 2`);
|
|
211
210
|
|
|
212
211
|
result = assignment.exec(`name.prop().method(blah) = blah.prop() == ha ? first : second`)
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sequence } from "../../patterns/Sequence";
|
|
2
2
|
import { Literal } from "../../patterns/Literal";
|
|
3
|
-
import {
|
|
3
|
+
import { Options } from "../../patterns/Options";
|
|
4
4
|
import { Reference } from "../../patterns/Reference";
|
|
5
5
|
import { Regex } from "../../patterns/Regex";
|
|
6
6
|
import { Repeat } from "../../patterns/Repeat";
|
|
7
7
|
import { optionalSpaces } from "./optionalSpaces";
|
|
8
|
+
import { Optional } from "../../patterns/Optional";
|
|
8
9
|
|
|
9
10
|
const divider = new Regex("array-divider", "\\s*,\\s*");
|
|
10
|
-
const arrayItems = new Repeat("array-items", new Reference("expression"), { divider
|
|
11
|
+
const arrayItems = new Optional("array-items", new Repeat("array-items", new Reference("expression"), { divider}));
|
|
11
12
|
|
|
12
|
-
export const arrayLiteral = new
|
|
13
|
-
[new
|
|
13
|
+
export const arrayLiteral = new Options("array-literal",
|
|
14
|
+
[new Sequence("empty-array-literal", [
|
|
14
15
|
new Literal("open-square-bracket", "["),
|
|
15
16
|
optionalSpaces,
|
|
16
17
|
new Literal("close-square-bracket", "]"),
|
|
17
18
|
]),
|
|
18
|
-
new
|
|
19
|
+
new Sequence("array-literal", [
|
|
19
20
|
new Literal("open-square-bracket", "["),
|
|
20
21
|
optionalSpaces,
|
|
21
22
|
arrayItems,
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sequence } from "../../patterns/Sequence";
|
|
2
2
|
import { Literal } from "../../patterns/Literal";
|
|
3
|
-
import {
|
|
3
|
+
import { Options } from "../../patterns/Options";
|
|
4
4
|
import { Reference } from "../../patterns/Reference";
|
|
5
5
|
import { expression } from "./expression";
|
|
6
6
|
import { optionalSpaces } from "./optionalSpaces";
|
|
7
7
|
|
|
8
|
-
const assignmentOperators = new
|
|
8
|
+
const assignmentOperators = new Options("assignment-operators", [
|
|
9
9
|
new Literal("assign", "="),
|
|
10
10
|
new Literal("addition-assign", "+="),
|
|
11
11
|
new Literal("subtraction-assign", "-="),
|
|
12
12
|
]);
|
|
13
13
|
|
|
14
|
-
const assignment = new
|
|
14
|
+
const assignment = new Sequence("assignment", [
|
|
15
15
|
expression,
|
|
16
16
|
optionalSpaces,
|
|
17
17
|
assignmentOperators,
|
|
18
18
|
optionalSpaces,
|
|
19
|
-
new
|
|
19
|
+
new Options("assignment-right-operand", [
|
|
20
20
|
new Reference("assignment"),
|
|
21
21
|
expression
|
|
22
22
|
]),
|
|
@@ -25,4 +25,4 @@ const assignment = new And("assignment", [
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
export { assignment }
|
|
28
|
+
export { assignment };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sequence } from "../../patterns/Sequence";
|
|
2
2
|
import { Literal } from "../../patterns/Literal";
|
|
3
3
|
import { Regex } from "../../patterns/Regex";
|
|
4
4
|
import { expression } from "./expression";
|
|
5
5
|
import { propertyAccess } from "./propertyAccess";
|
|
6
6
|
|
|
7
7
|
const space = new Regex("space", "\\s+");
|
|
8
|
-
export const deleteStatement = new
|
|
8
|
+
export const deleteStatement = new Sequence("delete-statement", [
|
|
9
9
|
new Literal("delete-keyword", "delete"),
|
|
10
10
|
space,
|
|
11
11
|
expression,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sequence } from "../../patterns/Sequence";
|
|
2
2
|
import { Literal } from "../../patterns/Literal";
|
|
3
|
-
import {
|
|
3
|
+
import { Options } from "../../patterns/Options";
|
|
4
4
|
import { Regex } from "../../patterns/Regex";
|
|
5
5
|
|
|
6
6
|
const backslash = new Literal("backslash", "\\");
|
|
@@ -20,7 +20,7 @@ hexDigit.setTokens([
|
|
|
20
20
|
"A", "B", "C", "D", "E", "F",
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
|
-
const unicode = new
|
|
23
|
+
const unicode = new Sequence("hex", [
|
|
24
24
|
new Literal("u", "u"),
|
|
25
25
|
hexDigit,
|
|
26
26
|
hexDigit,
|
|
@@ -28,7 +28,7 @@ const unicode = new And("hex", [
|
|
|
28
28
|
hexDigit
|
|
29
29
|
]);
|
|
30
30
|
|
|
31
|
-
const specialCharacter = new
|
|
31
|
+
const specialCharacter = new Options("special-character", [
|
|
32
32
|
doubleQuote,
|
|
33
33
|
singleQuote,
|
|
34
34
|
backslash,
|
|
@@ -41,9 +41,9 @@ const specialCharacter = new Or("special-character", [
|
|
|
41
41
|
unicode,
|
|
42
42
|
]);
|
|
43
43
|
|
|
44
|
-
const escapedCharacter = new
|
|
44
|
+
const escapedCharacter = new Sequence("escaped-character", [backslash, specialCharacter]);
|
|
45
45
|
|
|
46
46
|
export {
|
|
47
47
|
escapedCharacter
|
|
48
|
-
}
|
|
48
|
+
};
|
|
49
49
|
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sequence } from "../../patterns/Sequence";
|
|
2
2
|
import { Literal } from "../../patterns/Literal";
|
|
3
|
-
import {
|
|
3
|
+
import { Options } from "../../patterns/Options";
|
|
4
4
|
import { Regex } from "../../patterns/Regex";
|
|
5
5
|
|
|
6
|
-
const e = new
|
|
6
|
+
const e = new Options("e", [
|
|
7
7
|
new Literal("e", "e"),
|
|
8
8
|
new Literal("e", "E")
|
|
9
9
|
]);
|
|
10
10
|
|
|
11
|
-
const optionalSign = new
|
|
11
|
+
const optionalSign = new Options("sign", [
|
|
12
12
|
new Literal("plus", "+"),
|
|
13
13
|
new Literal("minus", "-")
|
|
14
14
|
], true);
|
|
15
15
|
|
|
16
16
|
const digit = new Regex("digit", "\\d+");
|
|
17
17
|
|
|
18
|
-
const exponent = new
|
|
18
|
+
const exponent = new Sequence("exponent", [
|
|
19
19
|
e,
|
|
20
20
|
optionalSign,
|
|
21
21
|
digit,
|
|
22
22
|
]);
|
|
23
23
|
|
|
24
|
-
export { exponent }
|
|
24
|
+
export { exponent };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sequence } from "../../patterns/Sequence";
|
|
2
2
|
import { Literal } from "../../patterns/Literal";
|
|
3
|
-
import {
|
|
3
|
+
import { Options } from "../../patterns/Options";
|
|
4
4
|
import { Reference } from "../../patterns/Reference";
|
|
5
5
|
import { Regex } from "../../patterns/Regex";
|
|
6
6
|
import { Repeat } from "../../patterns/Repeat";
|
|
@@ -13,24 +13,25 @@ import { objectAccess } from "./objectAccess";
|
|
|
13
13
|
import { optionalSpaces } from "./optionalSpaces";
|
|
14
14
|
import { prefixOperator } from "./prefixOperator";
|
|
15
15
|
import { propertyAccess } from "./propertyAccess";
|
|
16
|
+
import { Optional } from "../../patterns/Optional";
|
|
16
17
|
|
|
17
|
-
const space = new Regex("space", "\\s+")
|
|
18
|
+
const space = new Regex("space", "\\s+");
|
|
18
19
|
const newKeyword = new Literal("new-keyword", "new");
|
|
19
20
|
const deleteKeyword = new Literal("delete-keyword", "delete");
|
|
20
21
|
|
|
21
|
-
const newExpression = new
|
|
22
|
+
const newExpression = new Sequence("new-expression", [
|
|
22
23
|
newKeyword,
|
|
23
24
|
space,
|
|
24
25
|
new Reference("expression")
|
|
25
26
|
]);
|
|
26
27
|
|
|
27
|
-
const deleteExpression = new
|
|
28
|
+
const deleteExpression = new Sequence("delete-expression", [
|
|
28
29
|
deleteKeyword,
|
|
29
30
|
space,
|
|
30
31
|
new Reference("expression")
|
|
31
32
|
]);
|
|
32
33
|
|
|
33
|
-
const groupExpression = new
|
|
34
|
+
const groupExpression = new Sequence("group-expression", [
|
|
34
35
|
new Literal("open-paren", "("),
|
|
35
36
|
optionalSpaces,
|
|
36
37
|
new Reference("expression"),
|
|
@@ -38,13 +39,13 @@ const groupExpression = new And("group-expression", [
|
|
|
38
39
|
new Literal("close-paren", ")")
|
|
39
40
|
]);
|
|
40
41
|
|
|
41
|
-
const prefixExpression = new
|
|
42
|
+
const prefixExpression = new Sequence("prefix-expression", [
|
|
42
43
|
prefixOperator,
|
|
43
44
|
new Reference("expression")
|
|
44
45
|
]);
|
|
45
46
|
|
|
46
47
|
const memberAccess = new Repeat("member-access",
|
|
47
|
-
new
|
|
48
|
+
new Options("member-access", [
|
|
48
49
|
invocation,
|
|
49
50
|
propertyAccess,
|
|
50
51
|
])
|
|
@@ -53,7 +54,7 @@ const memberAccess = new Repeat("member-access",
|
|
|
53
54
|
|
|
54
55
|
var variableName = name.clone("variable-name");
|
|
55
56
|
|
|
56
|
-
const expressions = new
|
|
57
|
+
const expressions = new Options("expressions", [
|
|
57
58
|
newExpression,
|
|
58
59
|
deleteExpression,
|
|
59
60
|
literal,
|
|
@@ -64,24 +65,24 @@ const expressions = new Or("expressions", [
|
|
|
64
65
|
prefixExpression
|
|
65
66
|
]);
|
|
66
67
|
|
|
67
|
-
const expressionBody = new
|
|
68
|
+
const expressionBody = new Sequence("expression-body", [
|
|
68
69
|
expressions,
|
|
69
|
-
|
|
70
|
+
new Optional("optional-member-access", memberAccess),
|
|
70
71
|
]);
|
|
71
72
|
|
|
72
|
-
const infixExpression = new
|
|
73
|
+
const infixExpression = new Sequence("infix-expression", [
|
|
73
74
|
expressionBody,
|
|
74
75
|
optionalSpaces,
|
|
75
76
|
infixOperator,
|
|
76
77
|
optionalSpaces,
|
|
77
|
-
new
|
|
78
|
+
new Options("infix-right-operand", [
|
|
78
79
|
new Reference("infix-expression"),
|
|
79
80
|
expressionBody,
|
|
80
81
|
])
|
|
81
82
|
]);
|
|
82
83
|
|
|
83
|
-
const ternaryExpression = new
|
|
84
|
-
new
|
|
84
|
+
const ternaryExpression = new Sequence("ternary", [
|
|
85
|
+
new Options("ternary-condition", [
|
|
85
86
|
infixExpression,
|
|
86
87
|
expressionBody
|
|
87
88
|
]),
|
|
@@ -95,11 +96,11 @@ const ternaryExpression = new And("ternary", [
|
|
|
95
96
|
new Reference("expression")
|
|
96
97
|
]);
|
|
97
98
|
|
|
98
|
-
const expression = new
|
|
99
|
+
const expression = new Options("expression", [
|
|
99
100
|
ternaryExpression,
|
|
100
101
|
infixExpression,
|
|
101
102
|
expressionBody
|
|
102
103
|
]);
|
|
103
104
|
|
|
104
|
-
export { expression }
|
|
105
|
+
export { expression };
|
|
105
106
|
|