@forthic/interp 0.14.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.
@@ -1,48 +1,50 @@
1
- import { CodeLocation } from "./tokenizer";
1
+ import type { CodeLocation } from "./tokenizer";
2
2
  export declare class ForthicError extends Error {
3
3
  private forthic;
4
4
  private note;
5
5
  private location?;
6
- constructor(forthic: string, note: string, location?: CodeLocation);
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);
@@ -6,12 +6,17 @@ class ForthicError extends Error {
6
6
  forthic;
7
7
  note;
8
8
  location;
9
- constructor(forthic, note, location) {
9
+ cause;
10
+ constructor(forthic, note, location, cause) {
10
11
  const message = `${note}`;
11
12
  super(message);
12
13
  this.forthic = forthic;
13
14
  this.note = note;
14
15
  this.location = location;
16
+ this.cause = cause;
17
+ if (cause) {
18
+ this.cause = cause;
19
+ }
15
20
  }
16
21
  getDescription() {
17
22
  return get_error_description(this.forthic, this);
@@ -28,6 +33,9 @@ class ForthicError extends Error {
28
33
  getMessage() {
29
34
  return this.message;
30
35
  }
36
+ getCause() {
37
+ return this.cause;
38
+ }
31
39
  }
32
40
  exports.ForthicError = ForthicError;
33
41
  // ============================================================
@@ -35,9 +43,9 @@ exports.ForthicError = ForthicError;
35
43
  // Interpreter couldn't find word in dictionaries
36
44
  class UnknownWordError extends ForthicError {
37
45
  word;
38
- constructor(forthic, word, location) {
46
+ constructor(forthic, word, location, cause) {
39
47
  const note = `Unknown word: ${word}`;
40
- super(forthic, note, location);
48
+ super(forthic, note, location, cause);
41
49
  this.word = word;
42
50
  this.name = "UnknownWordError";
43
51
  }
@@ -50,9 +58,9 @@ exports.UnknownWordError = UnknownWordError;
50
58
  class InvalidVariableNameError extends ForthicError {
51
59
  var_name;
52
60
  addl_note;
53
- constructor(forthic, var_name, addl_note, location) {
61
+ constructor(forthic, var_name, addl_note, location, cause) {
54
62
  const note = `Invalid variable name: ${var_name}(${addl_note})`;
55
- super(forthic, note, location);
63
+ super(forthic, note, location, cause);
56
64
  this.var_name = var_name;
57
65
  this.addl_note = addl_note;
58
66
  this.name = "InvalidVariableNameError";
@@ -68,9 +76,9 @@ exports.InvalidVariableNameError = InvalidVariableNameError;
68
76
  // Interpreter couldn't find screen
69
77
  class UnknownScreenError extends ForthicError {
70
78
  screen_name;
71
- constructor(forthic, screen_name, location) {
79
+ constructor(forthic, screen_name, location, cause) {
72
80
  const note = `Unknown screen: ${screen_name}`;
73
- super(forthic, note, location);
81
+ super(forthic, note, location, cause);
74
82
  this.screen_name = screen_name;
75
83
  this.name = "UnknownScreenError";
76
84
  }
@@ -82,9 +90,9 @@ exports.UnknownScreenError = UnknownScreenError;
82
90
  // Interpreter couldn't find module
83
91
  class UnknownModuleError extends ForthicError {
84
92
  module_name;
85
- constructor(forthic, module_name, location) {
93
+ constructor(forthic, module_name, location, cause) {
86
94
  const note = `Unknown module: ${module_name}`;
87
- super(forthic, note, location);
95
+ super(forthic, note, location, cause);
88
96
  this.module_name = module_name;
89
97
  this.name = "UnknownModuleError";
90
98
  }
@@ -96,9 +104,9 @@ exports.UnknownModuleError = UnknownModuleError;
96
104
  class TooManyAttemptsError extends ForthicError {
97
105
  num_attempts;
98
106
  max_attempts;
99
- constructor(forthic, num_attempts, max_attempts, location) {
107
+ constructor(forthic, num_attempts, max_attempts, location, cause) {
100
108
  const note = `Too many recovery attempts: ${num_attempts} of ${max_attempts}`;
101
- super(forthic, note, location);
109
+ super(forthic, note, location, cause);
102
110
  this.num_attempts = num_attempts;
103
111
  this.max_attempts = max_attempts;
104
112
  this.name = "TooManyAttemptsError";
@@ -114,9 +122,9 @@ exports.TooManyAttemptsError = TooManyAttemptsError;
114
122
  class WordExecutionError extends ForthicError {
115
123
  word_name;
116
124
  error;
117
- constructor(forthic, word_name, error, location) {
125
+ constructor(forthic, word_name, error, location, cause) {
118
126
  const note = `(${error.message}) when executing word ${word_name}`;
119
- super(forthic, note, location);
127
+ super(forthic, note, location, cause);
120
128
  this.word_name = word_name;
121
129
  this.error = error;
122
130
  this.name = "WordExecutionError";
@@ -138,9 +146,9 @@ exports.WordExecutionError = WordExecutionError;
138
146
  class ModuleError extends ForthicError {
139
147
  module_name;
140
148
  error;
141
- constructor(forthic, module_name, error, location) {
149
+ constructor(forthic, module_name, error, location, cause) {
142
150
  const note = `Error in module ${module_name}`;
143
- super(forthic, note, location);
151
+ super(forthic, note, location, cause);
144
152
  this.module_name = module_name;
145
153
  this.error = error;
146
154
  this.name = "ModuleError";
@@ -154,18 +162,18 @@ class ModuleError extends ForthicError {
154
162
  }
155
163
  exports.ModuleError = ModuleError;
156
164
  class StackUnderflowError extends ForthicError {
157
- constructor(forthic, location) {
165
+ constructor(forthic, location, cause) {
158
166
  const note = `Stack underflow`;
159
- super(forthic, note, location);
167
+ super(forthic, note, location, cause);
160
168
  this.name = "StackUnderflowError";
161
169
  }
162
170
  }
163
171
  exports.StackUnderflowError = StackUnderflowError;
164
172
  class UnknownTokenError extends ForthicError {
165
173
  token;
166
- constructor(forthic, token, location) {
174
+ constructor(forthic, token, location, cause) {
167
175
  const note = `(Should never happen) Unknown type of token: ${token}`;
168
- super(forthic, note, location);
176
+ super(forthic, note, location, cause);
169
177
  this.token = token;
170
178
  this.name = "UnknownTokenError";
171
179
  }
@@ -175,17 +183,17 @@ class UnknownTokenError extends ForthicError {
175
183
  }
176
184
  exports.UnknownTokenError = UnknownTokenError;
177
185
  class MissingSemicolonError extends ForthicError {
178
- constructor(forthic, location) {
186
+ constructor(forthic, location, cause) {
179
187
  const note = `Definition was missing its semicolon`;
180
- super(forthic, note, location);
188
+ super(forthic, note, location, cause);
181
189
  this.name = "MissingSemicolonError";
182
190
  }
183
191
  }
184
192
  exports.MissingSemicolonError = MissingSemicolonError;
185
193
  class ExtraSemicolonError extends ForthicError {
186
- constructor(forthic, location) {
194
+ constructor(forthic, location, cause) {
187
195
  const note = `Unexpected semicolon -- no definition in progress`;
188
- super(forthic, note, location);
196
+ super(forthic, note, location, cause);
189
197
  this.name = "ExtraSemicolonError";
190
198
  }
191
199
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/forthic/errors.ts"],"names":[],"mappings":";;;AAqMA,sDAqBC;AAxND,MAAa,YAAa,SAAQ,KAAK;IACf;IAAyB;IAAsB;IAAnE,YAAoB,OAAe,EAAU,IAAY,EAAU,QAAuB;QACtF,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;IAI1F,CAAC;IAED,cAAc;QACV,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,C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AA6D;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;
@@ -28,6 +28,7 @@ class GlobalModule extends module_1.Module {
28
28
  this.literal_handlers = [
29
29
  this.to_bool,
30
30
  this.to_float,
31
+ this.to_zoned_datetime,
31
32
  this.to_literal_date,
32
33
  this.to_time,
33
34
  this.to_int,
@@ -256,63 +257,10 @@ class GlobalModule extends module_1.Module {
256
257
  return result;
257
258
  }
258
259
  to_literal_date(str_val) {
259
- // --------------------
260
- // Handle date format strings like "YYYY-MM-DD" or "YYYY-MM-03" or "YYYY-02-03" or "2025-02-03"
261
- let year;
262
- let month;
263
- let day;
264
- const date_parts = str_val.split("-");
265
- const zonedDateTime = temporal_polyfill_1.Temporal.Now.zonedDateTimeISO(this.interp?.get_timezone() ?? "UTC");
266
- // Case 1: If time is like "YYYY-MM-DD"
267
- if (str_val.match(/^YYYY-MM-DD$/)) {
268
- year = zonedDateTime.year;
269
- month = zonedDateTime.month;
270
- day = zonedDateTime.day;
271
- } // Case 2: If time is like "YYYY-MM-03"
272
- else if (str_val.match(/^YYYY-MM-\d{2}$/)) {
273
- year = zonedDateTime.year;
274
- month = zonedDateTime.month;
275
- day = parseInt(date_parts[2]);
276
- } // Case 3: If time is like "YYYY-02-03"
277
- else if (str_val.match(/^YYYY-\d{2}-\d{2}$/)) {
278
- year = zonedDateTime.year;
279
- month = parseInt(date_parts[1]);
280
- day = parseInt(date_parts[2]);
281
- } // Case 4: If time is like "2025-02-03"
282
- else if (str_val.match(/^\d{4}-\d{2}-\d{2}$/)) {
283
- year = parseInt(date_parts[0]);
284
- month = parseInt(date_parts[1]);
285
- day = parseInt(date_parts[2]);
286
- } // Case 5: If time is like "2025-MM-DD"
287
- else if (str_val.match(/^\d{4}-MM-DD$/)) {
288
- year = parseInt(date_parts[0]);
289
- month = zonedDateTime.month;
290
- day = zonedDateTime.day;
291
- } // Case 6: If time is like "2025-02-DD"
292
- else if (str_val.match(/^\d{4}-\d{2}-DD$/)) {
293
- year = parseInt(date_parts[0]);
294
- month = parseInt(date_parts[1]);
295
- day = zonedDateTime.day;
296
- } // Case 7: If time is like "2025-MM-03"
297
- else if (str_val.match(/^\d{4}-MM-\d{2}$/)) {
298
- year = parseInt(date_parts[0]);
299
- month = zonedDateTime.month;
300
- day = parseInt(date_parts[2]);
301
- } // Case 8: If time is like "YYYY-03-DD"
302
- else if (str_val.match(/^YYYY-\d{2}-DD$/)) {
303
- year = zonedDateTime.year;
304
- month = parseInt(date_parts[1]);
305
- day = zonedDateTime.day;
306
- } // Otherwise, return null
307
- else {
308
- return null;
309
- }
310
- const result = temporal_polyfill_1.Temporal.PlainDate.from({
311
- year: year,
312
- month: month,
313
- day: day,
314
- });
315
- return result;
260
+ return (0, utils_1.to_literal_date)(str_val, this.interp?.get_timezone() ?? "UTC");
261
+ }
262
+ to_zoned_datetime(str_val) {
263
+ return (0, utils_1.to_zoned_datetime)(str_val);
316
264
  }
317
265
  to_time(str_val) {
318
266
  const match = str_val.match(/(\d{1,2}):(\d{2})/);
@@ -1792,8 +1740,7 @@ class GlobalModule extends module_1.Module {
1792
1740
  // ( str -- datetime )
1793
1741
  word_STR_to_DATETIME(interp) {
1794
1742
  const s = interp.stack_pop();
1795
- const date = new Date(s);
1796
- const result = temporal_polyfill_1.Temporal.Instant.fromEpochMilliseconds(date.getTime()).toZonedDateTime({ timeZone: interp.get_timezone(), calendar: "iso8601" });
1743
+ const result = (0, utils_1.to_zoned_datetime)(s, interp.get_timezone());
1797
1744
  interp.stack_push(result);
1798
1745
  }
1799
1746
  // ( str -- timestamp )