@@ -15,7 +15,8 @@ class PickleError extends Error {
15
15
}
16
16
17
17
/**
18
- * Object representing the location a particular object was defined in.
18
+ * Object representing the location (filename, line, column)
19
+ * a particular object was originally defined in.
19
20
*/
20
21
class PickleSourceLocation {
21
22
/**
@@ -53,7 +54,12 @@ class PickleSourceLocation {
53
54
* All objects in Pickle are instances of this.
54
55
*/
55
56
class PickleObject {
56
- constructor ( ) {
57
+ /**
58
+ * Create a new Pickle object.
59
+ * @param {string } typeName
60
+ * @param {any } data
61
+ */
62
+ constructor ( typeName , data ) {
57
63
/**
58
64
* @type {Map<string, PickleObject> }
59
65
*/
@@ -70,6 +76,14 @@ class PickleObject {
70
76
* @type {PickleSourceLocation? }
71
77
*/
72
78
this . source = null ;
79
+ /**
80
+ * @type {string }
81
+ */
82
+ this . type = typeName ;
83
+ /**
84
+ * @type {any }
85
+ */
86
+ this . data = data ;
73
87
}
74
88
/**
75
89
* Returns true if the object has a property on itself (not a prototype)
@@ -171,9 +185,10 @@ class PickleToken {
171
185
* @param {string } content
172
186
* @param {LineColumn } start
173
187
* @param {LineColumn } end
188
+ * @param {string } [filename=""]
174
189
* @param {string } [message=""]
175
190
*/
176
- constructor ( type , content , start , end , message = "" ) {
191
+ constructor ( type , content , start , end , filename = "" , message = "" ) {
177
192
var types = type . split ( "." ) ;
178
193
/**
179
194
* @type {string }
@@ -195,6 +210,10 @@ class PickleToken {
195
210
* @type {LineColumn }
196
211
*/
197
212
this . end = end ;
213
+ /**
214
+ * @type {string{
215
+ */
216
+ this . filename = filename ;
198
217
/**
199
218
* @type {string }
200
219
*/
@@ -207,6 +226,7 @@ class PickleToken {
207
226
content : this . content ,
208
227
start : this . start ,
209
228
end : this . end ,
229
+ filename : this . filename ,
210
230
message : this . message
211
231
} ;
212
232
}
@@ -219,8 +239,9 @@ class PickleTokenizer {
219
239
/**
220
240
* Create a new `PickleTokenizer`.
221
241
* @param {string } string The stream
242
+ * @param {string } filename
222
243
*/
223
- constructor ( string ) {
244
+ constructor ( string , filename ) {
224
245
/**
225
246
* @type {string }
226
247
*/
@@ -237,6 +258,10 @@ class PickleTokenizer {
237
258
* @type {number }
238
259
*/
239
260
this . bi = 0 ;
261
+ /**
262
+ * @type {string }
263
+ */
264
+ this . filename = filename ;
240
265
}
241
266
/**
242
267
* Get the current line and column the tokenizer is sitting on.
@@ -313,7 +338,7 @@ class PickleTokenizer {
313
338
* @returns {PickleToken }
8000
314
339
*/
315
340
makeToken ( type , content , message = "" ) {
316
- return new PickleToken ( type , content , this . beginning , this . lineColumn ( ) , message ) ;
341
+ return new PickleToken ( type , content , this . beginning , this . lineColumn ( ) , this . filename , message ) ;
317
342
}
318
343
/**
319
344
* Advances the tokenizer and returns the next token, or undefined if the tokenizer is empty.
@@ -431,11 +456,16 @@ class PickleParser {
431
456
/**
432
457
* Create a new parser.
433
458
* @param {string } code
459
+ * @param {string } filename
434
460
*/
435
- constructor ( code ) {
461
+ constructor ( code , filename ) {
436
462
/**
437
463
* @type {PickleTokenizer }
438
464
*/
439
465
this . tokenizer = new PickleTokenizer ( code ) ;
466
+ /**
467
+ * @type {string }
468
+ */
469
+ this . filename = filename ;
440
470
}
441
471
}
0 commit comments