JohnEarnest / ok

An open-source interpreter for the K5 programming language.
MIT License
587 stars 72 forks source link

Parser should track and report source location information #47

Open darkf opened 8 years ago

darkf commented 8 years ago

It is a ubiquitous feature to many compilers/interpreters that error messages report the location of the error, e.g. "Type error: line 1, column 6", but oK currently does not.

K6 also has a helpful feature to point a caret at the location of an error:

1 + b + 2
    ^
value error
ngn commented 8 years ago

This may require a redesign of the parser which currently modifies the code with .replace(), .trim(), and " "+ and thus loses track of the original token offsets. Speaking of which, I'd suggest working towards a simple recursive parser/tokenizer that encodes the AST in the language's own data structures. I don't know if k6 does this, but I quite like the near-homoiconicity of older versions of k/q through -5!x and -6!x.

JohnEarnest commented 8 years ago

Looking forward, I agree- the parser has grown some unnecessary scar tissue and a rewrite could both provide useful new features and permit simplification of the interpreter.

I would recommend holding off on this, though, until we have most of the k6 changes solidified.