@aeriajs/compiler 0.0.4 → 0.0.6
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/dist/ast.d.ts +79 -0
- package/dist/ast.js +23 -0
- package/dist/ast.mjs +21 -0
- package/dist/codegen/generateContracts.d.ts +5 -0
- package/dist/codegen/generateContracts.js +84 -0
- package/dist/codegen/generateContracts.mjs +77 -0
- package/dist/codegen/generateExports.d.ts +15 -0
- package/dist/codegen/generateExports.js +41 -0
- package/dist/codegen/generateExports.mjs +32 -0
- package/dist/codegen/generateJSCollections.d.ts +2 -0
- package/dist/codegen/generateJSCollections.js +91 -0
- package/dist/codegen/generateJSCollections.mjs +82 -0
- package/dist/codegen/generateTSCollections.d.ts +2 -0
- package/dist/codegen/generateTSCollections.js +107 -0
- package/dist/codegen/generateTSCollections.mjs +99 -0
- package/dist/codegen/index.d.ts +4 -0
- package/dist/codegen/index.js +20 -0
- package/dist/codegen/index.mjs +5 -0
- package/dist/codegen/utils.d.ts +29 -0
- package/dist/codegen/utils.js +135 -0
- package/dist/codegen/utils.mjs +114 -0
- package/dist/codegen.d.ts +3 -0
- package/dist/codegen.js +102 -0
- package/dist/codegen.mjs +52 -0
- package/dist/compile.d.ts +21 -0
- package/dist/compile.js +96 -0
- package/dist/compile.mjs +57 -0
- package/dist/diagnostic.d.ts +8 -0
- package/dist/diagnostic.js +22 -0
- package/dist/diagnostic.mjs +16 -0
- package/dist/guards.d.ts +3 -0
- package/dist/guards.js +45 -0
- package/dist/guards.mjs +8 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +23 -0
- package/dist/index.mjs +8 -0
- package/dist/lexer.d.ts +14 -0
- package/dist/lexer.js +272 -0
- package/dist/lexer.mjs +270 -0
- package/dist/parser.d.ts +8 -0
- package/dist/parser.js +907 -0
- package/dist/parser.mjs +851 -0
- package/dist/semantic.d.ts +5 -0
- package/dist/semantic.js +149 -0
- package/dist/semantic.mjs +111 -0
- package/dist/token.d.ts +38 -0
- package/dist/token.js +24 -0
- package/dist/token.mjs +22 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +2 -0
- package/dist/utils.mjs +1 -0
- package/package.json +2 -3
package/dist/lexer.mjs
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { TokenType } from "./token.mjs";
|
|
3
|
+
import { Diagnostic } from "./diagnostic.mjs";
|
|
4
|
+
export const COLLECTION_KEYWORDS = [
|
|
5
|
+
"actions",
|
|
6
|
+
"filters",
|
|
7
|
+
"form",
|
|
8
|
+
"functions",
|
|
9
|
+
"icon",
|
|
10
|
+
"indexes",
|
|
11
|
+
"individualActions",
|
|
12
|
+
"owned",
|
|
13
|
+
"presets",
|
|
14
|
+
"properties",
|
|
15
|
+
"required",
|
|
16
|
+
"search",
|
|
17
|
+
"table"
|
|
18
|
+
];
|
|
19
|
+
export const COLLECTION_ACTIONS_KEYWORDS = [
|
|
20
|
+
"ask",
|
|
21
|
+
"button",
|
|
22
|
+
"clearItem",
|
|
23
|
+
"effect",
|
|
24
|
+
"event",
|
|
25
|
+
"fetchItem",
|
|
26
|
+
"function",
|
|
27
|
+
"icon",
|
|
28
|
+
"label",
|
|
29
|
+
"params",
|
|
30
|
+
"query",
|
|
31
|
+
"requires",
|
|
32
|
+
"roles",
|
|
33
|
+
"route",
|
|
34
|
+
"selection",
|
|
35
|
+
"setItem",
|
|
36
|
+
"translate"
|
|
37
|
+
];
|
|
38
|
+
export const COLLECTION_SEARCH_KEYWORDS = [
|
|
39
|
+
"indexes",
|
|
40
|
+
"placeholder",
|
|
41
|
+
"exactMatches"
|
|
42
|
+
];
|
|
43
|
+
export const CONTRACT_KEYWORDS = [
|
|
44
|
+
"payload",
|
|
45
|
+
"query",
|
|
46
|
+
"response"
|
|
47
|
+
];
|
|
48
|
+
export const TOPLEVEL_KEYWORDS = [
|
|
49
|
+
"collection",
|
|
50
|
+
"contract",
|
|
51
|
+
"functionset"
|
|
52
|
+
];
|
|
53
|
+
export const MISC_KEYWORDS = ["extends"];
|
|
54
|
+
export const KEYWORDS = [].concat(
|
|
55
|
+
COLLECTION_KEYWORDS,
|
|
56
|
+
COLLECTION_ACTIONS_KEYWORDS,
|
|
57
|
+
COLLECTION_SEARCH_KEYWORDS,
|
|
58
|
+
CONTRACT_KEYWORDS,
|
|
59
|
+
TOPLEVEL_KEYWORDS,
|
|
60
|
+
MISC_KEYWORDS
|
|
61
|
+
);
|
|
62
|
+
const keywordsSet = /* @__PURE__ */ new Set();
|
|
63
|
+
for (const keyword of KEYWORDS) {
|
|
64
|
+
keywordsSet.add(keyword);
|
|
65
|
+
}
|
|
66
|
+
const TOKENS = [
|
|
67
|
+
{
|
|
68
|
+
type: null,
|
|
69
|
+
matcher: /\r?[ \t]+/
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: TokenType.LineBreak,
|
|
73
|
+
matcher: "\n"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: TokenType.Comment,
|
|
77
|
+
matcher: "//"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: TokenType.LeftBracket,
|
|
81
|
+
matcher: "{"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: TokenType.RightBracket,
|
|
85
|
+
matcher: "}"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: TokenType.LeftParens,
|
|
89
|
+
matcher: "("
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: TokenType.RightParens,
|
|
93
|
+
matcher: ")"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: TokenType.LeftSquareBracket,
|
|
97
|
+
matcher: "["
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: TokenType.RightSquareBracket,
|
|
101
|
+
matcher: "]"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
type: TokenType.Pipe,
|
|
105
|
+
matcher: "|"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: TokenType.Comma,
|
|
109
|
+
matcher: ","
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
type: TokenType.Range,
|
|
113
|
+
matcher: /(\d+\.\.\d*|\d*\.\.\d+)/g,
|
|
114
|
+
valueExtractor: (value) => {
|
|
115
|
+
const [, left, right] = value.match(/(\d*)\.\.(\d*)/);
|
|
116
|
+
return [
|
|
117
|
+
parseInt(left),
|
|
118
|
+
parseInt(right)
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: TokenType.Dot,
|
|
124
|
+
matcher: "."
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: TokenType.Number,
|
|
128
|
+
matcher: /[0-9]+(\.[0-9]+)?/,
|
|
129
|
+
construct: Number
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
type: TokenType.Boolean,
|
|
133
|
+
matcher: [
|
|
134
|
+
"true",
|
|
135
|
+
"false"
|
|
136
|
+
],
|
|
137
|
+
construct: Boolean
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
type: TokenType.Keyword,
|
|
141
|
+
matcher: Array.from(keywordsSet),
|
|
142
|
+
condition: (state) => !state.inPropertiesStack.at(-1)
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
type: TokenType.MacroName,
|
|
146
|
+
matcher: /[a-zA-Z]([a-zA-Z0-9]|_)+\(/,
|
|
147
|
+
valueExtractor: (value) => value.slice(0, -1)
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
type: TokenType.Identifier,
|
|
151
|
+
matcher: /([a-zA-Z0-9]|_)+/
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
type: TokenType.QuotedString,
|
|
155
|
+
matcher: /"([^"]+)"/,
|
|
156
|
+
valueExtractor: (value) => value.slice(1, -1)
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
type: TokenType.AttributeName,
|
|
160
|
+
matcher: /@[a-zA-Z0-9]+/,
|
|
161
|
+
valueExtractor: (value) => value.slice(1)
|
|
162
|
+
}
|
|
163
|
+
];
|
|
164
|
+
export const tokenize = function(input) {
|
|
165
|
+
let index = 0, line = 1, start = 0, end = 0;
|
|
166
|
+
const tokens = [];
|
|
167
|
+
const errors = [];
|
|
168
|
+
const state = {
|
|
169
|
+
inPropertiesStack: []
|
|
170
|
+
};
|
|
171
|
+
while (index < input.length) {
|
|
172
|
+
let hasMatch = false;
|
|
173
|
+
for (const { type, matcher, valueExtractor, construct, condition } of TOKENS) {
|
|
174
|
+
let value;
|
|
175
|
+
let token;
|
|
176
|
+
if (condition) {
|
|
177
|
+
if (!condition(state)) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (typeof matcher === "string") {
|
|
182
|
+
if (input.slice(index).startsWith(matcher)) {
|
|
183
|
+
value = matcher;
|
|
184
|
+
}
|
|
185
|
+
} else if (matcher instanceof RegExp) {
|
|
186
|
+
const currentMatcher = new RegExp(matcher.source, "y");
|
|
187
|
+
currentMatcher.lastIndex = index;
|
|
188
|
+
const matched = currentMatcher.exec(input);
|
|
189
|
+
if (matched) {
|
|
190
|
+
[value] = matched;
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
const segment = input.slice(index, index + input.slice(index).search(/[ \t\n\{\}\(\)\[\]]/));
|
|
194
|
+
if (segment && matcher.includes(segment)) {
|
|
195
|
+
value = segment;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (value) {
|
|
199
|
+
let tokenValue;
|
|
200
|
+
const location = {
|
|
201
|
+
index: index += value.length,
|
|
202
|
+
line,
|
|
203
|
+
end: end += value.length,
|
|
204
|
+
start: start = end - value.length
|
|
205
|
+
};
|
|
206
|
+
switch (type) {
|
|
207
|
+
case null:
|
|
208
|
+
break;
|
|
209
|
+
case TokenType.LineBreak:
|
|
210
|
+
line++;
|
|
211
|
+
end = 0;
|
|
212
|
+
start = 0;
|
|
213
|
+
break;
|
|
214
|
+
case TokenType.Comment: {
|
|
215
|
+
while (input[index++] !== "\n") {
|
|
216
|
+
}
|
|
217
|
+
line++;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
default: {
|
|
221
|
+
if (valueExtractor) {
|
|
222
|
+
tokenValue = construct ? construct(valueExtractor(value)) : valueExtractor(value);
|
|
223
|
+
} else {
|
|
224
|
+
tokenValue = construct ? construct(value) : value;
|
|
225
|
+
}
|
|
226
|
+
token = {
|
|
227
|
+
type,
|
|
228
|
+
location,
|
|
229
|
+
value: tokenValue
|
|
230
|
+
};
|
|
231
|
+
switch (type) {
|
|
232
|
+
case TokenType.LeftBracket: {
|
|
233
|
+
const lastToken = tokens.at(-1);
|
|
234
|
+
if (lastToken) {
|
|
235
|
+
if (lastToken.value === "properties") {
|
|
236
|
+
state.inPropertiesStack.push(true);
|
|
237
|
+
} else {
|
|
238
|
+
state.inPropertiesStack.push(false);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case TokenType.RightBracket: {
|
|
244
|
+
if (state.inPropertiesStack.length > 0) {
|
|
245
|
+
state.inPropertiesStack.pop();
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
tokens.push(token);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
hasMatch = true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (!hasMatch) {
|
|
257
|
+
index += input.slice(index).search(/[ \t\n\{\}\(\)\[\]]/);
|
|
258
|
+
errors.push(new Diagnostic("unexpected token", {
|
|
259
|
+
index,
|
|
260
|
+
line,
|
|
261
|
+
start,
|
|
262
|
+
end
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
tokens,
|
|
268
|
+
errors
|
|
269
|
+
};
|
|
270
|
+
};
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Token, type Location } from './token.js';
|
|
2
|
+
import { Diagnostic } from './diagnostic.js';
|
|
3
|
+
import * as AST from './ast.js';
|
|
4
|
+
export declare const locationMap: WeakMap<symbol, Location>;
|
|
5
|
+
export declare const parse: (tokens: (Token | undefined)[]) => {
|
|
6
|
+
ast: AST.ProgramNode;
|
|
7
|
+
errors: Diagnostic[];
|
|
8
|
+
};
|