Skip to content

Commit 3fb2995

Browse files
committed
fixed string quote parsing issue
1 parent 545ec21 commit 3fb2995

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

index.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@
2828
<body>
2929
<div class="container">
3030
<h4>JSPython development console</h4>
31-
<div id="editor">x = -3.14 + 1</div>
31+
<div id="editor">
32+
def power(base, exponent):
33+
if exponent == 0:
34+
return 1
35+
else:
36+
return base * power(base, exponent - 1)
37+
38+
"5 ** 10 = " + power(5, 10) + " == " + Math.pow(5, 10)
39+
40+
</div>
3241
<!--
3342
def f(n):
3443
n * n

src/interpreter.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,22 @@ describe('Interpreter', () => {
364364

365365
});
366366

367+
it('Recursive function - power', async () => {
368+
369+
const script =
370+
`
371+
def power(base, exponent):
372+
if exponent == 0:
373+
return 1
374+
else:
375+
return base * power(base, exponent - 1)
376+
377+
"5 ** 10 == " + power(5, 10) + " == " + Math.pow(5, 10)
378+
`
379+
expect(await e.evaluate(script)).toBe('5 ** 10 == 9765625 == 9765625');
380+
});
381+
382+
383+
384+
367385
});

src/tokenizer/tokenizer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ export class Tokenizer {
145145
this.tokenText += script[this._cursor];
146146
if (this._cursor + 1 >= script.length) break;
147147
}
148+
149+
//start column needs to take into account a begining quote, not just a string
150+
this._startColumn--;
148151
}
149152

150153
// a special case when empty string

0 commit comments

Comments
 (0)