Skip to content

Commit

Permalink
make sure all tokens coming out of compilation have a 'pos' attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Oct 14, 2020
1 parent 1b0f301 commit 2e7deb1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions runtime/scripts/jme.js
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,9 @@ jme.Parser.prototype = /** @lends Numbas.jme.Parser.prototype */ {
// if followed by an open bracket, this is a function application
if( i<this.tokens.length-1 && this.tokens[i+1].type=="(") {
var name = this.funcSynonym(tok.nameWithoutAnnotation);
this.stack.push(new TFunc(name,tok.annotation));
var ntok = new TFunc(name,tok.annotation);
ntok.pos = tok.pos;
this.stack.push(ntok);
this.numvars.push(0);
this.olength.push(this.output.length);
} else {
Expand Down Expand Up @@ -1436,10 +1438,13 @@ jme.Parser.prototype = /** @lends Numbas.jme.Parser.prototype */ {
}
switch(this.listmode.pop()) {
case 'new':
this.addoutput(new TList(n))
var ntok = new TList(n);
ntok.pos = tok.pos;
this.addoutput(ntok)
break;
case 'index':
var f = new TFunc('listval');
f.pos = tok.pos;
f.vars = 2;
this.addoutput(f);
break;
Expand Down Expand Up @@ -1552,6 +1557,9 @@ jme.Parser.prototype = /** @lends Numbas.jme.Parser.prototype */ {
}

function bin(tok,lhs,rhs) {
if(!tok.pos) {
tok.pos = lhs.tok.pos;
}
return {tok: tok, args: [lhs,rhs]};
}

Expand Down

0 comments on commit 2e7deb1

Please sign in to comment.