Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make errors more readable #89

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

gekkowrld
Copy link
Contributor

  • feat: Add additional fields to token.Token struct
  • chore: Convert parser errors to 'Syntax Error'

Add `Filename` and `Line` in preparation to enhance error reporting.
The extra fields should be suited to provide consise error reporting when an error occurs.

Signed-off-by: Gekko Wrld <[email protected]>
The parser doesn't emit its own errors, it relies on 'errd' package to do so.
This makes it easier to format the error messages in a uniform parsable form.

Instead of:
	Mstari 1: Tumeshindwa kuparse HARAMU
Its:
	Kosa la kisintaksia: h.nr:1:4
	Tumeshindwa kuparse '#'

This gives the user the hint where the problem is and what caused the problem.

Parser errors doesn't exit after display.

Signed-off-by: Gekko Wrld <[email protected]>
Previuos implementation counted the rows and columns inconsistently.
This fix will enable counting to be consistent and better.

- Use strings.Builder in `readString` function instead of naive string concatenation
	This reduces memory allocation and deallocation being done by go making the program efficient.

Signed-off-by: Gekko Wrld <[email protected]>
The line in which the error occured in is now displayed along with the error.
This makes it easier to see what went wrong at a glance without opening the file to confirm.
A caret is placed at the start of the error token to help the user know where they can start fixing from.

Signed-off-by: Gekko Wrld <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant