clarity-pattern-parser 6.0.2 → 7.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.
Files changed (88) hide show
  1. package/TODO.md +1 -78
  2. package/dist/ast/Node.d.ts +1 -0
  3. package/dist/grammar/Grammar.d.ts +17 -0
  4. package/dist/grammar/patterns/andLiteral.d.ts +2 -0
  5. package/dist/grammar/patterns/comment.d.ts +2 -0
  6. package/dist/grammar/patterns/grammar.d.ts +2 -0
  7. package/dist/grammar/patterns/literal.d.ts +2 -0
  8. package/dist/grammar/patterns/name.d.ts +2 -0
  9. package/dist/grammar/patterns/orLiteral.d.ts +2 -0
  10. package/dist/grammar/patterns/pattern.d.ts +2 -0
  11. package/dist/grammar/patterns/regexLiteral.d.ts +2 -0
  12. package/dist/grammar/patterns/repeatLiteral.d.ts +3 -0
  13. package/dist/grammar/patterns/spaces.d.ts +2 -0
  14. package/dist/grammar/patterns/statement.d.ts +2 -0
  15. package/dist/index.browser.js +1161 -556
  16. package/dist/index.browser.js.map +1 -1
  17. package/dist/index.d.ts +5 -4
  18. package/dist/index.esm.js +1159 -555
  19. package/dist/index.esm.js.map +1 -1
  20. package/dist/index.js +1159 -554
  21. package/dist/index.js.map +1 -1
  22. package/dist/intellisense/AutoComplete.d.ts +2 -6
  23. package/dist/patterns/And.d.ts +1 -1
  24. package/dist/patterns/Cursor.d.ts +1 -0
  25. package/dist/patterns/CursorHistory.d.ts +2 -1
  26. package/dist/patterns/FiniteRepeat.d.ts +39 -0
  27. package/dist/patterns/InfiniteRepeat.d.ts +47 -0
  28. package/dist/patterns/Literal.d.ts +1 -1
  29. package/dist/patterns/Not.d.ts +1 -1
  30. package/dist/patterns/Or.d.ts +1 -1
  31. package/dist/patterns/Pattern.d.ts +1 -1
  32. package/dist/patterns/Reference.d.ts +1 -1
  33. package/dist/patterns/Regex.d.ts +1 -1
  34. package/dist/patterns/Repeat.d.ts +18 -22
  35. package/jest.config.js +0 -1
  36. package/jest.coverage.config.js +13 -0
  37. package/package.json +3 -3
  38. package/src/ast/Node.test.ts +15 -0
  39. package/src/ast/Node.ts +12 -6
  40. package/src/grammar/Grammar.test.ts +288 -0
  41. package/src/grammar/Grammar.ts +234 -0
  42. package/src/grammar/patterns/andLiteral.ts +8 -0
  43. package/src/grammar/patterns/comment.ts +3 -0
  44. package/src/grammar/patterns/grammar.ts +19 -0
  45. package/src/grammar/patterns/literal.ts +5 -0
  46. package/src/grammar/patterns/name.ts +3 -0
  47. package/src/grammar/patterns/orLiteral.ts +8 -0
  48. package/src/grammar/patterns/pattern.ts +13 -0
  49. package/src/grammar/patterns/regexLiteral.ts +4 -0
  50. package/src/grammar/patterns/repeatLiteral.ts +72 -0
  51. package/src/grammar/patterns/spaces.ts +4 -0
  52. package/src/grammar/patterns/statement.ts +35 -0
  53. package/src/grammar/spec.md +142 -0
  54. package/src/index.ts +6 -3
  55. package/src/intellisense/AutoComplete.test.ts +21 -2
  56. package/src/intellisense/AutoComplete.ts +14 -25
  57. package/src/intellisense/Suggestion.ts +0 -1
  58. package/src/intellisense/css/cssValue.ts +1 -1
  59. package/src/intellisense/css/method.ts +1 -1
  60. package/src/intellisense/css/values.ts +1 -1
  61. package/src/intellisense/javascript/Javascript.test.ts +0 -1
  62. package/src/intellisense/javascript/arrayLiteral.ts +1 -1
  63. package/src/intellisense/javascript/expression.ts +1 -1
  64. package/src/intellisense/javascript/invocation.ts +1 -1
  65. package/src/intellisense/javascript/objectLiteral.ts +1 -1
  66. package/src/intellisense/javascript/parameters.ts +1 -1
  67. package/src/intellisense/javascript/stringLiteral.ts +2 -4
  68. package/src/patterns/And.test.ts +5 -5
  69. package/src/patterns/And.ts +11 -17
  70. package/src/patterns/Cursor.ts +4 -0
  71. package/src/patterns/CursorHistory.ts +34 -5
  72. package/src/patterns/FiniteRepeat.test.ts +481 -0
  73. package/src/patterns/FiniteRepeat.ts +231 -0
  74. package/src/patterns/InfiniteRepeat.test.ts +296 -0
  75. package/src/patterns/InfiniteRepeat.ts +329 -0
  76. package/src/patterns/Literal.test.ts +4 -4
  77. package/src/patterns/Literal.ts +1 -1
  78. package/src/patterns/Not.test.ts +11 -11
  79. package/src/patterns/Not.ts +1 -1
  80. package/src/patterns/Or.test.ts +9 -9
  81. package/src/patterns/Or.ts +1 -1
  82. package/src/patterns/Pattern.ts +1 -1
  83. package/src/patterns/Reference.test.ts +8 -8
  84. package/src/patterns/Reference.ts +1 -1
  85. package/src/patterns/Regex.test.ts +4 -4
  86. package/src/patterns/Regex.ts +1 -1
  87. package/src/patterns/Repeat.test.ts +160 -165
  88. package/src/patterns/Repeat.ts +95 -230
package/TODO.md CHANGED
@@ -1,78 +1 @@
1
- ## Grammar Ideas
2
- ```
3
- #comment
4
- integer = /0|([1-9][0-9]+)/
5
- method-name = "subtract" | "add" | "multiply"
6
- divider = /\s*,\s*/
7
- open-paren = "("
8
- close-paren = ")"
9
- argument = integer | method
10
- arguments = argument+ divider
11
- not-integer = !integer
12
- optional-integer = integer?
13
- method = method-name & open-paren & arguments? & close-paren
14
-
15
- export (method, arguments)
16
- ```
17
-
18
- Using Grammar for a simple JSON Parser
19
- ```
20
- # Number Integer
21
- integer = /([1-9][0-9])*|0/
22
- digit = /\d+/
23
-
24
- # Number Fraction
25
- period = "."
26
- fraction = period & digit
27
-
28
- # Number Exponent
29
- e = "e" | "E"
30
- sign = "+" | "-"
31
- number-exponent = e & sign? & digit
32
-
33
- # Number
34
- number = integer & fraction? & number-exponent?
35
-
36
- # String Unicode
37
- hex-digit = /[0-9a-fA-F]/
38
- unicode = "u" & hex-digit & hex-digit & hex-digit & hex-digit
39
- special-character =
40
- "'" |
41
- "\"" |
42
- "\\" |
43
- "/" |
44
- "b" |
45
- "f" |
46
- "n" |
47
- "r" |
48
- "t" |
49
- unicode
50
-
51
- normal-character = /[^\\"]+/
52
- escaped-character = "\\" & special-character
53
- character = normal-character | special-character
54
- characters = character*
55
-
56
- # String
57
- string = "\"" & characters & "\""
58
-
59
- # Boolean
60
- boolean = "true" | "false"
61
-
62
- spaces /\s+/
63
-
64
- array-item = number | boolean | string | array | object
65
- array-items = array-items* /\s+,\s+/
66
- array = "[" & spaces? & array-items & spaces? & "]"
67
-
68
-
69
- ```
70
-
71
- // Other file
72
- import (method, arguments) from "./method.grammar"
73
-
74
-
75
-
76
- We can easily make this parser a breadth first parser by adding a custom parser to essentially count brackets until its whole, so capture a full block, then allow another system handle each block.
77
-
78
- By default this parser is depth first.
1
+ * Need to Rename Repeat.ts to InfiniteRepeat and them make a new class that is Repeat.ts that is a fascade to FiniteRepeat and InfiniteRepeat, so its easier to use.
@@ -42,6 +42,7 @@ export declare class Node {
42
42
  walkDown(callback: (node: Node) => void): void;
43
43
  flatten(): Node[];
44
44
  reduce(): void;
45
+ remove(): void;
45
46
  clone(): Node;
46
47
  toString(): string;
47
48
  toCycleFreeObject(): CycleFreeNode;
@@ -0,0 +1,17 @@
1
+ import { Pattern } from "../patterns/Pattern";
2
+ export declare class Grammar {
3
+ private _parseContext;
4
+ private _autoComplete;
5
+ constructor();
6
+ parse(expression: string): Map<string, Pattern>;
7
+ private _tryToParse;
8
+ private _cleanAst;
9
+ private _buildPatterns;
10
+ private _buildLiteral;
11
+ private _buildRegex;
12
+ private _buildOr;
13
+ private _getPattern;
14
+ private _buildAnd;
15
+ private _buildRepeat;
16
+ static parse(expression: string): Map<string, Pattern>;
17
+ }
@@ -0,0 +1,2 @@
1
+ import { Repeat } from "../../patterns/Repeat";
2
+ export declare const andLiteral: Repeat;
@@ -0,0 +1,2 @@
1
+ import { Regex } from "../../patterns/Regex";
2
+ export declare const comment: Regex;
@@ -0,0 +1,2 @@
1
+ import { Repeat } from "../../patterns/Repeat";
2
+ export declare const grammar: Repeat;
@@ -0,0 +1,2 @@
1
+ import { Regex } from "../../patterns/Regex";
2
+ export declare const literal: Regex;
@@ -0,0 +1,2 @@
1
+ import { Regex } from "../../patterns/Regex";
2
+ export declare const name: Regex;
@@ -0,0 +1,2 @@
1
+ import { Repeat } from "../../patterns/Repeat";
2
+ export declare const orLiteral: Repeat;
@@ -0,0 +1,2 @@
1
+ import { And } from "../../patterns/And";
2
+ export declare const pattern: And;
@@ -0,0 +1,2 @@
1
+ import { Regex } from "../../patterns/Regex";
2
+ export declare const regexLiteral: Regex;
@@ -0,0 +1,3 @@
1
+ import { And } from "../../patterns/And";
2
+ export declare const pattern: And;
3
+ export declare const repeatLiteral: And;
@@ -0,0 +1,2 @@
1
+ import { Regex } from "../../patterns/Regex";
2
+ export declare const spaces: Regex;
@@ -0,0 +1,2 @@
1
+ import { And } from "../../patterns/And";
2
+ export declare const statement: And;