@forthic/interp 0.15.0 → 0.16.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.
- package/dist/cjs/forthic/errors.d.ts +14 -12
- package/dist/cjs/forthic/errors.js +31 -23
- package/dist/cjs/forthic/errors.js.map +1 -1
- package/dist/cjs/forthic/global_module.d.ts +1 -0
- package/dist/cjs/forthic/global_module.js +6 -59
- package/dist/cjs/forthic/global_module.js.map +1 -1
- package/dist/cjs/forthic/interpreter.js +1 -1
- package/dist/cjs/forthic/interpreter.js.map +1 -1
- package/dist/cjs/forthic/module.js +2 -2
- package/dist/cjs/forthic/module.js.map +1 -1
- package/dist/cjs/forthic/utils.d.ts +2 -0
- package/dist/cjs/forthic/utils.js +112 -0
- package/dist/cjs/forthic/utils.js.map +1 -1
- package/dist/esm/forthic/errors.d.ts +14 -12
- package/dist/esm/forthic/errors.js +31 -23
- package/dist/esm/forthic/errors.js.map +1 -1
- package/dist/esm/forthic/global_module.d.ts +1 -0
- package/dist/esm/forthic/global_module.js +7 -60
- package/dist/esm/forthic/global_module.js.map +1 -1
- package/dist/esm/forthic/interpreter.js +1 -1
- package/dist/esm/forthic/interpreter.js.map +1 -1
- package/dist/esm/forthic/module.js +2 -2
- package/dist/esm/forthic/module.js.map +1 -1
- package/dist/esm/forthic/utils.d.ts +2 -0
- package/dist/esm/forthic/utils.js +110 -0
- package/dist/esm/forthic/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ exports.to_string = to_string;
|
|
|
10
10
|
exports.to_date = to_date;
|
|
11
11
|
exports.date_to_string = date_to_string;
|
|
12
12
|
exports.date_to_int = date_to_int;
|
|
13
|
+
exports.to_literal_date = to_literal_date;
|
|
14
|
+
exports.to_zoned_datetime = to_zoned_datetime;
|
|
13
15
|
const temporal_polyfill_1 = require("temporal-polyfill");
|
|
14
16
|
function is_string(value) {
|
|
15
17
|
return typeof value === "string" || value instanceof String;
|
|
@@ -77,4 +79,114 @@ function date_to_int(date) {
|
|
|
77
79
|
const result = parseInt(digits);
|
|
78
80
|
return result;
|
|
79
81
|
}
|
|
82
|
+
function to_literal_date(str_val, timezone = "UTC") {
|
|
83
|
+
// --------------------
|
|
84
|
+
// Handle date format strings like "YYYY-MM-DD" or "YYYY-MM-03" or "YYYY-02-03" or "2025-02-03"
|
|
85
|
+
let year;
|
|
86
|
+
let month;
|
|
87
|
+
let day;
|
|
88
|
+
const date_parts = str_val.split("-");
|
|
89
|
+
const zonedDateTime = temporal_polyfill_1.Temporal.Now.zonedDateTimeISO(timezone);
|
|
90
|
+
// Case 1: If time is like "YYYY-MM-DD"
|
|
91
|
+
if (str_val.match(/^YYYY-MM-DD$/)) {
|
|
92
|
+
year = zonedDateTime.year;
|
|
93
|
+
month = zonedDateTime.month;
|
|
94
|
+
day = zonedDateTime.day;
|
|
95
|
+
} // Case 2: If time is like "YYYY-MM-03"
|
|
96
|
+
else if (str_val.match(/^YYYY-MM-\d{2}$/)) {
|
|
97
|
+
year = zonedDateTime.year;
|
|
98
|
+
month = zonedDateTime.month;
|
|
99
|
+
day = parseInt(date_parts[2]);
|
|
100
|
+
} // Case 3: If time is like "YYYY-02-03"
|
|
101
|
+
else if (str_val.match(/^YYYY-\d{2}-\d{2}$/)) {
|
|
102
|
+
year = zonedDateTime.year;
|
|
103
|
+
month = parseInt(date_parts[1]);
|
|
104
|
+
day = parseInt(date_parts[2]);
|
|
105
|
+
} // Case 4: If time is like "2025-02-03"
|
|
106
|
+
else if (str_val.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
107
|
+
year = parseInt(date_parts[0]);
|
|
108
|
+
month = parseInt(date_parts[1]);
|
|
109
|
+
day = parseInt(date_parts[2]);
|
|
110
|
+
} // Case 5: If time is like "2025-MM-DD"
|
|
111
|
+
else if (str_val.match(/^\d{4}-MM-DD$/)) {
|
|
112
|
+
year = parseInt(date_parts[0]);
|
|
113
|
+
month = zonedDateTime.month;
|
|
114
|
+
day = zonedDateTime.day;
|
|
115
|
+
} // Case 6: If time is like "2025-02-DD"
|
|
116
|
+
else if (str_val.match(/^\d{4}-\d{2}-DD$/)) {
|
|
117
|
+
year = parseInt(date_parts[0]);
|
|
118
|
+
month = parseInt(date_parts[1]);
|
|
119
|
+
day = zonedDateTime.day;
|
|
120
|
+
} // Case 7: If time is like "2025-MM-03"
|
|
121
|
+
else if (str_val.match(/^\d{4}-MM-\d{2}$/)) {
|
|
122
|
+
year = parseInt(date_parts[0]);
|
|
123
|
+
month = zonedDateTime.month;
|
|
124
|
+
day = parseInt(date_parts[2]);
|
|
125
|
+
} // Case 8: If time is like "YYYY-03-DD"
|
|
126
|
+
else if (str_val.match(/^YYYY-\d{2}-DD$/)) {
|
|
127
|
+
year = zonedDateTime.year;
|
|
128
|
+
month = parseInt(date_parts[1]);
|
|
129
|
+
day = zonedDateTime.day;
|
|
130
|
+
} // Otherwise, return null
|
|
131
|
+
else {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const result = temporal_polyfill_1.Temporal.PlainDate.from({
|
|
135
|
+
year: year,
|
|
136
|
+
month: month,
|
|
137
|
+
day: day,
|
|
138
|
+
});
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
function to_zoned_datetime(str_val, tz = "UTC") {
|
|
142
|
+
try {
|
|
143
|
+
// We're handling these cases:
|
|
144
|
+
// 2025-05-24T10:15 # Hours and minutes only, current timezone
|
|
145
|
+
// 2025-05-24T10:15:00 # Hours, minutes, seconds, current timezone
|
|
146
|
+
// 2025-05-24T10:15:00.123 # With milliseconds, current timezone
|
|
147
|
+
// 2025-05-24T10:15Z # Hours and minutes only, UTC
|
|
148
|
+
// 2025-05-24T10:15:00Z # Hours, minutes, seconds, UTC
|
|
149
|
+
// 2025-05-24T10:15:00.123Z # With milliseconds, UTC
|
|
150
|
+
// 2025-05-24T10:15:00-05:00 # With timezone offset
|
|
151
|
+
// 2025-05-24T10:15:00[America/New_York] # With timezone name (NOTE: This one doesn't work in raw Forthic because `[` and `]` are special characters)
|
|
152
|
+
const datetimeRegex = new RegExp([
|
|
153
|
+
'^',
|
|
154
|
+
'(?<datetime>\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2})', // Named group for date and time
|
|
155
|
+
'(?::(?<seconds>\\d{2}))?', // Named group for optional seconds
|
|
156
|
+
'(?:\\.(?<milliseconds>\\d{3}))?', // Named group for optional milliseconds
|
|
157
|
+
'(?<timezone>Z|[+-]\\d{2}:\\d{2})?', // Named group for simple timezone (Z or offset)
|
|
158
|
+
'(?<bracketedTimezone>\\[[A-Za-z][A-Za-z0-9_/]+\\])?', // Named group for bracketed timezone
|
|
159
|
+
'$'
|
|
160
|
+
].join(''));
|
|
161
|
+
const match = str_val.match(datetimeRegex);
|
|
162
|
+
if (!match)
|
|
163
|
+
return null;
|
|
164
|
+
// Extract regex groups
|
|
165
|
+
const datetime = match.groups?.datetime;
|
|
166
|
+
const seconds = match.groups?.seconds || "00";
|
|
167
|
+
const milliseconds = match.groups?.milliseconds || "000";
|
|
168
|
+
const timezone = match.groups?.timezone;
|
|
169
|
+
const bracketedTimezone = match.groups?.bracketedTimezone;
|
|
170
|
+
const datetimeStr = `${datetime}${seconds ? `:${seconds}` : ''}${milliseconds ? `.${milliseconds}` : ''}`;
|
|
171
|
+
let result = null;
|
|
172
|
+
// If timezone is specified in brackets, use it
|
|
173
|
+
if (bracketedTimezone) {
|
|
174
|
+
result = temporal_polyfill_1.Temporal.ZonedDateTime.from(`${datetimeStr}${bracketedTimezone}`);
|
|
175
|
+
}
|
|
176
|
+
// If we have a Z or a timezone offset, use that but convert to UTC
|
|
177
|
+
else if (timezone) {
|
|
178
|
+
const date = new Date(datetimeStr + timezone);
|
|
179
|
+
result = temporal_polyfill_1.Temporal.Instant.fromEpochMilliseconds(date.getTime()).toZonedDateTime({ timeZone: "UTC", calendar: 'iso8601' });
|
|
180
|
+
}
|
|
181
|
+
// Otherwise, use the current timezone
|
|
182
|
+
else {
|
|
183
|
+
const date = new Date(datetimeStr);
|
|
184
|
+
result = temporal_polyfill_1.Temporal.Instant.fromEpochMilliseconds(date.getTime()).toZonedDateTime({ timeZone: tz, calendar: 'iso8601' });
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
80
192
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/forthic/utils.ts"],"names":[],"mappings":";;AAEA,8BAEG;AAED,8BAGC;AAED,8BAEC;AAED,4BAEC;AAED,0CAKC;AAED,oCAEC;AAED,8BAEC;AAGD,0BAcC;AAED,wCAcC;AAED,kCAKC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/forthic/utils.ts"],"names":[],"mappings":";;AAEA,8BAEG;AAED,8BAGC;AAED,8BAEC;AAED,4BAEC;AAED,0CAKC;AAED,oCAEC;AAED,8BAEC;AAGD,0BAcC;AAED,wCAcC;AAED,kCAKC;AAGH,0CA4DC;AAED,8CAsDC;AA/LD,yDAA6C;AAE7C,SAAgB,SAAS,CAAC,KAAU;IAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,CAAC;AAC9D,CAAC;AAED,SAAgB,SAAS,CAAC,KAAU;IAClC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED,SAAgB,SAAS,CAAC,KAAU;IAClC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED,SAAgB,QAAQ,CAAC,KAAU;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;A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qBAAqB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5H,CAAC;QACD,sCAAsC;aACjC,CAAC;YACJ,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;YACnC,MAAM,GAAG,4BAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACzH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -3,46 +3,48 @@ export declare class ForthicError extends Error {
|
|
|
3
3
|
private forthic;
|
|
4
4
|
private note;
|
|
5
5
|
private location?;
|
|
6
|
-
|
|
6
|
+
cause?: Error;
|
|
7
|
+
constructor(forthic: string, note: string, location?: CodeLocation, cause?: Error);
|
|
7
8
|
getDescription(): string;
|
|
8
9
|
getLocation(): CodeLocation;
|
|
9
10
|
getForthic(): string;
|
|
10
11
|
getNote(): string;
|
|
11
12
|
getMessage(): string;
|
|
13
|
+
getCause(): Error | undefined;
|
|
12
14
|
}
|
|
13
15
|
export declare class UnknownWordError extends ForthicError {
|
|
14
16
|
private word;
|
|
15
|
-
constructor(forthic: string, word: string, location?: CodeLocation);
|
|
17
|
+
constructor(forthic: string, word: string, location?: CodeLocation, cause?: Error);
|
|
16
18
|
getWord(): string;
|
|
17
19
|
}
|
|
18
20
|
export declare class InvalidVariableNameError extends ForthicError {
|
|
19
21
|
private var_name;
|
|
20
22
|
private addl_note;
|
|
21
|
-
constructor(forthic: string, var_name: string, addl_note: string, location?: CodeLocation);
|
|
23
|
+
constructor(forthic: string, var_name: string, addl_note: string, location?: CodeLocation, cause?: Error);
|
|
22
24
|
getVarName(): string;
|
|
23
25
|
getAddlNote(): string;
|
|
24
26
|
}
|
|
25
27
|
export declare class UnknownScreenError extends ForthicError {
|
|
26
28
|
private screen_name;
|
|
27
|
-
constructor(forthic: string, screen_name: string, location?: CodeLocation);
|
|
29
|
+
constructor(forthic: string, screen_name: string, location?: CodeLocation, cause?: Error);
|
|
28
30
|
getScreenName(): string;
|
|
29
31
|
}
|
|
30
32
|
export declare class UnknownModuleError extends ForthicError {
|
|
31
33
|
private module_name;
|
|
32
|
-
constructor(forthic: string, module_name: string, location?: CodeLocation);
|
|
34
|
+
constructor(forthic: string, module_name: string, location?: CodeLocation, cause?: Error);
|
|
33
35
|
getModuleName(): string;
|
|
34
36
|
}
|
|
35
37
|
export declare class TooManyAttemptsError extends ForthicError {
|
|
36
38
|
private num_attempts;
|
|
37
39
|
private max_attempts;
|
|
38
|
-
constructor(forthic: string, num_attempts: number, max_attempts: number, location?: CodeLocation);
|
|
40
|
+
constructor(forthic: string, num_attempts: number, max_attempts: number, location?: CodeLocation, cause?: Error);
|
|
39
41
|
getNumAttempts(): number;
|
|
40
42
|
getMaxAttempts(): number;
|
|
41
43
|
}
|
|
42
44
|
export declare class WordExecutionError extends ForthicError {
|
|
43
45
|
private word_name;
|
|
44
46
|
private error;
|
|
45
|
-
constructor(forthic: string, word_name: string, error: Error, location?: CodeLocation);
|
|
47
|
+
constructor(forthic: string, word_name: string, error: Error, location?: CodeLocation, cause?: Error);
|
|
46
48
|
getWordName(): string;
|
|
47
49
|
getError(): Error;
|
|
48
50
|
getRootError(): Error;
|
|
@@ -50,23 +52,23 @@ export declare class WordExecutionError extends ForthicError {
|
|
|
50
52
|
export declare class ModuleError extends ForthicError {
|
|
51
53
|
private module_name;
|
|
52
54
|
private error;
|
|
53
|
-
constructor(forthic: string, module_name: string, error: Error, location?: CodeLocation);
|
|
55
|
+
constructor(forthic: string, module_name: string, error: Error, location?: CodeLocation, cause?: Error);
|
|
54
56
|
getModuleName(): string;
|
|
55
57
|
getError(): Error;
|
|
56
58
|
}
|
|
57
59
|
export declare class StackUnderflowError extends ForthicError {
|
|
58
|
-
constructor(forthic: string, location?: CodeLocation);
|
|
60
|
+
constructor(forthic: string, location?: CodeLocation, cause?: Error);
|
|
59
61
|
}
|
|
60
62
|
export declare class UnknownTokenError extends ForthicError {
|
|
61
63
|
private token;
|
|
62
|
-
constructor(forthic: string, token: string, location?: CodeLocation);
|
|
64
|
+
constructor(forthic: string, token: string, location?: CodeLocation, cause?: Error);
|
|
63
65
|
getToken(): string;
|
|
64
66
|
}
|
|
65
67
|
export declare class MissingSemicolonError extends ForthicError {
|
|
66
|
-
constructor(forthic: string, location?: CodeLocation);
|
|
68
|
+
constructor(forthic: string, location?: CodeLocation, cause?: Error);
|
|
67
69
|
}
|
|
68
70
|
export declare class ExtraSemicolonError extends ForthicError {
|
|
69
|
-
constructor(forthic: string, location?: CodeLocation);
|
|
71
|
+
constructor(forthic: string, location?: CodeLocation, cause?: Error);
|
|
70
72
|
}
|
|
71
73
|
export declare class IntentionalStopError extends Error {
|
|
72
74
|
constructor(message: string);
|
|
@@ -2,12 +2,17 @@ export class ForthicError extends Error {
|
|
|
2
2
|
forthic;
|
|
3
3
|
note;
|
|
4
4
|
location;
|
|
5
|
-
|
|
5
|
+
cause;
|
|
6
|
+
constructor(forthic, note, location, cause) {
|
|
6
7
|
const message = `${note}`;
|
|
7
8
|
super(message);
|
|
8
9
|
this.forthic = forthic;
|
|
9
10
|
this.note = note;
|
|
10
11
|
this.location = location;
|
|
12
|
+
this.cause = cause;
|
|
13
|
+
if (cause) {
|
|
14
|
+
this.cause = cause;
|
|
15
|
+
}
|
|
11
16
|
}
|
|
12
17
|
getDescription() {
|
|
13
18
|
return get_error_description(this.forthic, this);
|
|
@@ -24,15 +29,18 @@ export class ForthicError extends Error {
|
|
|
24
29
|
getMessage() {
|
|
25
30
|
return this.message;
|
|
26
31
|
}
|
|
32
|
+
getCause() {
|
|
33
|
+
return this.cause;
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
// ============================================================
|
|
29
37
|
// Interpreter errors
|
|
30
38
|
// Interpreter couldn't find word in dictionaries
|
|
31
39
|
export class UnknownWordError extends ForthicError {
|
|
32
40
|
word;
|
|
33
|
-
constructor(forthic, word, location) {
|
|
41
|
+
constructor(forthic, word, location, cause) {
|
|
34
42
|
const note = `Unknown word: ${word}`;
|
|
35
|
-
super(forthic, note, location);
|
|
43
|
+
super(forthic, note, location, cause);
|
|
36
44
|
this.word = word;
|
|
37
45
|
this.name = "UnknownWordError";
|
|
38
46
|
}
|
|
@@ -44,9 +52,9 @@ export class UnknownWordError extends ForthicError {
|
|
|
44
52
|
export class InvalidVariableNameError extends ForthicError {
|
|
45
53
|
var_name;
|
|
46
54
|
addl_note;
|
|
47
|
-
constructor(forthic, var_name, addl_note, location) {
|
|
55
|
+
constructor(forthic, var_name, addl_note, location, cause) {
|
|
48
56
|
const note = `Invalid variable name: ${var_name}(${addl_note})`;
|
|
49
|
-
super(forthic, note, location);
|
|
57
|
+
super(forthic, note, location, cause);
|
|
50
58
|
this.var_name = var_name;
|
|
51
59
|
this.addl_note = addl_note;
|
|
52
60
|
this.name = "InvalidVariableNameError";
|
|
@@ -61,9 +69,9 @@ export class InvalidVariableNameError extends ForthicError {
|
|
|
61
69
|
// Interpreter couldn't find screen
|
|
62
70
|
export class UnknownScreenError extends ForthicError {
|
|
63
71
|
screen_name;
|
|
64
|
-
constructor(forthic, screen_name, location) {
|
|
72
|
+
constructor(forthic, screen_name, location, cause) {
|
|
65
73
|
const note = `Unknown screen: ${screen_name}`;
|
|
66
|
-
super(forthic, note, location);
|
|
74
|
+
super(forthic, note, location, cause);
|
|
67
75
|
this.screen_name = screen_name;
|
|
68
76
|
this.name = "UnknownScreenError";
|
|
69
77
|
}
|
|
@@ -74,9 +82,9 @@ export class UnknownScreenError extends ForthicError {
|
|
|
74
82
|
// Interpreter couldn't find module
|
|
75
83
|
export class UnknownModuleError extends ForthicError {
|
|
76
84
|
module_name;
|
|
77
|
-
constructor(forthic, module_name, location) {
|
|
85
|
+
constructor(forthic, module_name, location, cause) {
|
|
78
86
|
const note = `Unknown module: ${module_name}`;
|
|
79
|
-
super(forthic, note, location);
|
|
87
|
+
super(forthic, note, location, cause);
|
|
80
88
|
this.module_name = module_name;
|
|
81
89
|
this.name = "UnknownModuleError";
|
|
82
90
|
}
|
|
@@ -87,9 +95,9 @@ export class UnknownModuleError extends ForthicError {
|
|
|
87
95
|
export class TooManyAttemptsError extends ForthicError {
|
|
88
96
|
num_attempts;
|
|
89
97
|
max_attempts;
|
|
90
|
-
constructor(forthic, num_attempts, max_attempts, location) {
|
|
98
|
+
constructor(forthic, num_attempts, max_attempts, location, cause) {
|
|
91
99
|
const note = `Too many recovery attempts: ${num_attempts} of ${max_attempts}`;
|
|
92
|
-
super(forthic, note, location);
|
|
100
|
+
super(forthic, note, location, cause);
|
|
93
101
|
this.num_attempts = num_attempts;
|
|
94
102
|
this.max_attempts = max_attempts;
|
|
95
103
|
this.name = "TooManyAttemptsError";
|
|
@@ -104,9 +112,9 @@ export class TooManyAttemptsError extends ForthicError {
|
|
|
104
112
|
export class WordExecutionError extends ForthicError {
|
|
105
113
|
word_name;
|
|
106
114
|
error;
|
|
107
|
-
constructor(forthic, word_name, error, location) {
|
|
115
|
+
constructor(forthic, word_name, error, location, cause) {
|
|
108
116
|
const note = `(${error.message}) when executing word ${word_name}`;
|
|
109
|
-
super(forthic, note, location);
|
|
117
|
+
super(forthic, note, location, cause);
|
|
110
118
|
this.word_name = word_name;
|
|
111
119
|
this.error = error;
|
|
112
120
|
this.name = "WordExecutionError";
|
|
@@ -127,9 +135,9 @@ export class WordExecutionError extends ForthicError {
|
|
|
127
135
|
export class ModuleError extends ForthicError {
|
|
128
136
|
module_name;
|
|
129
137
|
error;
|
|
130
|
-
constructor(forthic, module_name, error, location) {
|
|
138
|
+
constructor(forthic, module_name, error, location, cause) {
|
|
131
139
|
const note = `Error in module ${module_name}`;
|
|
132
|
-
super(forthic, note, location);
|
|
140
|
+
super(forthic, note, location, cause);
|
|
133
141
|
this.module_name = module_name;
|
|
134
142
|
this.error = error;
|
|
135
143
|
this.name = "ModuleError";
|
|
@@ -142,17 +150,17 @@ export class ModuleError extends ForthicError {
|
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
152
|
export class StackUnderflowError extends ForthicError {
|
|
145
|
-
constructor(forthic, location) {
|
|
153
|
+
constructor(forthic, location, cause) {
|
|
146
154
|
const note = `Stack underflow`;
|
|
147
|
-
super(forthic, note, location);
|
|
155
|
+
super(forthic, note, location, cause);
|
|
148
156
|
this.name = "StackUnderflowError";
|
|
149
157
|
}
|
|
150
158
|
}
|
|
151
159
|
export class UnknownTokenError extends ForthicError {
|
|
152
160
|
token;
|
|
153
|
-
constructor(forthic, token, location) {
|
|
161
|
+
constructor(forthic, token, location, cause) {
|
|
154
162
|
const note = `(Should never happen) Unknown type of token: ${token}`;
|
|
155
|
-
super(forthic, note, location);
|
|
163
|
+
super(forthic, note, location, cause);
|
|
156
164
|
this.token = token;
|
|
157
165
|
this.name = "UnknownTokenError";
|
|
158
166
|
}
|
|
@@ -161,16 +169,16 @@ export class UnknownTokenError extends ForthicError {
|
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
171
|
export class MissingSemicolonError extends ForthicError {
|
|
164
|
-
constructor(forthic, location) {
|
|
172
|
+
constructor(forthic, location, cause) {
|
|
165
173
|
const note = `Definition was missing its semicolon`;
|
|
166
|
-
super(forthic, note, location);
|
|
174
|
+
super(forthic, note, location, cause);
|
|
167
175
|
this.name = "MissingSemicolonError";
|
|
168
176
|
}
|
|
169
177
|
}
|
|
170
178
|
export class ExtraSemicolonError extends ForthicError {
|
|
171
|
-
constructor(forthic, location) {
|
|
179
|
+
constructor(forthic, location, cause) {
|
|
172
180
|
const note = `Unexpected semicolon -- no definition in progress`;
|
|
173
|
-
super(forthic, note, location);
|
|
181
|
+
super(forthic, note, location, cause);
|
|
174
182
|
this.name = "ExtraSemicolonError";
|
|
175
183
|
}
|
|
176
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/forthic/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACf;IAAyB;IAAsB;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/forthic/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACf;IAAyB;IAAsB;IAAgC;IAAnG,YAAoB,OAAe,EAAU,IAAY,EAAU,QAAuB,EAAS,KAAa;QAC5G,MAAM,OAAO,GAAG,GAAG,IAAI,EAAE,CAAC;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,YAAO,GAAP,OAAO,CAAQ;QAAU,SAAI,GAAJ,IAAI,CAAQ;QAAU,aAAQ,GAAR,QAAQ,CAAe;QAAS,UAAK,GAAL,KAAK,CAAQ;QAI5G,IAAI,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACvB,CAAC;IACL,CAAC;IAED,cAAc;QACV,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,WAAW;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,UAAU;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,OAAO;QACH,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,UAAU;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;CACJ;AAED,+DAA+D;AAC/D,qBAAqB;AAErB,iDAAiD;AACjD,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IACX;IAArC,YAAY,OAAe,EAAU,IAAY,EAAE,QAAuB,EAA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,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;IAE5C,4DAA4D;IAC5D,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;IAE/B,2BAA2B;IAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAErD,6GAA6G;IAC7G,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IAErG,6DAA6D;IAC7D,MAAM,aAAa,GAAG,GAAG,YAAY,CAAC,OAAO,EAAE,YAAY,QAAQ,cAAc,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,UAAU,UAAU,CAAC;IACpJ,OAAO,aAAa,CAAC;AACzB,CAAC"}
|
|
@@ -11,6 +11,7 @@ export declare class GlobalModule extends Module {
|
|
|
11
11
|
to_int(str_val: string): number | null;
|
|
12
12
|
to_float(str_val: string): number | null;
|
|
13
13
|
to_literal_date(str_val: string): Temporal.PlainDate | null;
|
|
14
|
+
to_zoned_datetime(str_val: string): Temporal.ZonedDateTime | null;
|
|
14
15
|
to_time(str_val: string): Temporal.PlainTime | null;
|
|
15
16
|
make_element_word(element_name: string): (interp: Interpreter) => Promise<void>;
|
|
16
17
|
add_element_word(element_name: string): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Module, PushValueWord } from "./module";
|
|
2
|
-
import { is_array, is_record, is_string, pretty_print, to_date, date_to_string, date_to_int, } from "./utils";
|
|
2
|
+
import { is_array, is_record, is_string, pretty_print, to_date, date_to_string, date_to_int, to_literal_date, to_zoned_datetime, } from "./utils";
|
|
3
3
|
import { Temporal } from "temporal-polyfill";
|
|
4
4
|
import { MapWord } from "./global_module/map_word";
|
|
5
5
|
import { CodeLocation } from "./tokenizer";
|
|
@@ -25,6 +25,7 @@ export class GlobalModule extends Module {
|
|
|
25
25
|
this.literal_handlers = [
|
|
26
26
|
this.to_bool,
|
|
27
27
|
this.to_float,
|
|
28
|
+
this.to_zoned_datetime,
|
|
28
29
|
this.to_literal_date,
|
|
29
30
|
this.to_time,
|
|
30
31
|
this.to_int,
|
|
@@ -253,63 +254,10 @@ export class GlobalModule extends Module {
|
|
|
253
254
|
return result;
|
|
254
255
|
}
|
|
255
256
|
to_literal_date(str_val) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
let day;
|
|
261
|
-
const date_parts = str_val.split("-");
|
|
262
|
-
const zonedDateTime = Temporal.Now.zonedDateTimeISO(this.interp?.get_timezone() ?? "UTC");
|
|
263
|
-
// Case 1: If time is like "YYYY-MM-DD"
|
|
264
|
-
if (str_val.match(/^YYYY-MM-DD$/)) {
|
|
265
|
-
year = zonedDateTime.year;
|
|
266
|
-
month = zonedDateTime.month;
|
|
267
|
-
day = zonedDateTime.day;
|
|
268
|
-
} // Case 2: If time is like "YYYY-MM-03"
|
|
269
|
-
else if (str_val.match(/^YYYY-MM-\d{2}$/)) {
|
|
270
|
-
year = zonedDateTime.year;
|
|
271
|
-
month = zonedDateTime.month;
|
|
272
|
-
day = parseInt(date_parts[2]);
|
|
273
|
-
} // Case 3: If time is like "YYYY-02-03"
|
|
274
|
-
else if (str_val.match(/^YYYY-\d{2}-\d{2}$/)) {
|
|
275
|
-
year = zonedDateTime.year;
|
|
276
|
-
month = parseInt(date_parts[1]);
|
|
277
|
-
day = parseInt(date_parts[2]);
|
|
278
|
-
} // Case 4: If time is like "2025-02-03"
|
|
279
|
-
else if (str_val.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
280
|
-
year = parseInt(date_parts[0]);
|
|
281
|
-
month = parseInt(date_parts[1]);
|
|
282
|
-
day = parseInt(date_parts[2]);
|
|
283
|
-
} // Case 5: If time is like "2025-MM-DD"
|
|
284
|
-
else if (str_val.match(/^\d{4}-MM-DD$/)) {
|
|
285
|
-
year = parseInt(date_parts[0]);
|
|
286
|
-
month = zonedDateTime.month;
|
|
287
|
-
day = zonedDateTime.day;
|
|
288
|
-
} // Case 6: If time is like "2025-02-DD"
|
|
289
|
-
else if (str_val.match(/^\d{4}-\d{2}-DD$/)) {
|
|
290
|
-
year = parseInt(date_parts[0]);
|
|
291
|
-
month = parseInt(date_parts[1]);
|
|
292
|
-
day = zonedDateTime.day;
|
|
293
|
-
} // Case 7: If time is like "2025-MM-03"
|
|
294
|
-
else if (str_val.match(/^\d{4}-MM-\d{2}$/)) {
|
|
295
|
-
year = parseInt(date_parts[0]);
|
|
296
|
-
month = zonedDateTime.month;
|
|
297
|
-
day = parseInt(date_parts[2]);
|
|
298
|
-
} // Case 8: If time is like "YYYY-03-DD"
|
|
299
|
-
else if (str_val.match(/^YYYY-\d{2}-DD$/)) {
|
|
300
|
-
year = zonedDateTime.year;
|
|
301
|
-
month = parseInt(date_parts[1]);
|
|
302
|
-
day = zonedDateTime.day;
|
|
303
|
-
} // Otherwise, return null
|
|
304
|
-
else {
|
|
305
|
-
return null;
|
|
306
|
-
}
|
|
307
|
-
const result = Temporal.PlainDate.from({
|
|
308
|
-
year: year,
|
|
309
|
-
month: month,
|
|
310
|
-
day: day,
|
|
311
|
-
});
|
|
312
|
-
return result;
|
|
257
|
+
return to_literal_date(str_val, this.interp?.get_timezone() ?? "UTC");
|
|
258
|
+
}
|
|
259
|
+
to_zoned_datetime(str_val) {
|
|
260
|
+
return to_zoned_datetime(str_val);
|
|
313
261
|
}
|
|
314
262
|
to_time(str_val) {
|
|
315
263
|
const match = str_val.match(/(\d{1,2}):(\d{2})/);
|
|
@@ -1789,8 +1737,7 @@ export class GlobalModule extends Module {
|
|
|
1789
1737
|
// ( str -- datetime )
|
|
1790
1738
|
word_STR_to_DATETIME(interp) {
|
|
1791
1739
|
const s = interp.stack_pop();
|
|
1792
|
-
const
|
|
1793
|
-
const result = Temporal.Instant.fromEpochMilliseconds(date.getTime()).toZonedDateTime({ timeZone: interp.get_timezone(), calendar: "iso8601" });
|
|
1740
|
+
const result = to_zoned_datetime(s, interp.get_timezone());
|
|
1794
1741
|
interp.stack_push(result);
|
|
1795
1742
|
}
|
|
1796
1743
|
// ( str -- timestamp )
|