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

Explicit RibParseError, avoid expects in parsers and handle keywords properly #950

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

afsalthaj
Copy link
Contributor

@afsalthaj afsalthaj commented Sep 19, 2024

Fixes #943

Given below are some examples showing how this PR improved/fixed Rib behaviour from a user perspective

  • let let = 1; was allowed before. This is not allowed anymore.

  • { err : "foo" } wasn't allowed before. Now we allow it! Field names can be err, or ok or such keywords. The idea here is names in record are more-or-less text itself. The only difference is they are not wrapped in quotes following WASM-WAVE syntax.

  • some1((x) wasn't allowed before. Likewise err1, none1, match1 etall used to fail. Obviously users can write their own variants having such names.

Fundamental changes

  • Proper Custom Error called RibParseError which can be used only if there is constraints that talks about conversion to combine's native StreamError. This is a very nice feature in combine, that we can have our own errors, but still consider everything as combine's ParseError. There is more to it, but they are library details

  • With above, we remove all expects in parsers. It is to be noted combine libraries examples uses expect but pretty sure, its not giving the intended behavior.

  • An identifier can be alpha numeric allowing - and _ but it shouldn't be any of the keywords such as if, then, else.

  • With the reduced backtracking, parser also got committed early resulting in prioritized parsers to fail without getting into identifier parser, such as some1. The PR tries to solve it without bringing back the usage of attempt.

  • The precise error messages are more precise due to these changes now. let x = 1; let result in Invalid identifier. let is a keyword rather than unexpected eof and so on.

  • Minor cleanups

With Grammar based fuzzing, or property based tests, we will tighten up all these behaviors even better.

@afsalthaj
Copy link
Contributor Author

Fixes #943

@afsalthaj afsalthaj changed the title WIP: Explicit RibParseError, avoid expectsd and make sure reserved keywords are not parsed successfully outside. WIP: Explicit RibParseError, avoid expects in parsers and handle keywords properly Sep 19, 2024
@afsalthaj afsalthaj marked this pull request as ready for review September 19, 2024 15:55
@afsalthaj afsalthaj changed the title WIP: Explicit RibParseError, avoid expects in parsers and handle keywords properly Explicit RibParseError, avoid expects in parsers and handle keywords properly Sep 19, 2024
@afsalthaj afsalthaj merged commit 5be9f83 into main Sep 19, 2024
17 checks passed
@afsalthaj afsalthaj deleted the fix_identifier branch September 19, 2024 16:02
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.

Rib Robustness: Revisit Identifier Parser
2 participants