Skip to content

Commit 6ecc867

Browse files
committed
Fix rewind bug
1 parent ea0b9c5 commit 6ecc867

File tree

6 files changed

+40
-32
lines changed

6 files changed

+40
-32
lines changed

dist/easycoder-min.js

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/easycoder.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,11 +1509,11 @@ const EasyCoder_Core = {
15091509
}
15101510
const value = [];
15111511
while (true) {
1512-
compiler.mark();
1512+
const mark = compiler.getIndex();
15131513
try {
15141514
value.push(compiler.getValue());
15151515
} catch (err) {
1516-
compiler.rewind();
1516+
compiler.rewindTo(mark);
15171517
break;
15181518
}
15191519
}
@@ -7617,15 +7617,15 @@ const EasyCoder_Condition = {
76177617

76187618
compile: (compiler) => {
76197619
// See if any of the domains can handle it
7620-
compiler.mark();
7620+
const mark = compiler.getIndex();
76217621
for (const domainName of Object.keys(compiler.domain)) {
76227622
// console.log(`Try domain '${domainName}' for condition`);
76237623
const domain = compiler.domain[domainName];
76247624
const code = domain.condition.compile(compiler);
76257625
if (code) {
76267626
return code;
76277627
}
7628-
compiler.rewind();
7628+
compiler.rewindto(mark);
76297629
}
76307630
},
76317631

@@ -7691,14 +7691,14 @@ const EasyCoder_Value = {
76917691
}
76927692

76937693
// See if any of the domains can handle it
7694-
compiler.mark();
7694+
const mark = compiler.getIndex();
76957695
for (const name of Object.keys(compiler.domain)) {
76967696
const handler = compiler.domain[name];
76977697
const code = handler.value.compile(compiler);
76987698
if (code) {
76997699
return code;
77007700
}
7701-
compiler.rewind();
7701+
compiler.rewindTo(mark);
77027702
}
77037703
return null;
77047704
},
@@ -8210,6 +8210,10 @@ const EasyCoder_Compiler = {
82108210
this.index = this.savedMark;
82118211
},
82128212

8213+
rewindTo: function(index) {
8214+
this.index = index;
8215+
},
8216+
82138217
completeHandler: function() {
82148218
const lino = this.getLino();
82158219
// Add a 'goto' to skip the action
@@ -8284,7 +8288,7 @@ const EasyCoder_Compiler = {
82848288
return;
82858289
}
82868290
// console.log(`Compile ${token}`);
8287-
this.mark();
8291+
const mark = compiler.getIndex();
82888292
for (const domainName of Object.keys(this.domain)) {
82898293
// console.log(`Try domain ${domainName} for token ${token}`);
82908294
const domain = this.domain[domainName];
@@ -8296,7 +8300,7 @@ const EasyCoder_Compiler = {
82968300
}
82978301
}
82988302
}
8299-
this.rewind();
8303+
this.rewindTo(mark);
83008304
}
83018305
console.log(`No handler found`);
83028306
throw new Error(`I don't understand '${token}...'`);

js/easycoder/Compile.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ const EasyCoder_Compiler = {
175175
this.index = this.savedMark;
176176
},
177177

178+
rewindTo: function(index) {
179+
this.index = index;
180+
},
181+
178182
completeHandler: function() {
179183
const lino = this.getLino();
180184
// Add a 'goto' to skip the action
@@ -249,7 +253,7 @@ const EasyCoder_Compiler = {
249253
return;
250254
}
251255
// console.log(`Compile ${token}`);
252-
this.mark();
256+
const mark = compiler.getIndex();
253257
for (const domainName of Object.keys(this.domain)) {
254258
// console.log(`Try domain ${domainName} for token ${token}`);
255259
const domain = this.domain[domainName];
@@ -261,7 +265,7 @@ const EasyCoder_Compiler = {
261265
}
262266
}
263267
}
264-
this.rewind();
268+
this.rewindTo(mark);
265269
}
266270
console.log(`No handler found`);
267271
throw new Error(`I don't understand '${token}...'`);

js/easycoder/Condition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const EasyCoder_Condition = {
55

66
compile: (compiler) => {
77
// See if any of the domains can handle it
8-
compiler.mark();
8+
const mark = compiler.getIndex();
99
for (const domainName of Object.keys(compiler.domain)) {
1010
// console.log(`Try domain '${domainName}' for condition`);
1111
const domain = compiler.domain[domainName];
1212
const code = domain.condition.compile(compiler);
1313
if (code) {
1414
return code;
1515
}
16-
compiler.rewind();
16+
compiler.rewindto(mark);
1717
}
1818
},
1919

js/easycoder/Core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,11 +1509,11 @@ const EasyCoder_Core = {
15091509
}
15101510
const value = [];
15111511
while (true) {
1512-
compiler.mark();
1512+
const mark = compiler.getIndex();
15131513
try {
15141514
value.push(compiler.getValue());
15151515
} catch (err) {
1516-
compiler.rewind();
1516+
compiler.rewindTo(mark);
15171517
break;
15181518
}
15191519
}

js/easycoder/Value.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ const EasyCoder_Value = {
5353
}
5454

5555
// See if any of the domains can handle it
56-
compiler.mark();
56+
const mark = compiler.getIndex();
5757
for (const name of Object.keys(compiler.domain)) {
5858
const handler = compiler.domain[name];
5959
const code = handler.value.compile(compiler);
6060
if (code) {
6161
return code;
6262
}
63-
compiler.rewind();
63+
compiler.rewindTo(mark);
6464
}
6565
return null;
6666
},

0 commit comments

Comments
 (0)