-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
State Saver #15
Merged
Merged
State Saver #15
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
Instead of relying on the _save_idx and _resotre_idx functions, we introduced a context manager to handle the state storing and restoring for us.
Added special unicode class that handles iterating through the source text. This unicode class provides all of the functionality (and speed) of the prior solution but also allows the parser to more easily restore to a previous point in the source text without needing to copy/tee the generator.
Updated marker variable to save_marker to be more descriptive of which marker variable this is.
Preserving prior variable conventions.
Moved state handler into src since it is directly related to the source text.
After testing found that generators performed significantly better than indexing implementation that perserved TOMLChars.
Some bugs related to reverting back to the generator implementation.
Modified state preserver to only restore unless explicitly configured to restore or if an exception was raised during parsing. Introduced a new exception (Restore) which when raised within a state handler will cause the state to be restored, but then the exception is silently consumed by the state handler.
You can see at these lines in |
Looking forward into the potential development of a more modular parsing. This shift further seeks to seperate the functionality between the source text handling and the actual parsing itself.
This was referenced Oct 22, 2018
Closed
@sdispater anything I can do to get this rolling? |
Add a convenience method that is of great value to simplifying and streamlining the parsing functions.
Thanks a lot for the amount of work your put into this PR. I really appreciate it. Looks good to me 👍 |
capuanob
pushed a commit
to capuanob/tomlkit
that referenced
this pull request
Mar 1, 2023
* Added state saving logic Instead of relying on the _save_idx and _resotre_idx functions, we introduced a context manager to handle the state storing and restoring for us. * Added _Source Added special unicode class that handles iterating through the source text. This unicode class provides all of the functionality (and speed) of the prior solution but also allows the parser to more easily restore to a previous point in the source text without needing to copy/tee the generator. * Update variable name Updated marker variable to save_marker to be more descriptive of which marker variable this is. * Switch index back to idx Preserving prior variable conventions. * Cleanup state handler Moved state handler into src since it is directly related to the source text. * Added back generators After testing found that generators performed significantly better than indexing implementation that perserved TOMLChars. * Addressed minor bugs Some bugs related to reverting back to the generator implementation. * Fixed state saving to properly handle various restore cases Modified state preserver to only restore unless explicitly configured to restore or if an exception was raised during parsing. Introduced a new exception (Restore) which when raised within a state handler will cause the state to be restored, but then the exception is silently consumed by the state handler. * Moved Source into a standalone file Looking forward into the potential development of a more modular parsing. This shift further seeks to seperate the functionality between the source text handling and the actual parsing itself. * Added consume method Add a convenience method that is of great value to simplifying and streamlining the parsing functions.
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.
Simplified state saving/restoring.
Previously:
Now:
And in cases where the marker also needs to be preserved:
A bonus feature that may become valuable for number versus date parsing is the ability to save multiple states: