goccmack / gocc

Parser / Scanner Generator
Other
622 stars 48 forks source link

Make errors more human friendly #110

Closed kfsone closed 3 years ago

kfsone commented 3 years ago

Per https://github.com/goccmack/gocc/issues/109

The aim of this change is to provide a more human-readable form of error-message in the default (.Error()) version.

Most editors/IDEs recognize the FLC (file, line, column) syntax for errors that typically makes them easy to interact with in tooling.

In particular, a common convention is:

FileLineComment
    : Filename ":" LineNo ":" ColumnNo ":" " " "error" ":" " " ErrorMessage
    ;

Vim, Emacs and Visual Studio/Code will recognize this as "your build didn't work, and I can tell you why".

The parser knows nothing about filenames, so we can't attempt to print one, the user just needs to prefix printing the error with their filename, e.g.

fmt.Printf("%s:%s\n", filename, err.Error())
awalterschulze commented 3 years ago

Will review more later sorry

kfsone commented 3 years ago

@awalterschulze I removed the quoting on the e.ErrorToken.Lit, because it often seems to include whitespace: e.g got: "error\r" (windows).

kfsone commented 3 years ago

Will review more later sorry

A partial review is fully appreciated :)

awalterschulze commented 3 years ago

Sorry for the delay, still trying to find some time to review this.

kfsone commented 3 years ago

TIL: The downside to using "git checkout -" all the time is you become a twonk and make pull requests from main/master :)

kfsone commented 3 years ago

All the user context stuff should now be gone from this branch.

kfsone commented 3 years ago

@awalterschulze Apologies for making this so tedious with the rookie merge mistakes, a handful of tiny nuances just enough to throw me off: I'm doing my development across gitlab and bitbucket server, I've gone from being a chair on a bash command-line-golf group to an all out powershell user and I'm still relatively new to the go ecosystem :) I literally could not see the Makefile initially, lol.

awalterschulze commented 3 years ago

Not a problem, I understand these seemingly silly things can keep one busy for hours.

Problem is now in github the diff shows that almost every file has changed, but when I look at the files, they seem to be the same. I don't know what went wrong, but this makes reviewing the code really hard. Do you think it is possible to make something easier to review. Even it is requires creating a new pull request.

kfsone commented 3 years ago

Happy to, gives me the chance to correct my mistake of doing it off master :)

kfsone commented 3 years ago

@awalterschulze replaced with https://github.com/goccmack/gocc/pull/115