-
Notifications
You must be signed in to change notification settings - Fork 0
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
Scanner refactor #8
Merged
Merged
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
Significant changes include: - Simplified the NewParser function in parser.go by removing unnecessary steps and adding a next() call. - Refactored the Scan function in scanner.go to return position, token, and literal directly instead of setting them as properties on the Scanner struct. - Updated tests in scanner_test.go to reflect these changes.
The parser's error matching has been improved to check for substrings, providing more flexibility. The scanner now advances to the next token after identifying an identifier, ensuring proper sequence progression. Adjustments were also made to the scanner tests: literal comparison no longer trims spaces from input, and position calculation now accounts for an extra character. Lastly, a change was made in how scanning errors are handled during testing.
A new function, PositionFor, has been added to the token package. This function returns the Position value for a given file position. If the provided position is out of bounds, it's adjusted to match File.Offset behavior. Alongside this addition, a test suite has also been created to ensure that calling PositionFor yields equivalent results as calling file.PositionFor(p, false).
The scanner's initialization has been refactored for better readability. The creation of the bufio.Scanner and setting its split function is now done before creating the Scanner struct. A new method, Position, has been added to the Scanner which returns a token's position in a file. In addition, changes have been made to the scanner tests. The test case for scanning an identifier followed by a token has been replaced with one for scanning an identifier followed by whitespace. Additional assertions have also been added to ensure that after scanning an identifier or special character, the next scan returns EOF (end of file).
Added new tests to the scanner_test.go file. These include a test for the Position function, ensuring it's equivalent to calling file.PositionFor(p, false). Also added checks for token position and newline tokens in existing tests. Corrected an issue with scanning newline followed by token.
The scanning logic has been refactored for better readability and efficiency. The 'done' flag check is now performed after the offset update, ensuring accurate line addition in case of newline characters. In addition, the test coverage for the scanner functionality has been significantly expanded. New test cases have been added to verify correct token scanning following a newline character, with various input scenarios considered. This ensures robustness of the scanner across different use-cases.
Significant changes include: - Removed redundant test cases in the scanner_test.go file - Simplified token scanning tests by focusing on space-separated tokens only - This results in a cleaner, more maintainable test suite
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8 +/- ##
==========================================
- Coverage 95.76% 95.72% -0.05%
==========================================
Files 6 7 +1
Lines 378 374 -4
==========================================
- Hits 362 358 -4
Misses 12 12
Partials 4 4 ☔ View full report in Codecov by Sentry. |
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.
Follow the
pos, tok, lit := scanner.Scan()
pattern from go/scannerPos should refer to the token's starting position