@tsplc/typegen 0.2.17 → 0.2.18
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/README.md +2 -2
- package/dist/cli.js +798 -544
- package/dist/cli.js.map +15 -9
- package/dist/codegen.js +252 -177
- package/dist/codegen.js.map +5 -5
- package/dist/hardware.js +447 -338
- package/dist/hardware.js.map +10 -5
- package/dist/index.js +848 -602
- package/dist/index.js.map +16 -9
- package/package.json +55 -62
- package/src/cli.ts +68 -51
- package/src/codegen/constants.ts +177 -86
- package/src/codegen/generate.ts +436 -388
- package/src/codegen/parser.ts +358 -287
- package/src/device-tree.ts +152 -140
- package/src/hardware/channels.ts +157 -0
- package/src/hardware/eds.ts +408 -0
- package/src/hardware/mapping-types.ts +88 -0
- package/src/hardware/modbus.ts +105 -0
- package/src/hardware/process-image.ts +102 -0
- package/src/hardware/selection.ts +136 -0
- package/src/hardware.ts +195 -844
- package/src/index.ts +25 -1
- package/src/project.ts +246 -151
package/src/codegen/parser.ts
CHANGED
|
@@ -1,329 +1,400 @@
|
|
|
1
|
+
import {
|
|
2
|
+
blockCommentEnd,
|
|
3
|
+
directAddressEnd,
|
|
4
|
+
identifierPattern,
|
|
5
|
+
lineCommentEnd,
|
|
6
|
+
qualifiers,
|
|
7
|
+
} from "@tsplc/iec/st";
|
|
8
|
+
|
|
1
9
|
export interface Source {
|
|
2
|
-
|
|
3
|
-
|
|
10
|
+
name: string;
|
|
11
|
+
text: string;
|
|
4
12
|
}
|
|
5
13
|
|
|
6
14
|
export type TypeReference =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
| { kind: "named"; name: string }
|
|
16
|
+
| { kind: "string"; name: "STRING" | "WSTRING"; length: string }
|
|
17
|
+
| {
|
|
18
|
+
kind: "array";
|
|
19
|
+
dimensions: { lower: string; upper: string }[];
|
|
20
|
+
element: TypeReference;
|
|
21
|
+
};
|
|
14
22
|
|
|
15
23
|
export interface Member {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
type: TypeReference;
|
|
27
|
+
initial?: string;
|
|
28
|
+
/** A CODESYS symbol attribute explicitly publishes this global for clients. */
|
|
29
|
+
published?: boolean;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export type Declaration = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
source: string;
|
|
28
36
|
} & (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
| { kind: "struct"; members: Member[] }
|
|
38
|
+
| {
|
|
39
|
+
kind: "alias";
|
|
40
|
+
type: TypeReference;
|
|
41
|
+
/** `{attribute 'tsplc_keyed'}`: an array whose indexes are enum keys, so each element is its own contract variable. */
|
|
42
|
+
keyed?: boolean;
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
kind: "enum";
|
|
46
|
+
members: { name: string; value?: string }[];
|
|
47
|
+
base: string;
|
|
48
|
+
}
|
|
41
49
|
);
|
|
42
50
|
|
|
43
51
|
export interface GlobalList {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
name: string;
|
|
53
|
+
description: string;
|
|
54
|
+
source: string;
|
|
55
|
+
constant: boolean;
|
|
56
|
+
members: Member[];
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
interface Token {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
text: string;
|
|
61
|
+
offset: number;
|
|
62
|
+
kind: "code" | "comment" | "attribute";
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
function tokenize(source: Source): Token[] {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
66
|
+
const tokens: Token[] = [];
|
|
67
|
+
let offset = 0;
|
|
68
|
+
while (offset < source.text.length) {
|
|
69
|
+
const rest = source.text.slice(offset);
|
|
70
|
+
const whitespace = /^\s+/.exec(rest);
|
|
71
|
+
if (whitespace) {
|
|
72
|
+
offset += whitespace[0].length;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (rest.startsWith("(*")) {
|
|
76
|
+
const end = blockCommentEnd(source.text, offset);
|
|
77
|
+
if (end === null) {
|
|
78
|
+
throw new Error(`${source.name}: unterminated comment`);
|
|
79
|
+
}
|
|
80
|
+
tokens.push({
|
|
81
|
+
text: source.text.slice(offset + 2, end - 2).trim(),
|
|
82
|
+
offset,
|
|
83
|
+
kind: "comment",
|
|
84
|
+
});
|
|
85
|
+
offset = end;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (rest.startsWith("//")) {
|
|
89
|
+
const end = lineCommentEnd(source.text, offset);
|
|
90
|
+
tokens.push({
|
|
91
|
+
text: source.text.slice(offset + 2, end).trim(),
|
|
92
|
+
offset,
|
|
93
|
+
kind: "comment",
|
|
94
|
+
});
|
|
95
|
+
offset = end;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const attribute =
|
|
99
|
+
/^\{(?:[^}'"]|'(?:\$[\s\S]|''|[^'])*'|"(?:\$[\s\S]|""|[^"])*")*\}/.exec(
|
|
100
|
+
rest,
|
|
101
|
+
);
|
|
102
|
+
if (attribute) {
|
|
103
|
+
tokens.push({ text: attribute[0], offset, kind: "attribute" });
|
|
104
|
+
offset += attribute[0].length;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const addressEnd = directAddressEnd(source.text, offset);
|
|
108
|
+
if (addressEnd !== null) {
|
|
109
|
+
tokens.push({
|
|
110
|
+
text: source.text.slice(offset, addressEnd),
|
|
111
|
+
offset,
|
|
112
|
+
kind: "code",
|
|
113
|
+
});
|
|
114
|
+
offset = addressEnd;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const code =
|
|
118
|
+
/^(?:'(?:\$[\s\S]|''|[^'])*'|"(?:\$[\s\S]|""|[^"])*"|\d[\d_]*#[\da-fA-F_]+|\d[\d_]*(?:\.(?!\.)[\d_]+)?(?:[eE][+-]?\d+)?|[A-Za-z_]\w*|:=|\.\.|[[\]():;,.+\-*/#])/i.exec(
|
|
119
|
+
rest,
|
|
120
|
+
);
|
|
121
|
+
if (!code) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`${source.name}:${source.text.slice(0, offset).split("\n").length}: unsupported token ${JSON.stringify(rest.slice(0, 24))}`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
tokens.push({ text: code[0], offset, kind: "code" });
|
|
127
|
+
offset += code[0].length;
|
|
128
|
+
}
|
|
129
|
+
return tokens;
|
|
114
130
|
}
|
|
115
131
|
|
|
116
132
|
class Parser {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
133
|
+
private position = 0;
|
|
134
|
+
private readonly tokens: Token[];
|
|
135
|
+
constructor(private readonly source: Source) {
|
|
136
|
+
this.tokens = tokenize(source);
|
|
137
|
+
}
|
|
122
138
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
139
|
+
private nextIndex(): number {
|
|
140
|
+
let index = this.position;
|
|
141
|
+
while (index < this.tokens.length && this.tokens[index]?.kind !== "code") {
|
|
142
|
+
index++;
|
|
143
|
+
}
|
|
144
|
+
return index;
|
|
145
|
+
}
|
|
128
146
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
147
|
+
peek(): string {
|
|
148
|
+
return this.tokens[this.nextIndex()]?.text.toUpperCase() ?? "";
|
|
149
|
+
}
|
|
132
150
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
151
|
+
error(message: string): never {
|
|
152
|
+
const offset =
|
|
153
|
+
this.tokens[this.nextIndex()]?.offset ?? this.source.text.length;
|
|
154
|
+
throw new Error(
|
|
155
|
+
`${this.source.name}:${this.source.text.slice(0, offset).split("\n").length}: ${message}`,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
139
158
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
159
|
+
private take(): string {
|
|
160
|
+
this.position = this.nextIndex();
|
|
161
|
+
const token = this.tokens[this.position++];
|
|
162
|
+
if (!token) {
|
|
163
|
+
this.error("unexpected end of declaration");
|
|
164
|
+
}
|
|
165
|
+
return token.text;
|
|
166
|
+
}
|
|
146
167
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
168
|
+
private accept(value: string): boolean {
|
|
169
|
+
if (this.peek() !== value) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
this.take();
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
152
175
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
176
|
+
private expect(value: string): void {
|
|
177
|
+
if (!this.accept(value)) {
|
|
178
|
+
this.error(`expected ${value}, found ${this.peek() || "end of file"}`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
156
181
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
182
|
+
private identifier(): string {
|
|
183
|
+
const name = this.take();
|
|
184
|
+
if (!identifierPattern.test(name)) {
|
|
185
|
+
this.error(`expected identifier, found ${name}`);
|
|
186
|
+
}
|
|
187
|
+
return name;
|
|
188
|
+
}
|
|
162
189
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
190
|
+
private documentation(): string {
|
|
191
|
+
const end = this.nextIndex();
|
|
192
|
+
const text = this.tokens
|
|
193
|
+
.slice(this.position, end)
|
|
194
|
+
.filter((token) => token.kind === "comment")
|
|
195
|
+
.map((token) => token.text)
|
|
196
|
+
.join("\n");
|
|
197
|
+
this.position = end;
|
|
198
|
+
return text;
|
|
199
|
+
}
|
|
173
200
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
201
|
+
private expression(stops: string[]): string {
|
|
202
|
+
const values: string[] = [];
|
|
203
|
+
const closing: string[] = [];
|
|
204
|
+
while (this.peek() && (closing.length || !stops.includes(this.peek()))) {
|
|
205
|
+
const token = this.take();
|
|
206
|
+
if (token === "(" || token === "[") {
|
|
207
|
+
closing.push(token === "(" ? ")" : "]");
|
|
208
|
+
}
|
|
209
|
+
if (token === ")" || token === "]") {
|
|
210
|
+
if (closing.pop() !== token) {
|
|
211
|
+
this.error(`unmatched ${token}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
values.push(token);
|
|
215
|
+
}
|
|
216
|
+
if (!values.length || closing.length) {
|
|
217
|
+
this.error("incomplete expression");
|
|
218
|
+
}
|
|
219
|
+
return values.join(" ");
|
|
220
|
+
}
|
|
188
221
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
222
|
+
private reference(): TypeReference {
|
|
223
|
+
if (this.accept("ARRAY")) {
|
|
224
|
+
this.expect("[");
|
|
225
|
+
const dimensions: { lower: string; upper: string }[] = [];
|
|
226
|
+
do {
|
|
227
|
+
const lower = this.expression([".."]);
|
|
228
|
+
this.expect("..");
|
|
229
|
+
const upper = this.expression([",", "]"]);
|
|
230
|
+
dimensions.push({ lower, upper });
|
|
231
|
+
} while (this.accept(","));
|
|
232
|
+
this.expect("]");
|
|
233
|
+
this.expect("OF");
|
|
234
|
+
return { kind: "array", dimensions, element: this.reference() };
|
|
235
|
+
}
|
|
236
|
+
const parts = [this.identifier()];
|
|
237
|
+
while (this.accept(".")) {
|
|
238
|
+
parts.push(this.identifier());
|
|
239
|
+
}
|
|
240
|
+
const name = parts.join(".");
|
|
241
|
+
const upper = name.toUpperCase();
|
|
242
|
+
if (upper === "STRING" || upper === "WSTRING") {
|
|
243
|
+
const opening = this.peek();
|
|
244
|
+
if (opening !== "(" && opening !== "[") {
|
|
245
|
+
return { kind: "string", name: upper, length: "80" };
|
|
246
|
+
}
|
|
247
|
+
this.take();
|
|
248
|
+
const closing = opening === "(" ? ")" : "]";
|
|
249
|
+
const length = this.expression([closing]);
|
|
250
|
+
this.expect(closing);
|
|
251
|
+
return { kind: "string", name: upper, length };
|
|
252
|
+
}
|
|
253
|
+
return { kind: "named", name };
|
|
254
|
+
}
|
|
218
255
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
private members(end: string): Member[] {
|
|
257
|
+
const members: Member[] = [];
|
|
258
|
+
while (this.peek() !== end) {
|
|
259
|
+
const published = this.tokens
|
|
260
|
+
.slice(this.position, this.nextIndex())
|
|
261
|
+
.some(
|
|
262
|
+
(token) =>
|
|
263
|
+
token.kind === "attribute" &&
|
|
264
|
+
/^\{\s*attribute\s+'symbol'\s*:=\s*'(?:read|write|readwrite)'\s*\}$/i.test(
|
|
265
|
+
token.text,
|
|
266
|
+
),
|
|
267
|
+
);
|
|
268
|
+
const description = this.documentation();
|
|
269
|
+
const names = [this.identifier()];
|
|
270
|
+
while (this.accept(",")) {
|
|
271
|
+
names.push(this.identifier());
|
|
272
|
+
}
|
|
273
|
+
if (this.accept("AT")) {
|
|
274
|
+
// Location belongs to the hardware/build mapping; it does not alter the
|
|
275
|
+
// scalar type that application consumers receive from type generation.
|
|
276
|
+
const address = this.take();
|
|
277
|
+
if (directAddressEnd(address, 0) !== address.length) {
|
|
278
|
+
this.error(`expected direct address after AT, found ${address}`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
this.expect(":");
|
|
282
|
+
const type = this.reference();
|
|
283
|
+
const initial = this.accept(":=") ? this.expression([";"]) : undefined;
|
|
284
|
+
this.expect(";");
|
|
285
|
+
for (const name of names) {
|
|
286
|
+
if (
|
|
287
|
+
members.some(
|
|
288
|
+
(member) => member.name.toUpperCase() === name.toUpperCase(),
|
|
289
|
+
)
|
|
290
|
+
) {
|
|
291
|
+
this.error(`duplicate member ${name}`);
|
|
292
|
+
}
|
|
293
|
+
members.push({
|
|
294
|
+
name,
|
|
295
|
+
description,
|
|
296
|
+
type,
|
|
297
|
+
...(initial === undefined ? {} : { initial }),
|
|
298
|
+
...(published ? { published: true } : {}),
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
this.expect(end);
|
|
303
|
+
return members;
|
|
304
|
+
}
|
|
258
305
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
306
|
+
declarations(): Declaration[] {
|
|
307
|
+
const declarations: Declaration[] = [];
|
|
308
|
+
while (this.peek()) {
|
|
309
|
+
const keyed = this.tokens
|
|
310
|
+
.slice(this.position, this.nextIndex())
|
|
311
|
+
.some(
|
|
312
|
+
(token) =>
|
|
313
|
+
token.kind === "attribute" &&
|
|
314
|
+
/^\{\s*attribute\s+'tsplc_keyed'\s*\}$/i.test(token.text),
|
|
315
|
+
);
|
|
316
|
+
const description = this.documentation();
|
|
317
|
+
this.expect("TYPE");
|
|
318
|
+
const name = this.identifier();
|
|
319
|
+
this.expect(":");
|
|
320
|
+
const common = { name, description, source: this.source.name };
|
|
321
|
+
if (this.accept("STRUCT")) {
|
|
322
|
+
declarations.push({
|
|
323
|
+
...common,
|
|
324
|
+
kind: "struct",
|
|
325
|
+
members: this.members("END_STRUCT"),
|
|
326
|
+
});
|
|
327
|
+
this.accept(";");
|
|
328
|
+
} else if (this.accept("(")) {
|
|
329
|
+
const members: { name: string; value?: string }[] = [];
|
|
330
|
+
do {
|
|
331
|
+
const member = this.identifier();
|
|
332
|
+
const value = this.accept(":=")
|
|
333
|
+
? this.expression([",", ")"])
|
|
334
|
+
: undefined;
|
|
335
|
+
if (
|
|
336
|
+
members.some(
|
|
337
|
+
(item) => item.name.toUpperCase() === member.toUpperCase(),
|
|
338
|
+
)
|
|
339
|
+
) {
|
|
340
|
+
this.error(`duplicate enum member ${member}`);
|
|
341
|
+
}
|
|
342
|
+
members.push({ name: member, value });
|
|
343
|
+
} while (this.accept(",") && this.peek() !== ")");
|
|
344
|
+
this.expect(")");
|
|
345
|
+
const base =
|
|
346
|
+
this.peek() === ";" ? "INT" : this.identifier().toUpperCase();
|
|
347
|
+
this.expect(";");
|
|
348
|
+
declarations.push({ ...common, kind: "enum", members, base });
|
|
349
|
+
} else {
|
|
350
|
+
const type = this.reference();
|
|
351
|
+
this.expect(";");
|
|
352
|
+
declarations.push({
|
|
353
|
+
...common,
|
|
354
|
+
kind: "alias",
|
|
355
|
+
type,
|
|
356
|
+
...(keyed ? { keyed } : {}),
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
this.expect("END_TYPE");
|
|
360
|
+
this.accept(";");
|
|
361
|
+
}
|
|
362
|
+
if (!declarations.length) {
|
|
363
|
+
this.error("no TYPE declarations found");
|
|
364
|
+
}
|
|
365
|
+
return declarations;
|
|
366
|
+
}
|
|
304
367
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
368
|
+
globals(name: string): GlobalList {
|
|
369
|
+
const description = this.documentation();
|
|
370
|
+
this.expect("VAR_GLOBAL");
|
|
371
|
+
const written = new Set<string>();
|
|
372
|
+
while (qualifiers.has(this.peek())) {
|
|
373
|
+
const qualifier = this.take().toUpperCase();
|
|
374
|
+
if (written.has(qualifier)) {
|
|
375
|
+
this.error(`duplicate ${qualifier} qualifier`);
|
|
376
|
+
}
|
|
377
|
+
written.add(qualifier);
|
|
378
|
+
}
|
|
379
|
+
const members = this.members("END_VAR");
|
|
380
|
+
this.accept(";");
|
|
381
|
+
if (this.peek()) {
|
|
382
|
+
this.error("only one VAR_GLOBAL block per file is supported");
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
name,
|
|
386
|
+
description,
|
|
387
|
+
source: this.source.name,
|
|
388
|
+
constant: written.has("CONSTANT"),
|
|
389
|
+
members,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
321
392
|
}
|
|
322
393
|
|
|
323
394
|
export function parseDeclarations(source: Source): Declaration[] {
|
|
324
|
-
|
|
395
|
+
return new Parser(source).declarations();
|
|
325
396
|
}
|
|
326
397
|
|
|
327
398
|
export function parseGlobals(source: Source, name: string): GlobalList {
|
|
328
|
-
|
|
399
|
+
return new Parser(source).globals(name);
|
|
329
400
|
}
|