no-context / moo

Optimised tokenizer/lexer generator! 🐄 Uses /y for performance. Moo.
BSD 3-Clause "New" or "Revised" License
821 stars 65 forks source link

Prettier Errors #38

Closed tjvr closed 7 years ago

tjvr commented 7 years ago
Invalid syntax: line 1: 'baa'

Also, attach line and col to the Error we throw—(is this useful?)

nathan commented 7 years ago

Confusing if you have a syntax error at the end of a line, since it would say the line was blank.

(is this useful?)

Yes, because I like to generate error messages that look like this:

Error: invalid syntax at /some/file.ext:12:3

  totally valid `syntax`
                ^

Probably makes sense to include offset too.

tjvr commented 7 years ago

Yes, because I like to generate error messages that look like this

Right. But you could already do that by defining an error rule.

nathan commented 7 years ago

Fair enough. Probably not, then.

bates64 commented 7 years ago

Please add line and col anyway?

tjvr commented 7 years ago

@nanalan Why? As explained above, you can define an error token.

bates64 commented 7 years ago

Actually, that's a good point 😜 Error tokens do look like the way to go!

tjvr commented 7 years ago

Confusing if you have a syntax error at the end of a line, since it would say the line was blank.

What do you propose? Special-case that -- Invalid end of line?

nathan commented 7 years ago

I'd be inclined to say just extract the whole line, scanning backward if possible.

tjvr commented 7 years ago

@nathan Done!

tjvr commented 7 years ago

(Ignore the failed check—that should be fixed now.)