Skip to content

Commit e07352f

Browse files
committed
More parser fixes
1 parent 9a41fe0 commit e07352f

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

pxtpy/lexer.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ namespace pxt.py {
137137
} else {
138138
s = "`" + source.slice(t.startPos, t.endPos) + "`"
139139
}
140-
s = s.replace(/\r/g, "").replace(/\n/g, "\\n")
140+
s = s.replace(/\r/g, "")
141+
.replace(/\n/g, "\\n")
142+
.replace(/\t/g, "\\t")
141143
let r = U.lf("{0} at {1}{2}", s, fn, position(t, source))
142144
if (pxt.options.debug)
143145
r += " " + tokenToString(t)
@@ -190,6 +192,7 @@ namespace pxt.py {
190192
}
191193
}
192194
pos0 = pos
195+
singleNewline()
193196
addToken(TokenType.EOF, "")
194197
return res
195198

@@ -354,8 +357,10 @@ namespace pxt.py {
354357
while (true) {
355358
const ch = source.charCodeAt(pos)
356359
if (ch == 9) {
357-
addError(U.lf("TAB indentaion not supported"))
358-
break
360+
// addError(U.lf("TAB indentaion not supported"))
361+
ind = (ind + 8) & ~7
362+
pos++
363+
continue
359364
}
360365
if (ch != 32)
361366
break

pxtpy/parser.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,12 @@ namespace pxt.py {
293293
function raise_stmt(): Stmt {
294294
let r = mkAST("Raise") as Raise
295295
expectKw("raise")
296-
r.exc = test()
297-
if (currentKw() == "from") {
298-
shiftToken()
299-
r.cause = test()
296+
if (!atStmtEnd()) {
297+
r.exc = test()
298+
if (currentKw() == "from") {
299+
shiftToken()
300+
r.cause = test()
301+
}
300302
}
301303
return finish(r)
302304
}
@@ -349,6 +351,7 @@ namespace pxt.py {
349351

350352
function del_stmt(): Stmt {
351353
let r = mkAST("Delete") as Delete
354+
expectKw("del")
352355
r.targets = parseList(U.lf("expression"), expr)
353356
return finish(r)
354357
}
@@ -963,6 +966,7 @@ namespace pxt.py {
963966
return dict(null, expr())
964967
} else if (currentOp() == "RBracket") {
965968
let r = mkAST("Dict", t0) as Dict
969+
shiftToken()
966970
r.keys = []
967971
r.values = []
968972
return finish(r)
@@ -1193,6 +1197,7 @@ namespace pxt.py {
11931197
let r = mkAST(comp) as GeneratorExp
11941198
r.elt = e0
11951199
r.generators = comp_for()
1200+
expectOp(cl)
11961201
return finish(r)
11971202
}
11981203

tests/python/parse0.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
headers = {}
2+
del pulses[0]
13
q = [int(i * self.brightness) for i in self._buf]

0 commit comments

Comments
 (0)