Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ohm-js/src/PosInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class PosInfo {
Object.keys(memo).forEach(k => {
const memoRec = memo[k];
if (pos + memoRec.examinedLength > invalidatedIdx) {
delete memo[k];
memo[k] = undefined;
} else {
this.maxExaminedLength = Math.max(this.maxExaminedLength, memoRec.examinedLength);
this.maxRightmostFailureOffset = Math.max(
Expand Down
14 changes: 7 additions & 7 deletions packages/ohm-js/src/Semantics.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Wrapper {

_forgetMemoizedResultFor(attributeName) {
// Remove the memoized attribute from the cstNode and all its children.
delete this._node[this._semantics.attributeKeys[attributeName]];
this._node[this._semantics.attributeKeys[attributeName]] = undefined;
this.children.forEach(child => {
child._forgetMemoizedResultFor(attributeName);
});
Expand Down Expand Up @@ -341,7 +341,7 @@ export class Semantics {
const thisThing = this._semantics[typePlural][name];

// Check that the caller passed the correct number of arguments.
if (arguments.length !== thisThing.formals.length) {
if (args.length !== thisThing.formals.length) {
throw new Error(
'Invalid number of arguments passed to ' +
name +
Expand All @@ -358,9 +358,9 @@ export class Semantics {
// Create an "arguments object" from the arguments that were passed to this
// operation / attribute.
const argsObj = Object.create(null);
for (const [idx, val] of Object.entries(args)) {
for (let idx = 0; idx < args.length; idx += 1) {
const formal = thisThing.formals[idx];
argsObj[formal] = val;
argsObj[formal] = args[idx];
}

const oldArgs = this.args;
Expand Down Expand Up @@ -569,12 +569,12 @@ Semantics.createSemantics = function (grammar, optSuperSemantics) {
let semantic;
if (operationOrAttributeName in s.operations) {
semantic = s.operations[operationOrAttributeName];
delete s.operations[operationOrAttributeName];
s.operations[operationOrAttributeName] = undefined;
} else if (operationOrAttributeName in s.attributes) {
semantic = s.attributes[operationOrAttributeName];
delete s.attributes[operationOrAttributeName];
s.attributes[operationOrAttributeName] = undefined;
}
delete s.Wrapper.prototype[operationOrAttributeName];
s.Wrapper.prototype[operationOrAttributeName] = undefined;
return semantic;
};
proxy.getOperationNames = function () {
Expand Down
153 changes: 135 additions & 18 deletions packages/ohm-js/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,136 @@

// Helpers

const escapeStringFor = {};
for (let c = 0; c < 128; c++) {
escapeStringFor[c] = String.fromCharCode(c);
}
escapeStringFor["'".charCodeAt(0)] = "\\'";
escapeStringFor['"'.charCodeAt(0)] = '\\"';
escapeStringFor['\\'.charCodeAt(0)] = '\\\\';
escapeStringFor['\b'.charCodeAt(0)] = '\\b';
escapeStringFor['\f'.charCodeAt(0)] = '\\f';
escapeStringFor['\n'.charCodeAt(0)] = '\\n';
escapeStringFor['\r'.charCodeAt(0)] = '\\r';
escapeStringFor['\t'.charCodeAt(0)] = '\\t';
escapeStringFor['\u000b'.charCodeAt(0)] = '\\v';
const escapeStringFor = {
0: '\x00',
1: '\x01',
2: '\x02',
3: '\x03',
4: '\x04',
5: '\x05',
6: '\x06',
7: '\x07',
8: '\\b',
9: '\\t',
10: '\\n',
11: '\\v',
12: '\\f',
13: '\\r',
14: '\x0E',
15: '\x0F',
16: '\x10',
17: '\x11',
18: '\x12',
19: '\x13',
20: '\x14',
21: '\x15',
22: '\x16',
23: '\x17',
24: '\x18',
25: '\x19',
26: '\x1A',
27: '\x1B',
28: '\x1C',
29: '\x1D',
30: '\x1E',
31: '\x1F',
32: ' ',
33: '!',
34: '\\"',
35: '#',
36: '$',
37: '%',
38: '&',
39: "\\'",
40: '(',
41: ')',
42: '*',
43: '+',
44: ',',
45: '-',
46: '.',
47: '/',
48: '0',
49: '1',
50: '2',
51: '3',
52: '4',
53: '5',
54: '6',
55: '7',
56: '8',
57: '9',
58: ':',
59: ';',
60: '<',
61: '=',
62: '>',
63: '?',
64: '@',
65: 'A',
66: 'B',
67: 'C',
68: 'D',
69: 'E',
70: 'F',
71: 'G',
72: 'H',
73: 'I',
74: 'J',
75: 'K',
76: 'L',
77: 'M',
78: 'N',
79: 'O',
80: 'P',
81: 'Q',
82: 'R',
83: 'S',
84: 'T',
85: 'U',
86: 'V',
87: 'W',
88: 'X',
89: 'Y',
90: 'Z',
91: '[',
92: '\\\\',
93: ']',
94: '^',
95: '_',
96: '`',
97: 'a',
98: 'b',
99: 'c',
100: 'd',
101: 'e',
102: 'f',
103: 'g',
104: 'h',
105: 'i',
106: 'j',
107: 'k',
108: 'l',
109: 'm',
110: 'n',
111: 'o',
112: 'p',
113: 'q',
114: 'r',
115: 's',
116: 't',
117: 'u',
118: 'v',
119: 'w',
120: 'x',
121: 'y',
122: 'z',
123: '{',
124: '|',
125: '}',
126: '~',
127: '\x7F',
};
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is here, it's not being used anywhere


// --------------------------------------------------------------------
// Exports
Expand Down Expand Up @@ -59,7 +176,7 @@ export function defineLazyProperty(obj, propName, getterFn) {

export function clone(obj) {
if (obj) {
return Object.assign({}, obj);
return {...obj};
}
return obj;
}
Expand All @@ -81,14 +198,14 @@ export function repeat(x, n) {
}

export function getDuplicates(array) {
const duplicates = [];
const duplicates = new Set();
for (let idx = 0; idx < array.length; idx++) {
const x = array[idx];
if (array.lastIndexOf(x) !== idx && duplicates.indexOf(x) < 0) {
duplicates.push(x);
if (array.lastIndexOf(x) !== idx && duplicates.has(x) < 0) {
duplicates.add(x);
}
}
return duplicates;
return [...duplicates];
}

export function copyWithoutDuplicates(array) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ohm-js/src/pexprs-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pexprs.Apply.prototype.eval = function (state) {
if (state.hasNecessaryInfo(memoRec)) {
return state.useMemoizedResult(state.inputStream.pos, memoRec);
}
delete posInfo.memo[memoKey];
posInfo.memo[memoKey] = undefined;
}
return app.reallyEval(state);
};
Expand Down