8000 add some more types, change comment syntax · dragoncoder047/pickle@82adb40 · GitHub
[go: up one dir, main page]

Skip to content

Commit 82adb40

Browse files
add some more types, change comment syntax
1 parent c2efacb commit 82adb40

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

pickle.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ class PickleTokenizer {
316316
return this.makeToken("string.block", lines.join("\n"));
317317
}
318318
const TOKEN_REGEXES = [
319-
{ type: "comment.block", re: /^(?<!#)(###+)(?!#)[\s\S\n\r]*?(?<!#)\1(?!#)/, significant: false },
320-
{ type: "comment.line", re: /^#[^\n]*/, significant: false },
319+
{ type: "comment.block", re: /^(?<!#)(###\S*?###)(?!#)[\s\S\n\r]*?(?<!#)\1(?!#)/, significant: false },
320+
{ type: "comment.line", re: /^##[^\n]*/, significant: false },
321321
{ type: "paren", re: /^[\(\)\[\]]/, significant: true, groupNum: 0 },
322322
{ type: "space", re: /^(?!\n)\s+/, significant: false },
323323
{ type: "eol", re: /^[;\n]+/, significant: true, groupNum: 0 },
@@ -327,7 +327,7 @@ class PickleTokenizer {
327327
{ type: "number.integer", re: /^-?([1-9][0-9]*|0x[0-9a-f]+|0b[01]+)/i, significant: true, groupNum: 0 },
328328
{ type: "number.float", re: /^-?[0-9]+(\.[0-9]+)?(e[+-]\d+)?/i, significant: true, groupNum: 0 },
329329
{ type: "symbol", re: /^[a-z_][a-z0- 8000 9_]*\??/i, significant: true, groupNum: 0 },
330-
{ type: "symbol.operator", re: /^[-~`!@$%^&*_+=[\]|\\:<>,.?/]+/, significant: true, groupNum: 0 },
330+
{ type: "symbol.operator", re: /^[-~`!@#$%^&*_+=[\]|\\:<>,.?/]+/, significant: true, groupNum: 0 },
331331
]
332332
for (var { type, re, significant, groupNum } of TOKEN_REGEXES) {
333333
console.debug("trying", type);
@@ -412,6 +412,9 @@ class PickleObject {
412412
*/
413413
this.source = null;
414414
}
415+
get typeName() {
416+
return this.constructor.typeName;
417+
}
415418
/**
416419
* Returns the method resolution order for this object's prototype chain.
417420
* @returns {PickleObject[]}
@@ -450,6 +453,17 @@ class PickleObject {
450453
setProperty(pname, value) {
451454
throw 'todo';
452455
}
456+
/**
457+
* Call the object with the specified parameters.
458+
* @param {PickleCollection} args
459+
* @param {PickleScope} scope
460+
* @param {PickleObject?} thisArg
461+
* @returns {PickleObject}
462+
*/
463+
call(args, scope, thisArg = this) {
464+
if (args.length > 0) throw new PickleError(`can't call ${this.typeName}`);
465+
return thisArg;
466+
}
453467
}
454468

455469
class PickleSymbol extends PickleObject {
@@ -707,6 +721,46 @@ class PickleExpando extends PickleInternalObject {
707721
}
708722
}
709723

724+
class PickleBoundProperty extends PickleInternalObject {
725+
static typeName = "bound_property_or_function";
726+
/**
727+
* @param {PickleObject} thisArg The object bound to
728+
* @param {PickleSymbol} property The property key
729+
* @param {...PickleObject} prototypes
730+
*/
731+
constructor(thisArg, property, ...prototypes) {
732+
super(...prototypes);
733+
/**
734+
* @type {PickleObject}
735+
*/
736+
this.thisArg = thisArg;
737+
/**
738+
* @type {PickleSymbol}
739+
*/
740+
this.property = property;
741+
}
742+
}
743+
744+
class PicklePropertySetter extends PickleInternalObject {
745+
static typeName = "setter";
746+
/**
747+
* @param {PickleSymbol} property The property key
748+
* @param {PickleObject} value The value to set to
749+
* @param {...PickleObject} 989A prototypes
750+
*/
751+
constructor(property, value, ...prototypes) {
752+
super(...prototypes);
753+
/**
754+
* @type {PickleSymbol}
755+
*/
756+
this.property = property;
757+
/**
758+
* @type {PickleObject}
759+
*/
760+
this.value = value;
761+
}
762+
}
763+
710764
/**
711765
* An object that parses Pickle code into an abstract syntax tree.
712766
*/

0 commit comments

Comments
 (0)
0