8000 add filename params · dragoncoder047/pickle@1f44564 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f44564

Browse files
add filename params
1 parent 7bc9fdb commit 1f44564

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

pickle.js

Lines changed: 36 additions & 6 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class PickleError extends Error {
1515
}
1616

1717
/**
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.
1920
*/
2021
class PickleSourceLocation {
2122
/**
@@ -53,7 +54,12 @@ class PickleSourceLocation {
5354
* All objects in Pickle are instances of this.
5455
*/
5556
class PickleObject {
56-
constructor() {
57+
/**
58+
* Create a new Pickle object.
59+
* @param {string} typeName
60+
* @param {any} data
61+
*/
62+
constructor(typeName, data) {
5763
/**
5864
* @type {Map<string, PickleObject>}
5965
*/
@@ -70,6 +76,14 @@ class PickleObject {
7076
* @type {PickleSourceLocation?}
7177
*/
7278
this.source = null;
79+
/**
80+
* @type {string}
81+
*/
82+
this.type = typeName;
83+
/**
84+
* @type {any}
85+
*/
86+
this.data = data;
7387
}
7488
/**
7589
* Returns true if the object has a property on itself (not a prototype)
@@ -171,9 +185,10 @@ class PickleToken {
171185
* @param {string} content
172186
* @param {LineColumn} start
173187
* @param {LineColumn} end
188+
* @param {string} [filename=""]
174189
* @param {string} [message=""]
175190
*/
176-
constructor(type, content, start, end, message = "") {
191+
constructor(type, content, start, end, filename = "", message = "") {
177192
var types = type.split(".");
178193
/**
179194
* @type {string}
@@ -195,6 +210,10 @@ class PickleToken {
195210
* @type {LineColumn}
196211
*/
197212
this.end = end;
213+
/**
214+
* @type {string{
215+
*/
216+
this.filename = filename;
198217
/**
199218
* @type {string}
200219
*/
@@ -207,6 +226,7 @@ class PickleToken {
207226
content: this.content,
208227
start: this.start,
209228
end: this.end,
229+
filename: this.filename,
210230
message: this.message
211231
};
212232
}
@@ -219,8 +239,9 @@ class PickleTokenizer {
219239
/**
220240
* Create a new `PickleTokenizer`.
221241
* @param {string} string The stream
242+
* @param {string } filename
222243
*/
223-
constructor(string) {
244+
constructor(string, filename) {
224245
/**
225246
* @type {string}
226247
*/
@@ -237,6 +258,10 @@ class PickleTokenizer {
237258
* @type {number}
238259
*/
239260
this.bi = 0;
261+
/**
262+
* @type {string}
263+
*/
264+
this.filename = filename;
240265
}
241266
/**
242267
* Get the current line and column the tokenizer is sitting on.
@@ -313,7 +338,7 @@ class PickleTokenizer {
313338
* @returns {PickleToken}
314339
*/
315340
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);
317342
}
318343
/**
319344
* Advances the tokenizer and returns the next token, or undefined if the tokenizer is empty.
@@ -431,11 +456,16 @@ class PickleParser {
431456
/**
432457
* Create a new parser.
433458
* @param {string} code
459+
* @param {string} filename
434460
*/
435-
constructor(code) {
461+
constructor(code, filename) {
436462
/**
437463
* @type {PickleTokenizer}
438464
*/
439465
this.tokenizer = new PickleTokenizer(code);
466+
/**
467+
* @type {string}
468+
*/
469+
this.filename = filename;
440470
}
441471
}

0 commit comments

Comments
 (0)
0