Skip to content

Commit

Permalink
Set up Sk.parse.linecache so we can provide lines of code to interest…
Browse files Browse the repository at this point in the history
…ed parties (e.g., traceback).
  • Loading branch information
acbart committed Aug 10, 2020
1 parent 86f57bf commit 8986e56
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ function makeParser(filename, style) {
return p;
}


Sk.parse = function parse(filename, input) {

var T_COMMENT = Sk.token.tokens.T_COMMENT;
Expand All @@ -313,7 +312,9 @@ Sk.parse = function parse(filename, input) {
* @returns {function(): string}
*/
function readline(input) {
var lines = input.split("\n").reverse();//.map(function (l) { return l + "\n"; });
let lines = input.split("\n");
Sk.parse.linecache[filename] = lines.slice();
lines = lines.reverse();

return function () {
if (lines.length === 0) {
Expand Down Expand Up @@ -373,6 +374,8 @@ Sk.parse = function parse(filename, input) {
return result;
};

Sk.parse.linecache = {};

Sk.parseTreeDump = function parseTreeDump(n, indent) {
//return JSON.stringify(n, null, 2);
var i;
Expand All @@ -395,3 +398,4 @@ Sk.parseTreeDump = function parseTreeDump(n, indent) {
Sk.exportSymbol("Sk.Parser", Parser);
Sk.exportSymbol("Sk.parse", Sk.parse);
Sk.exportSymbol("Sk.parseTreeDump", Sk.parseTreeDump);
Sk.exportSymbol("Sk.parse.linecache", Sk.parse.linecache);

0 comments on commit 8986e56

Please sign in to comment.