affinirum 1.5.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/.cache/arrow-preview-vWvB5K/affinirum-arrow-functions.patch +155 -0
  2. package/.cache/function-syntax-tests.log +20 -0
  3. package/README.md +925 -355
  4. package/dst/Affinirum.d.ts +29 -19
  5. package/dst/Affinirum.js +399 -334
  6. package/dst/CallFrame.d.ts +12 -3
  7. package/dst/CallFrame.js +49 -10
  8. package/dst/Constant.d.ts +1 -3
  9. package/dst/Constant.js +3 -8
  10. package/dst/LexicalScope.d.ts +11 -9
  11. package/dst/LexicalScope.js +10 -6
  12. package/dst/ParserSpan.d.ts +11 -0
  13. package/dst/{ScriptSpan.js → ParserSpan.js} +8 -5
  14. package/dst/ParserState.d.ts +28 -49
  15. package/dst/ParserState.js +256 -489
  16. package/dst/Type.d.ts +34 -17
  17. package/dst/Type.js +211 -115
  18. package/dst/TypeParser.d.ts +9 -0
  19. package/dst/TypeParser.js +127 -0
  20. package/dst/Value.d.ts +1 -1
  21. package/dst/Value.js +21 -10
  22. package/dst/Variable.d.ts +16 -5
  23. package/dst/Variable.js +32 -7
  24. package/dst/atom/ArrayAtom.d.ts +10 -10
  25. package/dst/atom/ArrayAtom.js +62 -55
  26. package/dst/atom/Atom.d.ts +7 -0
  27. package/dst/atom/FunctionAtom.d.ts +13 -15
  28. package/dst/atom/FunctionAtom.js +53 -104
  29. package/dst/atom/FunctionSignature.d.ts +23 -0
  30. package/dst/atom/FunctionSignature.js +124 -0
  31. package/dst/atom/ObjectAtom.d.ts +11 -9
  32. package/dst/atom/ObjectAtom.js +73 -33
  33. package/dst/atom/PrimitiveAtom.d.ts +6 -7
  34. package/dst/atom/PrimitiveAtom.js +7 -10
  35. package/dst/cjs/Affinirum.d.ts +29 -19
  36. package/dst/cjs/Affinirum.js +398 -333
  37. package/dst/cjs/CallFrame.d.ts +12 -3
  38. package/dst/cjs/CallFrame.js +49 -10
  39. package/dst/cjs/Constant.d.ts +1 -3
  40. package/dst/cjs/Constant.js +3 -8
  41. package/dst/cjs/LexicalScope.d.ts +11 -9
  42. package/dst/cjs/LexicalScope.js +10 -6
  43. package/dst/cjs/ParserSpan.d.ts +11 -0
  44. package/dst/cjs/{ScriptSpan.js → ParserSpan.js} +10 -7
  45. package/dst/cjs/ParserState.d.ts +28 -49
  46. package/dst/cjs/ParserState.js +255 -488
  47. package/dst/cjs/Type.d.ts +34 -17
  48. package/dst/cjs/Type.js +211 -115
  49. package/dst/cjs/TypeParser.d.ts +9 -0
  50. package/dst/cjs/TypeParser.js +131 -0
  51. package/dst/cjs/Value.d.ts +1 -1
  52. package/dst/cjs/Value.js +21 -10
  53. package/dst/cjs/Variable.d.ts +16 -5
  54. package/dst/cjs/Variable.js +36 -9
  55. package/dst/cjs/atom/ArrayAtom.d.ts +10 -10
  56. package/dst/cjs/atom/ArrayAtom.js +62 -55
  57. package/dst/cjs/atom/Atom.d.ts +7 -0
  58. package/dst/cjs/atom/FunctionAtom.d.ts +13 -15
  59. package/dst/cjs/atom/FunctionAtom.js +54 -105
  60. package/dst/cjs/atom/FunctionSignature.d.ts +23 -0
  61. package/dst/cjs/atom/FunctionSignature.js +128 -0
  62. package/dst/cjs/atom/ObjectAtom.d.ts +11 -9
  63. package/dst/cjs/atom/ObjectAtom.js +73 -33
  64. package/dst/cjs/atom/PrimitiveAtom.d.ts +6 -7
  65. package/dst/cjs/atom/PrimitiveAtom.js +7 -10
  66. package/dst/cjs/dictionary/Constants.d.ts +2 -0
  67. package/dst/cjs/dictionary/Constants.js +27 -0
  68. package/dst/cjs/dictionary/Functions.d.ts +2 -0
  69. package/dst/cjs/{Functions.js → dictionary/Functions.js} +27 -25
  70. package/dst/cjs/native/Aggregable.js +10 -2
  71. package/dst/cjs/native/Array.d.ts +2 -3
  72. package/dst/cjs/native/Array.js +38 -39
  73. package/dst/cjs/native/Boolean.d.ts +1 -1
  74. package/dst/cjs/native/Boolean.js +13 -10
  75. package/dst/cjs/native/Buffer.d.ts +5 -5
  76. package/dst/cjs/native/Buffer.js +70 -46
  77. package/dst/cjs/native/Composite.d.ts +5 -0
  78. package/dst/cjs/native/Composite.js +35 -0
  79. package/dst/cjs/native/Enumerable.js +20 -8
  80. package/dst/cjs/native/Float.d.ts +3 -1
  81. package/dst/cjs/native/Float.js +51 -12
  82. package/dst/cjs/native/Integer.d.ts +4 -2
  83. package/dst/cjs/native/Integer.js +60 -25
  84. package/dst/cjs/native/Iterable.d.ts +0 -2
  85. package/dst/cjs/native/Iterable.js +9 -28
  86. package/dst/cjs/native/Number.d.ts +0 -2
  87. package/dst/cjs/native/Number.js +34 -48
  88. package/dst/cjs/native/Object.d.ts +1 -1
  89. package/dst/cjs/native/Object.js +5 -6
  90. package/dst/cjs/native/String.d.ts +7 -6
  91. package/dst/cjs/native/String.js +28 -27
  92. package/dst/cjs/native/Timestamp.d.ts +3 -3
  93. package/dst/cjs/native/Timestamp.js +34 -36
  94. package/dst/cjs/native/Unknown.d.ts +3 -3
  95. package/dst/cjs/native/Unknown.js +48 -17
  96. package/dst/cjs/native/notation/AN.d.ts +1 -1
  97. package/dst/cjs/native/notation/AN.js +37 -35
  98. package/dst/cjs/native/notation/IP.d.ts +1 -1
  99. package/dst/cjs/native/notation/IP.js +11 -12
  100. package/dst/cjs/native/notation/JSON.d.ts +1 -1
  101. package/dst/cjs/native/notation/JSON.js +7 -6
  102. package/dst/cjs/node/AccessNode.d.ts +24 -0
  103. package/dst/cjs/node/AccessNode.js +193 -0
  104. package/dst/cjs/node/ArrayNode.d.ts +7 -4
  105. package/dst/cjs/node/ArrayNode.js +26 -15
  106. package/dst/cjs/node/AssignableNode.d.ts +16 -0
  107. package/dst/cjs/node/AssignableNode.js +18 -0
  108. package/dst/cjs/node/AssignmentNode.d.ts +20 -0
  109. package/dst/cjs/node/AssignmentNode.js +66 -0
  110. package/dst/cjs/node/BlockNode.d.ts +5 -4
  111. package/dst/cjs/node/BlockNode.js +18 -11
  112. package/dst/cjs/node/CallNode.d.ts +7 -5
  113. package/dst/cjs/node/CallNode.js +40 -41
  114. package/dst/cjs/node/CastNode.d.ts +5 -6
  115. package/dst/cjs/node/CastNode.js +16 -17
  116. package/dst/cjs/node/ConstantNode.d.ts +4 -6
  117. package/dst/cjs/node/ConstantNode.js +9 -17
  118. package/dst/cjs/node/FinalNode.d.ts +19 -0
  119. package/dst/cjs/node/FinalNode.js +41 -0
  120. package/dst/cjs/node/FunctionNode.d.ts +17 -0
  121. package/dst/cjs/node/FunctionNode.js +51 -0
  122. package/dst/cjs/node/InvocationNode.d.ts +5 -0
  123. package/dst/cjs/node/InvocationNode.js +34 -0
  124. package/dst/cjs/node/JumpNode.d.ts +7 -9
  125. package/dst/cjs/node/JumpNode.js +12 -19
  126. package/dst/cjs/node/LoopNode.d.ts +7 -5
  127. package/dst/cjs/node/LoopNode.js +33 -22
  128. package/dst/cjs/node/MatchNode.d.ts +17 -0
  129. package/dst/cjs/node/MatchNode.js +65 -0
  130. package/dst/cjs/node/Node.d.ts +14 -0
  131. package/dst/cjs/{Node.js → node/Node.js} +17 -11
  132. package/dst/cjs/node/ObjectNode.d.ts +7 -4
  133. package/dst/cjs/node/ObjectNode.js +42 -11
  134. package/dst/cjs/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
  135. package/dst/cjs/node/TernaryNode.js +45 -0
  136. package/dst/cjs/node/VariableNode.d.ts +10 -6
  137. package/dst/cjs/node/VariableNode.js +50 -16
  138. package/dst/dictionary/Constants.d.ts +2 -0
  139. package/dst/dictionary/Constants.js +24 -0
  140. package/dst/dictionary/Functions.d.ts +2 -0
  141. package/dst/{Functions.js → dictionary/Functions.js} +26 -24
  142. package/dst/native/Aggregable.js +11 -3
  143. package/dst/native/Array.d.ts +2 -3
  144. package/dst/native/Array.js +37 -38
  145. package/dst/native/Boolean.d.ts +1 -1
  146. package/dst/native/Boolean.js +12 -9
  147. package/dst/native/Buffer.d.ts +5 -5
  148. package/dst/native/Buffer.js +66 -42
  149. package/dst/native/Composite.d.ts +5 -0
  150. package/dst/native/Composite.js +32 -0
  151. package/dst/native/Enumerable.js +20 -8
  152. package/dst/native/Float.d.ts +3 -1
  153. package/dst/native/Float.js +48 -11
  154. package/dst/native/Integer.d.ts +4 -2
  155. package/dst/native/Integer.js +56 -23
  156. package/dst/native/Iterable.d.ts +0 -2
  157. package/dst/native/Iterable.js +8 -27
  158. package/dst/native/Number.d.ts +0 -2
  159. package/dst/native/Number.js +34 -46
  160. package/dst/native/Object.d.ts +1 -1
  161. package/dst/native/Object.js +4 -5
  162. package/dst/native/String.d.ts +7 -6
  163. package/dst/native/String.js +24 -24
  164. package/dst/native/Timestamp.d.ts +3 -3
  165. package/dst/native/Timestamp.js +31 -33
  166. package/dst/native/Unknown.d.ts +3 -3
  167. package/dst/native/Unknown.js +49 -18
  168. package/dst/native/notation/AN.d.ts +1 -1
  169. package/dst/native/notation/AN.js +37 -35
  170. package/dst/native/notation/IP.d.ts +1 -1
  171. package/dst/native/notation/IP.js +10 -11
  172. package/dst/native/notation/JSON.d.ts +1 -1
  173. package/dst/native/notation/JSON.js +6 -5
  174. package/dst/node/AccessNode.d.ts +24 -0
  175. package/dst/node/AccessNode.js +189 -0
  176. package/dst/node/ArrayNode.d.ts +7 -4
  177. package/dst/node/ArrayNode.js +26 -15
  178. package/dst/node/AssignableNode.d.ts +16 -0
  179. package/dst/node/AssignableNode.js +14 -0
  180. package/dst/node/AssignmentNode.d.ts +20 -0
  181. package/dst/node/AssignmentNode.js +62 -0
  182. package/dst/node/BlockNode.d.ts +5 -4
  183. package/dst/node/BlockNode.js +18 -11
  184. package/dst/node/CallNode.d.ts +7 -5
  185. package/dst/node/CallNode.js +40 -41
  186. package/dst/node/CastNode.d.ts +5 -6
  187. package/dst/node/CastNode.js +16 -17
  188. package/dst/node/ConstantNode.d.ts +4 -6
  189. package/dst/node/ConstantNode.js +9 -17
  190. package/dst/node/FinalNode.d.ts +19 -0
  191. package/dst/node/FinalNode.js +37 -0
  192. package/dst/node/FunctionNode.d.ts +17 -0
  193. package/dst/node/FunctionNode.js +47 -0
  194. package/dst/node/InvocationNode.d.ts +5 -0
  195. package/dst/node/InvocationNode.js +30 -0
  196. package/dst/node/JumpNode.d.ts +7 -9
  197. package/dst/node/JumpNode.js +12 -19
  198. package/dst/node/LoopNode.d.ts +7 -5
  199. package/dst/node/LoopNode.js +33 -22
  200. package/dst/node/MatchNode.d.ts +17 -0
  201. package/dst/node/MatchNode.js +61 -0
  202. package/dst/node/Node.d.ts +14 -0
  203. package/dst/node/Node.js +28 -0
  204. package/dst/node/ObjectNode.d.ts +7 -4
  205. package/dst/node/ObjectNode.js +42 -11
  206. package/dst/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
  207. package/dst/node/TernaryNode.js +41 -0
  208. package/dst/node/VariableNode.d.ts +10 -6
  209. package/dst/node/VariableNode.js +50 -16
  210. package/package.json +4 -4
  211. package/dst/Atom.d.ts +0 -7
  212. package/dst/Constants.d.ts +0 -2
  213. package/dst/Constants.js +0 -24
  214. package/dst/Functions.d.ts +0 -2
  215. package/dst/Jump.d.ts +0 -1
  216. package/dst/Jump.js +0 -1
  217. package/dst/JumpException.d.ts +0 -9
  218. package/dst/JumpException.js +0 -14
  219. package/dst/Keywords.d.ts +0 -1
  220. package/dst/Keywords.js +0 -17
  221. package/dst/Node.d.ts +0 -14
  222. package/dst/Node.js +0 -22
  223. package/dst/ScriptSpan.d.ts +0 -10
  224. package/dst/cjs/Atom.d.ts +0 -7
  225. package/dst/cjs/Constants.d.ts +0 -2
  226. package/dst/cjs/Constants.js +0 -27
  227. package/dst/cjs/Functions.d.ts +0 -2
  228. package/dst/cjs/Jump.d.ts +0 -1
  229. package/dst/cjs/Jump.js +0 -2
  230. package/dst/cjs/JumpException.d.ts +0 -9
  231. package/dst/cjs/JumpException.js +0 -18
  232. package/dst/cjs/Keywords.d.ts +0 -1
  233. package/dst/cjs/Keywords.js +0 -20
  234. package/dst/cjs/Node.d.ts +0 -14
  235. package/dst/cjs/ScriptSpan.d.ts +0 -10
  236. package/dst/cjs/node/SwitchNode.js +0 -49
  237. package/dst/cjs/node/VariadicNode.d.ts +0 -4
  238. package/dst/cjs/node/VariadicNode.js +0 -10
  239. package/dst/node/SwitchNode.js +0 -45
  240. package/dst/node/VariadicNode.d.ts +0 -4
  241. package/dst/node/VariadicNode.js +0 -6
  242. /package/dst/{Atom.js → atom/Atom.js} +0 -0
  243. /package/dst/cjs/{Atom.js → atom/Atom.js} +0 -0
@@ -1,564 +1,331 @@
1
+ import { Type } from "./Type.js";
2
+ import { Constant } from "./Constant.js";
3
+ import { ParserSpan } from "./ParserSpan.js";
4
+ import { funcRange } from "./native/Array.js";
1
5
  import { funcOr, funcAnd, funcNot } from "./native/Boolean.js";
2
6
  import { parseLiteralBuffer } from "./native/Buffer.js";
7
+ import { funcAt, funcOptionalAt, funcHas, funcOptionalHas } from "./native/Composite.js";
3
8
  import { funcAdd } from "./native/Aggregable.js";
4
9
  import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcPower, isNumericSymbol, parseLiteralNumber } from "./native/Number.js";
5
- import { funcCoalesce, funcEqual, funcNotEqual } from "./native/Unknown.js";
6
- import { isTokenStartSymbol, isTokenSymbol, parseLiteralString } from "./native/String.js";
10
+ import { funcCoalesce, funcEquals, funcNotEquals } from "./native/Unknown.js";
11
+ import { isIdentifierStartSymbol, isIdentifierSymbol, isWhiteSpaceSymbol, parseLiteralString } from "./native/String.js";
7
12
  import { parseLiteralTimestamp } from "./native/Timestamp.js";
8
- import { Constant } from "./Constant.js";
9
- import { Type } from "./Type.js";
10
- import { ScriptSpan } from "./ScriptSpan.js";
11
13
  class Literal {
12
14
  value;
13
15
  constructor(value) {
14
16
  this.value = value;
15
17
  }
16
18
  }
17
- const valueTrue = new Literal(true);
18
- const valueFalse = new Literal(false);
19
- const valueNull = new Literal(undefined);
20
- class Assignment {
21
- operator;
22
- constructor(operator) {
23
- this.operator = operator;
24
- }
25
- }
26
- const funcAssignment = new Assignment();
27
- const funcOrAssignment = new Assignment(funcOr);
28
- const funcAndAssignment = new Assignment(funcAnd);
29
- const funcAddAssignment = new Assignment(funcAdd);
30
- const funcSubtractAssignment = new Assignment(funcSubtract);
31
- const funcMultiplyAssignment = new Assignment(funcMultiply);
32
- const funcDivideAssignment = new Assignment(funcDivide);
33
- const funcRemainderAssignment = new Assignment(funcRemainder);
34
- const idParenthesesOpen = Symbol();
35
- const idParenthesesClose = Symbol();
36
- const idBracketsOpen = Symbol();
37
- const idBracketsClose = Symbol();
38
- const idBracesOpen = Symbol();
39
- const idBracesClose = Symbol();
40
- const idSemicolon = Symbol();
41
- const idColon = Symbol();
42
- const idComma = Symbol();
43
- const idTilda = Symbol();
44
- const idDot = Symbol();
45
- const idQuestion = Symbol();
46
- const idEllipsis = Symbol();
47
- const idCast = Symbol();
48
- const idVar = Symbol();
49
- const idVal = Symbol();
50
- const idIf = Symbol();
51
- const idElse = Symbol();
52
- const idWhile = Symbol();
53
- const idExit = Symbol();
54
- const idReturn = Symbol();
55
- const idStop = Symbol();
56
- const idNext = Symbol();
57
- export class ParserState extends ScriptSpan {
58
- _fragment;
19
+ export class ParserState extends ParserSpan {
20
+ _tokens = new Map(tokens);
21
+ _assignments = new Set(assignments);
22
+ _punctuators = new Set(punctuators);
23
+ _operators = new Set(operators);
24
+ _value;
59
25
  constructor(script) {
60
26
  super(script);
61
27
  }
62
- get literal() {
63
- return this._fragment;
64
- }
65
- get assignment() {
66
- return this._fragment;
67
- }
68
- get operator() {
69
- return this._fragment;
70
- }
71
- get type() {
72
- return this._fragment;
73
- }
74
- get token() {
75
- return this._fragment;
76
- }
77
- get isOperator() {
78
- return this._fragment instanceof Constant;
79
- }
80
- get isLiteral() {
81
- return this._fragment instanceof Literal;
28
+ equals(...tokens) {
29
+ return tokens.includes(this.text());
82
30
  }
83
- get isAssignment() {
84
- return this._fragment instanceof Assignment;
31
+ get isEnded() {
32
+ return this._start === this._script.length;
85
33
  }
86
34
  get isType() {
87
- return this._fragment instanceof Type;
88
- }
89
- get isToken() {
90
- return typeof this._fragment === "string";
91
- }
92
- get isParenthesesOpen() {
93
- return this._fragment === idParenthesesOpen;
94
- }
95
- get isParenthesesClose() {
96
- return this._fragment === idParenthesesClose;
97
- }
98
- get isBracketsOpen() {
99
- return this._fragment === idBracketsOpen;
100
- }
101
- get isBracketsClose() {
102
- return this._fragment === idBracketsClose;
35
+ return this._value instanceof Type;
103
36
  }
104
- get isBracesOpen() {
105
- return this._fragment === idBracesOpen;
37
+ get isConstant() {
38
+ return this._value instanceof Constant;
106
39
  }
107
- get isBracesClose() {
108
- return this._fragment === idBracesClose;
109
- }
110
- get isSemicolon() {
111
- return this._fragment === idSemicolon;
112
- }
113
- get isColon() {
114
- return this._fragment === idColon;
115
- }
116
- get isComma() {
117
- return this._fragment === idComma;
118
- }
119
- get isTilda() {
120
- return this._fragment === idTilda;
121
- }
122
- get isDot() {
123
- return this._fragment === idDot;
124
- }
125
- get isQuestion() {
126
- return this._fragment === idQuestion;
127
- }
128
- get isEllipsis() {
129
- return this._fragment === idEllipsis;
130
- }
131
- get isCast() {
132
- return this._fragment === idCast;
133
- }
134
- get isVar() {
135
- return this._fragment === idVar;
136
- }
137
- get isVal() {
138
- return this._fragment === idVal;
40
+ get isLiteral() {
41
+ return this._value instanceof Literal;
139
42
  }
140
- get isIf() {
141
- return this._fragment === idIf;
43
+ get isIdentifier() {
44
+ return typeof this._value === "string";
142
45
  }
143
- get isElse() {
144
- return this._fragment === idElse;
46
+ get isAssignment() {
47
+ return this._assignments.has(this.text());
145
48
  }
146
- get isWhile() {
147
- return this._fragment === idWhile;
49
+ get isPunctuator() {
50
+ return this._punctuators.has(this.text());
148
51
  }
149
- get isExit() {
150
- return this._fragment === idExit;
52
+ get isOperator() {
53
+ return this._operators.has(this.text());
151
54
  }
152
- get isReturn() {
153
- return this._fragment === idReturn;
55
+ get type() {
56
+ return this._value;
154
57
  }
155
- get isStop() {
156
- return this._fragment === idStop;
58
+ get constant() {
59
+ return this._value;
157
60
  }
158
- get isNext() {
159
- return this._fragment === idNext;
61
+ get literal() {
62
+ return this._value;
160
63
  }
161
- get isEmpty() {
162
- return this._fragment == null;
64
+ get identifier() {
65
+ return this._value;
163
66
  }
164
67
  openParentheses() {
165
- if (!this.isParenthesesOpen) {
68
+ if (!this.equals("(")) {
166
69
  this.throwError("missing opening parentheses");
167
70
  }
168
- return this;
169
71
  }
170
72
  closeParentheses() {
171
- if (!this.isParenthesesClose) {
73
+ if (!this.equals(")")) {
172
74
  this.throwError("missing closing parentheses");
173
75
  }
174
- return this;
175
76
  }
176
77
  openBrackets() {
177
- if (!this.isBracketsOpen) {
78
+ if (!this.equals("[")) {
178
79
  this.throwError("missing opening brackets");
179
80
  }
180
- return this;
181
81
  }
182
82
  closeBrackets() {
183
- if (!this.isBracketsClose) {
83
+ if (!this.equals("]")) {
184
84
  this.throwError("missing closing brackets");
185
85
  }
186
- return this;
187
86
  }
188
87
  openBraces() {
189
- if (!this.isBracesOpen) {
88
+ if (!this.equals("{")) {
190
89
  this.throwError("missing opening braces");
191
90
  }
192
- return this;
193
91
  }
194
92
  closeBraces() {
195
- if (!this.isBracesClose) {
93
+ if (!this.equals("}")) {
196
94
  this.throwError("missing closing braces");
197
95
  }
198
- return this;
199
96
  }
200
- separateByColon() {
201
- if (!this.isColon) {
97
+ assertColon() {
98
+ if (!this.equals(":")) {
202
99
  this.throwError("missing colon separator");
203
100
  }
204
- return this;
205
- }
206
- clone() {
207
- const state = new ParserState(this._script);
208
- state._start = this._start;
209
- state._end = this._end;
210
- state._fragment = this._fragment;
211
- return state;
212
101
  }
213
102
  next() {
214
- this._fragment = undefined;
215
- while (this._end < this._script.length && this._fragment == null) {
103
+ this._value = undefined;
104
+ while (this._end < this._script.length && this._value == null) {
216
105
  this._start = this._end;
217
106
  const c = this._script.charAt(this._end);
218
107
  ++this._end;
219
- switch (c) {
220
- case " ":
221
- case "\t":
222
- case "\n":
223
- case "\r":
224
- case "\v":
225
- case "\f": break;
226
- case "(":
227
- this._fragment = idParenthesesOpen;
228
- break;
229
- case ")":
230
- this._fragment = idParenthesesClose;
231
- break;
232
- case "[":
233
- this._fragment = idBracketsOpen;
234
- break;
235
- case "]":
236
- this._fragment = idBracketsClose;
237
- break;
238
- case "{":
239
- this._fragment = idBracesOpen;
240
- break;
241
- case "}":
242
- this._fragment = idBracesClose;
243
- break;
244
- case ";":
245
- this._fragment = idSemicolon;
246
- break;
247
- case ":":
248
- switch (this._script.charAt(this._end)) {
249
- case ":":
250
- ++this._end;
251
- this._fragment = idCast;
252
- break;
253
- default:
254
- this._fragment = idColon;
255
- break;
256
- }
257
- break;
258
- case ",":
259
- this._fragment = idComma;
260
- break;
261
- case "~":
262
- switch (this._script.charAt(this._end)) {
263
- case ">":
264
- ++this._end;
265
- this._fragment = idReturn;
266
- break;
267
- default:
268
- this._fragment = idTilda;
269
- break;
270
- }
271
- break;
272
- case "?":
273
- switch (this._script.charAt(this._end)) {
274
- case "?":
275
- ++this._end;
276
- this._fragment = Type.Unknown;
277
- break;
278
- case ":":
279
- ++this._end;
280
- this._fragment = funcCoalesce;
281
- break;
282
- default:
283
- this._fragment = idQuestion;
284
- break;
285
- }
286
- break;
287
- case "|":
288
- switch (this._script.charAt(this._end)) {
289
- case "=":
290
- ++this._end;
291
- this._fragment = funcOrAssignment;
292
- break;
293
- default:
294
- this._fragment = funcOr;
295
- break;
296
- }
297
- break;
298
- case "&":
299
- switch (this._script.charAt(this._end)) {
300
- case "=":
301
- ++this._end;
302
- this._fragment = funcAndAssignment;
303
- break;
304
- default:
305
- this._fragment = funcAnd;
306
- break;
307
- }
308
- break;
309
- case ">":
310
- switch (this._script.charAt(this._end)) {
311
- case "=":
312
- ++this._end;
313
- this._fragment = funcGreaterOrEqual;
314
- break;
315
- default:
316
- this._fragment = funcGreaterThan;
317
- break;
318
- }
319
- break;
320
- case "<":
321
- switch (this._script.charAt(this._end)) {
322
- case "=":
323
- ++this._end;
324
- this._fragment = funcLessOrEqual;
325
- break;
326
- default:
327
- this._fragment = funcLessThan;
328
- break;
329
- }
330
- break;
331
- case "!":
332
- switch (this._script.charAt(this._end)) {
333
- case "=":
334
- ++this._end;
335
- this._fragment = funcNotEqual;
336
- break;
337
- default:
338
- this._fragment = funcNot;
339
- break;
340
- }
341
- break;
342
- case "=":
343
- switch (this._script.charAt(this._end)) {
344
- case "=":
345
- ++this._end;
346
- this._fragment = funcEqual;
347
- break;
348
- case ">":
349
- ++this._end;
350
- this._fragment = idExit;
351
- break;
352
- default:
353
- this._fragment = funcAssignment;
354
- break;
355
- }
356
- break;
357
- case "+":
358
- switch (this._script.charAt(this._end)) {
359
- case "=":
108
+ if (isIdentifierStartSymbol(c)) {
109
+ while (isIdentifierSymbol(this._script.charAt(this._end))) {
110
+ ++this._end;
111
+ }
112
+ this._value = this._tokens.get(this.text()) ?? this.text();
113
+ }
114
+ else if (isNumericSymbol(c)) {
115
+ const [num, numEnd] = parseLiteralNumber(this._script, this._start);
116
+ this._end = numEnd;
117
+ this._value = new Literal(num);
118
+ }
119
+ else {
120
+ const token = symbolics.get(c)?.find((i) => this._script.startsWith(i, this._start));
121
+ if (token) {
122
+ this._end = this._start + token.length;
123
+ if (token === "//") {
124
+ while (this._script.charAt(this._end) !== "" &&
125
+ this._script.charAt(this._end) !== "\n") {
360
126
  ++this._end;
361
- this._fragment = funcAddAssignment;
362
- break;
363
- default:
364
- this._fragment = funcAdd;
365
- break;
127
+ }
366
128
  }
367
- break;
368
- case "-":
369
- switch (this._script.charAt(this._end)) {
370
- case "=":
371
- ++this._end;
372
- this._fragment = funcSubtractAssignment;
373
- break;
374
- default:
375
- this._fragment = funcSubtract;
376
- break;
129
+ else if (token === "///") {
130
+ this._end = this._script.indexOf("///", this._end);
131
+ if (this._end < 0) {
132
+ this._start = this._end = this._script.length;
133
+ throw new Error("missing closing comment mark");
134
+ }
135
+ this._end += 3;
377
136
  }
378
- break;
379
- case "*":
380
- switch (this._script.charAt(this._end)) {
381
- case "=":
382
- ++this._end;
383
- this._fragment = funcMultiplyAssignment;
384
- break;
385
- default:
386
- this._fragment = funcMultiply;
387
- break;
137
+ else if (token === "@") {
138
+ const [ts, tsEnd] = parseLiteralTimestamp(this._script, this._start);
139
+ this._end = tsEnd;
140
+ this._value = new Literal(ts);
388
141
  }
389
- break;
390
- case "/":
391
- switch (this._script.charAt(this._end)) {
392
- case "=":
393
- ++this._end;
394
- this._fragment = funcDivideAssignment;
395
- break;
396
- case "/":
397
- if (this._script.charAt(++this._end) === "/") {
398
- ++this._end;
399
- while (this._script.charAt(this._end) !== ""
400
- && (this._script.charAt(this._end) !== c
401
- || this._script.charAt(this._end - 1) !== c
402
- || this._script.charAt(this._end - 2) !== c)) {
403
- ++this._end;
404
- }
405
- if (this._end >= this._script.length) {
406
- this._start = this._script.length;
407
- throw new Error("missing closing comment mark");
408
- }
409
- ++this._end;
410
- }
411
- else {
412
- while (this._script.charAt(this._end) !== ""
413
- && this._script.charAt(this._end) !== "\n") {
414
- ++this._end;
415
- }
416
- }
417
- break;
418
- default:
419
- this._fragment = funcDivide;
420
- break;
142
+ else if (token === "`") {
143
+ const [buf, bufEnd] = parseLiteralBuffer(this._script, this._start);
144
+ this._end = bufEnd;
145
+ this._value = new Literal(buf);
421
146
  }
422
- break;
423
- case "%":
424
- switch (this._script.charAt(this._end)) {
425
- case "=":
426
- ++this._end;
427
- this._fragment = funcRemainderAssignment;
428
- break;
429
- default:
430
- this._fragment = funcRemainder;
431
- break;
147
+ else if (token === "'" || token === "\"") {
148
+ const [str, strEnd] = parseLiteralString(this._script, this._start);
149
+ this._end = strEnd;
150
+ this._value = new Literal(str);
432
151
  }
433
- break;
434
- case "^":
435
- this._fragment = funcPower;
436
- break;
437
- case ".":
438
- switch (this._script.charAt(this._end)) {
439
- case ".":
440
- if (this._script.charAt(++this._end) === ".") {
441
- ++this._end;
442
- this._fragment = idEllipsis;
443
- }
444
- else {
445
- throw new Error("incomplete ellipsis ...");
446
- }
447
- break;
448
- default:
449
- this._fragment = idDot;
450
- break;
152
+ else {
153
+ this._value = this._tokens.get(token);
451
154
  }
452
- break;
453
- case "@": {
454
- const [ts, tsEnd] = parseLiteralTimestamp(this._script, this._start);
455
- this._fragment = new Literal(ts);
456
- this._end = tsEnd;
457
- break;
458
155
  }
459
- case "`": {
460
- const [buf, bufEnd] = parseLiteralBuffer(this._script, this._start);
461
- this._fragment = new Literal(buf);
462
- this._end = bufEnd;
463
- break;
156
+ else if (!isWhiteSpaceSymbol(c)) {
157
+ throw new Error(`unexpected symbol ${c}`);
464
158
  }
465
- case "\"":
466
- case "'": {
467
- const [str, strEnd] = parseLiteralString(this._script, this._start);
468
- this._fragment = new Literal(str);
469
- this._end = strEnd;
470
- break;
471
- }
472
- default:
473
- if (isTokenStartSymbol(c)) {
474
- while (isTokenSymbol(this._script.charAt(this._end))) {
475
- ++this._end;
476
- }
477
- const token = this._script.substring(this._start, this._end);
478
- switch (token) {
479
- case "true":
480
- this._fragment = valueTrue;
481
- break;
482
- case "false":
483
- this._fragment = valueFalse;
484
- break;
485
- case "null":
486
- this._fragment = valueNull;
487
- break;
488
- case "void":
489
- this._fragment = Type.Void;
490
- break;
491
- case "bool":
492
- case "boolean":
493
- this._fragment = Type.Boolean;
494
- break;
495
- case "time":
496
- case "timestamp":
497
- this._fragment = Type.Timestamp;
498
- break;
499
- case "f64":
500
- case "float":
501
- this._fragment = Type.Float;
502
- break;
503
- case "i64":
504
- case "integer":
505
- this._fragment = Type.Integer;
506
- break;
507
- case "buffer":
508
- this._fragment = Type.Buffer;
509
- break;
510
- case "string":
511
- this._fragment = Type.String;
512
- break;
513
- case "array":
514
- this._fragment = Type.Array;
515
- break;
516
- case "object":
517
- this._fragment = Type.Object;
518
- break;
519
- case "function":
520
- this._fragment = Type.Function;
521
- break;
522
- case "var":
523
- this._fragment = idVar;
524
- break;
525
- case "val":
526
- this._fragment = idVal;
527
- break;
528
- case "if":
529
- this._fragment = idIf;
530
- break;
531
- case "else":
532
- this._fragment = idElse;
533
- break;
534
- case "while":
535
- this._fragment = idWhile;
536
- break;
537
- case "stop":
538
- this._fragment = idStop;
539
- break;
540
- case "next":
541
- this._fragment = idNext;
542
- break;
543
- default:
544
- this._fragment = token;
545
- break;
546
- }
547
- }
548
- else if (isNumericSymbol(c)) {
549
- const [num, numEnd] = parseLiteralNumber(this._script, this._start);
550
- this._fragment = new Literal(num);
551
- this._end = numEnd;
552
- }
553
- else {
554
- throw new Error(`unknown symbol ${c}`);
555
- }
556
- break;
557
159
  }
558
160
  }
559
- if (this._end > this._script.length) {
161
+ if (this._end > this._script.length || this._value == null) {
560
162
  this._start = this._end = this._script.length;
561
163
  }
562
164
  return this;
563
165
  }
564
166
  }
167
+ const tokens = [
168
+ ["var", false],
169
+ ["val", false],
170
+ ["func", false],
171
+ ["function", false],
172
+ ["if", false],
173
+ ["then", false],
174
+ ["else", false],
175
+ ["match", false],
176
+ ["while", false],
177
+ ["do", false],
178
+ ["until", false],
179
+ ["next", false],
180
+ ["exit", false],
181
+ ["true", new Literal(true)],
182
+ ["false", new Literal(false)],
183
+ ["null", new Literal(undefined)],
184
+ ["never", false],
185
+ ["any", Type.Any],
186
+ ["bool", Type.Boolean],
187
+ ["boolean", Type.Boolean],
188
+ ["time", Type.Timestamp],
189
+ ["timestamp", Type.Timestamp],
190
+ ["f64", Type.Float],
191
+ ["float", Type.Float],
192
+ ["i64", Type.Integer],
193
+ ["integer", Type.Integer],
194
+ ["buffer", Type.Buffer],
195
+ ["string", Type.String],
196
+ ["?:", funcCoalesce],
197
+ ["|", funcOr],
198
+ ["or", funcOr],
199
+ ["&", funcAnd],
200
+ ["and", funcAnd],
201
+ ["!", funcNot],
202
+ ["not", funcNot],
203
+ ["!=", funcNotEquals],
204
+ ["==", funcEquals],
205
+ [">", funcGreaterThan],
206
+ [">=", funcGreaterOrEqual],
207
+ ["<", funcLessThan],
208
+ ["<=", funcLessOrEqual],
209
+ ["+", funcAdd],
210
+ ["-", funcSubtract],
211
+ ["*", funcMultiply],
212
+ ["**", funcPower],
213
+ ["/", funcDivide],
214
+ ["%", funcRemainder],
215
+ [".", funcAt],
216
+ [".?", funcHas],
217
+ ["?.", funcOptionalAt],
218
+ ["?.?", funcOptionalHas],
219
+ ["?[", funcOptionalAt],
220
+ ["=", false],
221
+ ["|=", funcOr],
222
+ ["&=", funcAnd],
223
+ ["+=", funcAdd],
224
+ ["-=", funcSubtract],
225
+ ["*=", funcMultiply],
226
+ ["/=", funcDivide],
227
+ ["%=", funcRemainder],
228
+ ["(", false],
229
+ [")", false],
230
+ ["[", funcAt],
231
+ ["]", false],
232
+ ["{", false],
233
+ ["}", false],
234
+ [";", false],
235
+ [":", false],
236
+ [",", false],
237
+ ["?", false],
238
+ ["->", false],
239
+ ["=>", false],
240
+ ["..", funcRange],
241
+ ["...", false],
242
+ ["//", false],
243
+ ["///", false],
244
+ ["@", false],
245
+ ["`", false],
246
+ ["'", false],
247
+ ["\"", false],
248
+ ];
249
+ const assignments = [
250
+ "=",
251
+ "|=",
252
+ "&=",
253
+ "+=",
254
+ "-=",
255
+ "*=",
256
+ "/=",
257
+ "%=",
258
+ ];
259
+ const punctuators = [
260
+ "(",
261
+ ")",
262
+ "[",
263
+ "]",
264
+ "{",
265
+ "}",
266
+ ";",
267
+ ":",
268
+ ",",
269
+ "->",
270
+ "?",
271
+ "=>",
272
+ ".",
273
+ ".?",
274
+ "...",
275
+ "//",
276
+ "///",
277
+ "@",
278
+ "`",
279
+ "'",
280
+ "\"",
281
+ ];
282
+ const operators = [
283
+ "..",
284
+ "?:",
285
+ "|",
286
+ "or",
287
+ "&",
288
+ "and",
289
+ "!",
290
+ "not",
291
+ "!=",
292
+ "==",
293
+ ">",
294
+ ">=",
295
+ "<",
296
+ "<=",
297
+ "+",
298
+ "-",
299
+ "*",
300
+ "**",
301
+ "/",
302
+ "%",
303
+ "=",
304
+ "|=",
305
+ "&=",
306
+ "+=",
307
+ "-=",
308
+ "*=",
309
+ "/=",
310
+ "%=",
311
+ ];
312
+ export const keywords = new Set();
313
+ const symbolics = new Map();
314
+ for (const [lexeme] of tokens) {
315
+ const first = lexeme.charAt(0);
316
+ if (isIdentifierStartSymbol(first)) {
317
+ keywords.add(lexeme);
318
+ }
319
+ else {
320
+ const bucket = symbolics.get(first);
321
+ if (bucket) {
322
+ bucket.push(lexeme);
323
+ }
324
+ else {
325
+ symbolics.set(first, [lexeme]);
326
+ }
327
+ }
328
+ }
329
+ for (const bucket of symbolics.values()) {
330
+ bucket.sort((a, b) => b.length - a.length);
331
+ }