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

Modular error printing #50

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft

Modular error printing #50

wants to merge 11 commits into from

Conversation

zzril
Copy link
Owner

@zzril zzril commented Nov 20, 2024

Closes #38

@zzril zzril self-assigned this Nov 20, 2024
fputs("Unexpected character:\n", stream);
BarToken_print(compiler->bar, stream);

if(fprintf(stream, "\n%*s^", (int) (compiler->position - 1), " ") < 0) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're likely gonna use the exact same trick inside the token module; might be worth extracting the string formatting into a helper method.

char* bar;
NoteCompilerState state;
size_t bar_length;
char* filename;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we pass the filename in the constructor here, we should probably do that for all the other modules as well.
(Maybe not for the interpreter, if the idea is to be able to potentially load modules from different files?)

Also need to think about scope. (Caller needs to guarantee the string stays around for as long as the compiler/lexer whatever is used. This is fine, but should really be documented.)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Thinking more about this, we might want to store the (pointer-to) filename in the tokens instead. There's little sense in having the line information in one place, and the file name in another.)

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.

Better error reporting
1 participant