@hatchingpoint/point 0.0.6 → 0.0.8

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/src/index.ts CHANGED
@@ -1 +1 @@
1
- export * from "./core/index.ts";
1
+ export * from "./core/index.ts";
@@ -1,230 +1,230 @@
1
- import type { PointSourceSpan } from "../core/ast.ts";
2
-
3
- export interface PointSemanticProgram {
4
- kind: "semanticProgram";
5
- module?: string;
6
- uses: PointSemanticUseDeclaration[];
7
- declarations: PointSemanticDeclaration[];
8
- span?: PointSourceSpan;
9
- }
10
-
11
- export interface PointSemanticUseDeclaration {
12
- kind: "use";
13
- moduleName: string;
14
- from?: string;
15
- span?: PointSourceSpan;
16
- }
17
-
18
- export type PointSemanticDeclaration =
19
- | PointSemanticRecordDeclaration
20
- | PointSemanticCalculationDeclaration
21
- | PointSemanticRuleDeclaration
22
- | PointSemanticLabelDeclaration
23
- | PointSemanticExternalDeclaration
24
- | PointSemanticActionDeclaration
25
- | PointSemanticPolicyDeclaration
26
- | PointSemanticViewDeclaration
27
- | PointSemanticRouteDeclaration
28
- | PointSemanticWorkflowDeclaration
29
- | PointSemanticCommandDeclaration;
30
-
31
- export interface PointSemanticRecordDeclaration {
32
- kind: "record";
33
- name: string;
34
- fields: PointSemanticField[];
35
- span?: PointSourceSpan;
36
- }
37
-
38
- export interface PointSemanticField {
39
- label: string;
40
- type: PointSemanticTypeExpression;
41
- span?: PointSourceSpan;
42
- }
43
-
44
- export interface PointSemanticBinding {
45
- label: string;
46
- type: PointSemanticTypeExpression;
47
- span?: PointSourceSpan;
48
- }
49
-
50
- export interface PointSemanticOutputBinding {
51
- name: string;
52
- type: PointSemanticTypeExpression;
53
- span?: PointSourceSpan;
54
- }
55
-
56
- export interface PointSemanticCalculationDeclaration {
57
- kind: "calculation";
58
- name: string;
59
- inputs: PointSemanticBinding[];
60
- output: PointSemanticOutputBinding;
61
- body: PointSemanticCalculationStatement[];
62
- span?: PointSourceSpan;
63
- }
64
-
65
- export interface PointSemanticRuleDeclaration {
66
- kind: "rule";
67
- name: string;
68
- inputs: PointSemanticBinding[];
69
- output: PointSemanticOutputBinding;
70
- body: PointSemanticRuleStatement[];
71
- span?: PointSourceSpan;
72
- }
73
-
74
- export interface PointSemanticLabelDeclaration {
75
- kind: "label";
76
- name: string;
77
- inputs: PointSemanticBinding[];
78
- output: PointSemanticOutputBinding;
79
- body: PointSemanticLabelStatement[];
80
- span?: PointSourceSpan;
81
- }
82
-
83
- export interface PointSemanticExternalDeclaration {
84
- kind: "external";
85
- name: string;
86
- functions: PointSemanticExternalFunction[];
87
- span?: PointSourceSpan;
88
- }
89
-
90
- export interface PointSemanticExternalFunction {
91
- label: string;
92
- params: PointSemanticBinding[];
93
- returnType: PointSemanticTypeExpression;
94
- from: string;
95
- importAs?: string;
96
- span?: PointSourceSpan;
97
- }
98
-
99
- export interface PointSemanticActionDeclaration {
100
- kind: "action";
101
- name: string;
102
- inputs: PointSemanticBinding[];
103
- output: PointSemanticOutputBinding;
104
- touches: string[];
105
- body: PointSemanticActionStatement[];
106
- span?: PointSourceSpan;
107
- }
108
-
109
- export interface PointSemanticPolicyDeclaration {
110
- kind: "policy";
111
- name: string;
112
- inputs: PointSemanticBinding[];
113
- body: PointSemanticPolicyStatement[];
114
- span?: PointSourceSpan;
115
- }
116
-
117
- export interface PointSemanticViewDeclaration {
118
- kind: "view";
119
- name: string;
120
- inputs: PointSemanticBinding[];
121
- output: PointSemanticOutputBinding;
122
- body: PointSemanticViewStatement[];
123
- span?: PointSourceSpan;
124
- }
125
-
126
- export interface PointSemanticRouteDeclaration {
127
- kind: "route";
128
- name: string;
129
- method: string;
130
- path: string;
131
- inputs: PointSemanticBinding[];
132
- output: PointSemanticOutputBinding;
133
- body: PointSemanticRouteStatement[];
134
- span?: PointSourceSpan;
135
- }
136
-
137
- export interface PointSemanticWorkflowDeclaration {
138
- kind: "workflow";
139
- name: string;
140
- inputs: PointSemanticBinding[];
141
- output: PointSemanticOutputBinding;
142
- body: PointSemanticWorkflowStatement[];
143
- span?: PointSourceSpan;
144
- }
145
-
146
- export interface PointSemanticCommandDeclaration {
147
- kind: "command";
148
- name: string;
149
- inputs: PointSemanticBinding[];
150
- output: PointSemanticOutputBinding;
151
- body: PointSemanticCommandStatement[];
152
- span?: PointSourceSpan;
153
- }
154
-
155
- export type PointSemanticCalculationStatement =
156
- | { kind: "assignIs"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
157
- | { kind: "startsAt"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
158
- | { kind: "startsAs"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
159
- | { kind: "forEach"; item: string; iterable: PointSemanticExpression; body: PointSemanticMutationStatement[]; span?: PointSourceSpan }
160
- | PointSemanticMutationStatement
161
- | { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
162
-
163
- export type PointSemanticRuleStatement =
164
- | { kind: "startsAt"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
165
- | { kind: "addWhen"; amount: PointSemanticExpression; condition: PointSemanticExpression; span?: PointSourceSpan }
166
- | { kind: "forEach"; item: string; iterable: PointSemanticExpression; body: PointSemanticMutationStatement[]; span?: PointSourceSpan }
167
- | PointSemanticMutationStatement
168
- | { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
169
-
170
- export type PointSemanticLabelStatement =
171
- | { kind: "whenReturn"; condition: PointSemanticExpression; value: PointSemanticExpression; span?: PointSourceSpan }
172
- | { kind: "otherwiseReturn"; value: PointSemanticExpression; span?: PointSourceSpan };
173
-
174
- export type PointSemanticActionStatement =
175
- | { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan }
176
- | { kind: "expression"; value: PointSemanticExpression; span?: PointSourceSpan };
177
-
178
- export type PointSemanticPolicyStatement =
179
- | { kind: "allow"; condition: PointSemanticExpression; span?: PointSourceSpan }
180
- | { kind: "deny"; condition: PointSemanticExpression; span?: PointSourceSpan }
181
- | { kind: "require"; condition: PointSemanticExpression; span?: PointSourceSpan };
182
-
183
- export type PointSemanticViewStatement =
184
- | { kind: "render"; value: PointSemanticExpression; span?: PointSourceSpan }
185
- | { kind: "whenRender"; condition: PointSemanticExpression; value: PointSemanticExpression; span?: PointSourceSpan };
186
-
187
- export type PointSemanticRouteStatement = { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
188
-
189
- export type PointSemanticWorkflowStatement =
190
- | { kind: "step"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
191
- | { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
192
-
193
- export type PointSemanticCommandStatement = { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
194
-
195
- export type PointSemanticMutationStatement =
196
- | { kind: "addTo"; amount: PointSemanticExpression; target: string; span?: PointSourceSpan }
197
- | { kind: "subtractFrom"; amount: PointSemanticExpression; target: string; span?: PointSourceSpan }
198
- | { kind: "setTo"; target: string; value: PointSemanticExpression; span?: PointSourceSpan };
199
-
200
- export interface PointSemanticTypeExpression {
201
- kind: "typeRef";
202
- name: string;
203
- args: PointSemanticTypeExpression[];
204
- span?: PointSourceSpan;
205
- }
206
-
207
- export type PointSemanticExpression =
208
- | { kind: "literal"; value: string | number | boolean | null; span?: PointSourceSpan }
209
- | { kind: "name"; label: string; span?: PointSourceSpan }
210
- | { kind: "property"; target: PointSemanticExpression; label: string; span?: PointSourceSpan }
211
- | { kind: "list"; items: PointSemanticExpression[]; span?: PointSourceSpan }
212
- | { kind: "record"; fields: PointSemanticRecordLiteralField[]; span?: PointSourceSpan }
213
- | { kind: "call"; callee: string; args: PointSemanticExpression[]; span?: PointSourceSpan }
214
- | { kind: "await"; value: PointSemanticExpression; span?: PointSourceSpan }
215
- | { kind: "error"; message: string; span?: PointSourceSpan }
216
- | {
217
- kind: "binary";
218
- operator: PointSemanticBinaryOperator;
219
- left: PointSemanticExpression;
220
- right: PointSemanticExpression;
221
- span?: PointSourceSpan;
222
- };
223
-
224
- export interface PointSemanticRecordLiteralField {
225
- label: string;
226
- value: PointSemanticExpression;
227
- span?: PointSourceSpan;
228
- }
229
-
230
- export type PointSemanticBinaryOperator = "+" | "-" | "*" | "/" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "and" | "or";
1
+ import type { PointSourceSpan } from "../core/ast.ts";
2
+
3
+ export interface PointSemanticProgram {
4
+ kind: "semanticProgram";
5
+ module?: string;
6
+ uses: PointSemanticUseDeclaration[];
7
+ declarations: PointSemanticDeclaration[];
8
+ span?: PointSourceSpan;
9
+ }
10
+
11
+ export interface PointSemanticUseDeclaration {
12
+ kind: "use";
13
+ moduleName: string;
14
+ from?: string;
15
+ span?: PointSourceSpan;
16
+ }
17
+
18
+ export type PointSemanticDeclaration =
19
+ | PointSemanticRecordDeclaration
20
+ | PointSemanticCalculationDeclaration
21
+ | PointSemanticRuleDeclaration
22
+ | PointSemanticLabelDeclaration
23
+ | PointSemanticExternalDeclaration
24
+ | PointSemanticActionDeclaration
25
+ | PointSemanticPolicyDeclaration
26
+ | PointSemanticViewDeclaration
27
+ | PointSemanticRouteDeclaration
28
+ | PointSemanticWorkflowDeclaration
29
+ | PointSemanticCommandDeclaration;
30
+
31
+ export interface PointSemanticRecordDeclaration {
32
+ kind: "record";
33
+ name: string;
34
+ fields: PointSemanticField[];
35
+ span?: PointSourceSpan;
36
+ }
37
+
38
+ export interface PointSemanticField {
39
+ label: string;
40
+ type: PointSemanticTypeExpression;
41
+ span?: PointSourceSpan;
42
+ }
43
+
44
+ export interface PointSemanticBinding {
45
+ label: string;
46
+ type: PointSemanticTypeExpression;
47
+ span?: PointSourceSpan;
48
+ }
49
+
50
+ export interface PointSemanticOutputBinding {
51
+ name: string;
52
+ type: PointSemanticTypeExpression;
53
+ span?: PointSourceSpan;
54
+ }
55
+
56
+ export interface PointSemanticCalculationDeclaration {
57
+ kind: "calculation";
58
+ name: string;
59
+ inputs: PointSemanticBinding[];
60
+ output: PointSemanticOutputBinding;
61
+ body: PointSemanticCalculationStatement[];
62
+ span?: PointSourceSpan;
63
+ }
64
+
65
+ export interface PointSemanticRuleDeclaration {
66
+ kind: "rule";
67
+ name: string;
68
+ inputs: PointSemanticBinding[];
69
+ output: PointSemanticOutputBinding;
70
+ body: PointSemanticRuleStatement[];
71
+ span?: PointSourceSpan;
72
+ }
73
+
74
+ export interface PointSemanticLabelDeclaration {
75
+ kind: "label";
76
+ name: string;
77
+ inputs: PointSemanticBinding[];
78
+ output: PointSemanticOutputBinding;
79
+ body: PointSemanticLabelStatement[];
80
+ span?: PointSourceSpan;
81
+ }
82
+
83
+ export interface PointSemanticExternalDeclaration {
84
+ kind: "external";
85
+ name: string;
86
+ functions: PointSemanticExternalFunction[];
87
+ span?: PointSourceSpan;
88
+ }
89
+
90
+ export interface PointSemanticExternalFunction {
91
+ label: string;
92
+ params: PointSemanticBinding[];
93
+ returnType: PointSemanticTypeExpression;
94
+ from: string;
95
+ importAs?: string;
96
+ span?: PointSourceSpan;
97
+ }
98
+
99
+ export interface PointSemanticActionDeclaration {
100
+ kind: "action";
101
+ name: string;
102
+ inputs: PointSemanticBinding[];
103
+ output: PointSemanticOutputBinding;
104
+ touches: string[];
105
+ body: PointSemanticActionStatement[];
106
+ span?: PointSourceSpan;
107
+ }
108
+
109
+ export interface PointSemanticPolicyDeclaration {
110
+ kind: "policy";
111
+ name: string;
112
+ inputs: PointSemanticBinding[];
113
+ body: PointSemanticPolicyStatement[];
114
+ span?: PointSourceSpan;
115
+ }
116
+
117
+ export interface PointSemanticViewDeclaration {
118
+ kind: "view";
119
+ name: string;
120
+ inputs: PointSemanticBinding[];
121
+ output: PointSemanticOutputBinding;
122
+ body: PointSemanticViewStatement[];
123
+ span?: PointSourceSpan;
124
+ }
125
+
126
+ export interface PointSemanticRouteDeclaration {
127
+ kind: "route";
128
+ name: string;
129
+ method: string;
130
+ path: string;
131
+ inputs: PointSemanticBinding[];
132
+ output: PointSemanticOutputBinding;
133
+ body: PointSemanticRouteStatement[];
134
+ span?: PointSourceSpan;
135
+ }
136
+
137
+ export interface PointSemanticWorkflowDeclaration {
138
+ kind: "workflow";
139
+ name: string;
140
+ inputs: PointSemanticBinding[];
141
+ output: PointSemanticOutputBinding;
142
+ body: PointSemanticWorkflowStatement[];
143
+ span?: PointSourceSpan;
144
+ }
145
+
146
+ export interface PointSemanticCommandDeclaration {
147
+ kind: "command";
148
+ name: string;
149
+ inputs: PointSemanticBinding[];
150
+ output: PointSemanticOutputBinding;
151
+ body: PointSemanticCommandStatement[];
152
+ span?: PointSourceSpan;
153
+ }
154
+
155
+ export type PointSemanticCalculationStatement =
156
+ | { kind: "assignIs"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
157
+ | { kind: "startsAt"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
158
+ | { kind: "startsAs"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
159
+ | { kind: "forEach"; item: string; iterable: PointSemanticExpression; body: PointSemanticMutationStatement[]; span?: PointSourceSpan }
160
+ | PointSemanticMutationStatement
161
+ | { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
162
+
163
+ export type PointSemanticRuleStatement =
164
+ | { kind: "startsAt"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
165
+ | { kind: "addWhen"; amount: PointSemanticExpression; condition: PointSemanticExpression; span?: PointSourceSpan }
166
+ | { kind: "forEach"; item: string; iterable: PointSemanticExpression; body: PointSemanticMutationStatement[]; span?: PointSourceSpan }
167
+ | PointSemanticMutationStatement
168
+ | { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
169
+
170
+ export type PointSemanticLabelStatement =
171
+ | { kind: "whenReturn"; condition: PointSemanticExpression; value: PointSemanticExpression; span?: PointSourceSpan }
172
+ | { kind: "otherwiseReturn"; value: PointSemanticExpression; span?: PointSourceSpan };
173
+
174
+ export type PointSemanticActionStatement =
175
+ | { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan }
176
+ | { kind: "expression"; value: PointSemanticExpression; span?: PointSourceSpan };
177
+
178
+ export type PointSemanticPolicyStatement =
179
+ | { kind: "allow"; condition: PointSemanticExpression; span?: PointSourceSpan }
180
+ | { kind: "deny"; condition: PointSemanticExpression; span?: PointSourceSpan }
181
+ | { kind: "require"; condition: PointSemanticExpression; span?: PointSourceSpan };
182
+
183
+ export type PointSemanticViewStatement =
184
+ | { kind: "render"; value: PointSemanticExpression; span?: PointSourceSpan }
185
+ | { kind: "whenRender"; condition: PointSemanticExpression; value: PointSemanticExpression; span?: PointSourceSpan };
186
+
187
+ export type PointSemanticRouteStatement = { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
188
+
189
+ export type PointSemanticWorkflowStatement =
190
+ | { kind: "step"; name: string; value: PointSemanticExpression; span?: PointSourceSpan }
191
+ | { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
192
+
193
+ export type PointSemanticCommandStatement = { kind: "return"; value: PointSemanticExpression; span?: PointSourceSpan };
194
+
195
+ export type PointSemanticMutationStatement =
196
+ | { kind: "addTo"; amount: PointSemanticExpression; target: string; span?: PointSourceSpan }
197
+ | { kind: "subtractFrom"; amount: PointSemanticExpression; target: string; span?: PointSourceSpan }
198
+ | { kind: "setTo"; target: string; value: PointSemanticExpression; span?: PointSourceSpan };
199
+
200
+ export interface PointSemanticTypeExpression {
201
+ kind: "typeRef";
202
+ name: string;
203
+ args: PointSemanticTypeExpression[];
204
+ span?: PointSourceSpan;
205
+ }
206
+
207
+ export type PointSemanticExpression =
208
+ | { kind: "literal"; value: string | number | boolean | null; span?: PointSourceSpan }
209
+ | { kind: "name"; label: string; span?: PointSourceSpan }
210
+ | { kind: "property"; target: PointSemanticExpression; label: string; span?: PointSourceSpan }
211
+ | { kind: "list"; items: PointSemanticExpression[]; span?: PointSourceSpan }
212
+ | { kind: "record"; fields: PointSemanticRecordLiteralField[]; span?: PointSourceSpan }
213
+ | { kind: "call"; callee: string; args: PointSemanticExpression[]; span?: PointSourceSpan }
214
+ | { kind: "await"; value: PointSemanticExpression; span?: PointSourceSpan }
215
+ | { kind: "error"; message: string; span?: PointSourceSpan }
216
+ | {
217
+ kind: "binary";
218
+ operator: PointSemanticBinaryOperator;
219
+ left: PointSemanticExpression;
220
+ right: PointSemanticExpression;
221
+ span?: PointSourceSpan;
222
+ };
223
+
224
+ export interface PointSemanticRecordLiteralField {
225
+ label: string;
226
+ value: PointSemanticExpression;
227
+ span?: PointSourceSpan;
228
+ }
229
+
230
+ export type PointSemanticBinaryOperator = "+" | "-" | "*" | "/" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "and" | "or";
@@ -1,51 +1,51 @@
1
- const CALLABLE_KEYWORDS = [
2
- "calculation",
3
- "rule",
4
- "label",
5
- "action",
6
- "view",
7
- "route",
8
- "workflow",
9
- "command",
10
- ] as const;
11
-
12
- export function collectSemanticCallables(source: string): string[] {
13
- const callables = new Set<string>();
14
- const lines = source.split(/\r?\n/);
15
- let index = 0;
16
- while (index < lines.length) {
17
- const trimmed = (lines[index] ?? "").trim();
18
- if (trimmed.startsWith("external ")) {
19
- const body = collectBody(lines, index + 1);
20
- for (const line of body.lines) {
21
- const match = line.match(/^(.+)\(/);
22
- if (match) callables.add(match[1]?.trim() ?? "");
23
- }
24
- index = body.next;
25
- continue;
26
- }
27
- for (const keyword of CALLABLE_KEYWORDS) {
28
- if (trimmed.startsWith(`${keyword} `)) {
29
- callables.add(trimmed.slice(keyword.length + 1).trim());
30
- }
31
- }
32
- index += 1;
33
- }
34
- return [...callables];
35
- }
36
-
37
- function collectBody(lines: string[], start: number): { lines: string[]; next: number } {
38
- const body: string[] = [];
39
- let index = start;
40
- for (; index < lines.length; index += 1) {
41
- const trimmed = (lines[index] ?? "").trim();
42
- if (!trimmed) continue;
43
- if (isTopLevel(trimmed)) break;
44
- body.push(trimmed);
45
- }
46
- return { lines: body, next: index };
47
- }
48
-
49
- function isTopLevel(line: string): boolean {
50
- return /^(module|use|record|calculation|rule|label|external|action|policy|view|route|workflow|command)\s+/.test(line);
51
- }
1
+ const CALLABLE_KEYWORDS = [
2
+ "calculation",
3
+ "rule",
4
+ "label",
5
+ "action",
6
+ "view",
7
+ "route",
8
+ "workflow",
9
+ "command",
10
+ ] as const;
11
+
12
+ export function collectSemanticCallables(source: string): string[] {
13
+ const callables = new Set<string>();
14
+ const lines = source.split(/\r?\n/);
15
+ let index = 0;
16
+ while (index < lines.length) {
17
+ const trimmed = (lines[index] ?? "").trim();
18
+ if (trimmed.startsWith("external ")) {
19
+ const body = collectBody(lines, index + 1);
20
+ for (const line of body.lines) {
21
+ const match = line.match(/^(.+)\(/);
22
+ if (match) callables.add(match[1]?.trim() ?? "");
23
+ }
24
+ index = body.next;
25
+ continue;
26
+ }
27
+ for (const keyword of CALLABLE_KEYWORDS) {
28
+ if (trimmed.startsWith(`${keyword} `)) {
29
+ callables.add(trimmed.slice(keyword.length + 1).trim());
30
+ }
31
+ }
32
+ index += 1;
33
+ }
34
+ return [...callables];
35
+ }
36
+
37
+ function collectBody(lines: string[], start: number): { lines: string[]; next: number } {
38
+ const body: string[] = [];
39
+ let index = start;
40
+ for (; index < lines.length; index += 1) {
41
+ const trimmed = (lines[index] ?? "").trim();
42
+ if (!trimmed) continue;
43
+ if (isTopLevel(trimmed)) break;
44
+ body.push(trimmed);
45
+ }
46
+ return { lines: body, next: index };
47
+ }
48
+
49
+ function isTopLevel(line: string): boolean {
50
+ return /^(module|use|record|calculation|rule|label|external|action|policy|view|route|workflow|command)\s+/.test(line);
51
+ }