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

Stop using exit in parser. #47

Merged
merged 1 commit into from
Apr 6, 2021

Conversation

ArthurSonzogni
Copy link
Contributor

Using exit(EXIT_FAILURE) in the middle of a function makes kgt hard to
be embedded as a library, because it interrupts the caller.

The previous patch removed usage of exit for every generators:
#40

This one removes usage of exit for every parser. The parsing_error
struct is introduced to list all the errors.

Issue:

if (error_count != 0) {
fprintf(stderr, "KGT: Exiting. %d errors reported\n", error_count);
exit(EXIT_FAILURE);
}
Copy link
Owner

Choose a reason for hiding this comment

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

This is great work, thank you.

Do you think the queue is necessary? I'd only imagined kgt giving one error and exiting, I hadn't intended to attempt to recover and continue a parse. Have you seen multiple errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, multiple errors is possible.
You can try on:
https://arthursonzogni.com/Diagon/#Grammar


With input = iso-ebnf

a

output:

1:1:Syntax error: expected production rule assignment
1:1:Syntax error: expected production rule separator

With input = abnf

a = b

a = b

a = b

Output:

5:5:production rule <a> already exists
5:5:production rule <a> already exists

Copy link
Owner

Choose a reason for hiding this comment

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

Oh that makes sense. Those are good examples, thank you!

Using exit(EXIT_FAILURE) in the middle of a function makes kgt hard to
be embedded as a library, because it interrupts the caller.

The previous patch removed usage of exit for every generators:
katef#40

This one removes usage of exit for every parser. The parsing_error
struct is introduced to list all the errors.

Issue:
- katef#38
- ArthurSonzogni/Diagon#19
@ArthurSonzogni ArthurSonzogni force-pushed the task/no-exit-in-parser branch from 2bbd2a1 to b1b825a Compare April 5, 2021 13:53
@katef katef merged commit a7cbc52 into katef:main Apr 6, 2021
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.

2 participants