-
Notifications
You must be signed in to change notification settings - Fork 191
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
Pattern Matching #76
Open
AlexMax
wants to merge
15
commits into
Shopify:main
Choose a base branch
from
AlexMax:pattern
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pattern Matching #76
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Error messages did not properly chunkID the source filename, leading to @'s next to filenames and such. - LoadFile improperly raised a generic file read error, even if the actual error was a Lua error such as a SyntaxError.
Currently implements only a very limited subset of `gmatch`. Yes, there is a goto in this commit - it was in the original codebase.
In the original C version of match, there is a label after the default case that can be jumped into from above. The goto implementation in Go does not allow us to jump to that label in all cases. So instead, we form a closure from the default case that we can call into anyplace.
Enabling pattern-matching tests also opened the door to fixing a couple of parsing bugs and filling out a few additional features, such as +, *, and $.
- Implement balanced string and frontier matching. - Fix error messages to actually show up. - Fix a few nasty out of bounds slice accesses. - Run gmatch against the very last position of the source string.
The original version of match() used goto labels to avoid recursive function calls and keep control over the stack size. However, Go cannot jump from one block to another, so the original location of the "dflt" label was unusable. Until this commit, I worked around this deficiency with a closure, but this made the code harder to follow and "out-of-order" compared to the original codebase. The closure is gone, and instead we move the default case of the main switch out into the parent block, reintroducing the old "dflt" label. In cases where we do not want to execute the "dflt" label, we skip over it with a new label that goes straight to the "end" of the function.
Hello, Any update with this PR? Why is not merged? Thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So yeah, pattern matching. Hooray.
goto
in the main match function in order to keep the stack under control, and this has been preserved with slight alterations in order to accommodate Go's stricter rules on where you can and can't jump to. In my research, it appears that Go stacks are (nearly) infinite, but I'm not sure that means converting the jumps to recursive function calls is necessarily a good idea..Also, my apologies, but I actually started this branch midway through #67, so I would merge that before looking at this. I also added a little helpful bit to the Lua test harness that returns the error string off the stack if one exists when running the test suite - if you would rather that be in a separate pull request, it can be backed out.