puffnfresh/roy

line numbers out by one in parse errors.

dominictarr opened this issue · 4 comments

  if true or false then
    console.log( 'hello')
Error: Parse error on line 2: Unexpected 'IDENTIFIER'
    at. ...

should be line 1.

I've take a look at this previously - couldn't figure it out.

Need to take another look.

The off-by-one error seems to be in lexer.js (I fixed it by setting lineno=0):

exports.tokenise = function(source) {
    indent = 0;
    indents = [];
    tokens = [];
    lineno = 0;  // Was 1

awesome

So Jison indexes lines from 0.

Thanks @alsonkemp - I've merged your commit.