fix(scanner): correct implements keyword tokenization#22
Conversation
|
@ProgrammerKR |
|
Thanks for the detailed investigation and the well-explained fix. I reviewed the changes, and the root cause makes sense:
The implementation is small, focused, and aligns with the intended scanner behavior. I'll merge this after verifying the Windows CI failure is unrelated to this change. |
|
Fixed by #22. The scanner now correctly recognizes the Closing this issue. Thanks to @bastitva0-blip for the contribution. |
|
Hey, looks like the PR got closed instead of merged — was that intentional or did you mean to merge it? The CI failure should be unrelated to the scanner change since it's a pre-existing issue |
|
thanks for the merge @ProgrammerKR |
fixes #21
fix(scanner): correct
implementskeyword tokenizationWhat was broken
The
implementskeyword always tokenized asTOKEN_IDENTIFIER, making interface contracts silently non-functional. The parser had correct handling ready atparser.c:471butTOKEN_IMPLEMENTSwas never produced by the scanner.Two bugs in the same line inside
identifierType()inscanner.c:Bug 1:
scanner->start[2] == 'l'— wrong character.implementsisi-m-p-l-e-m-e-n-t-s, so index 2 is'p', not'l'. This condition was never true.Bug 2:
checkKeyword(scanner, 4, 7, "ements")— wrong length."ements"is 6 characters, not 7. Even with the character check fixed this would always fail thememcmp.The fix
start[2] == 'p'andstart[3] == 'l'(theplinim-pl-ements)> 3since we now read up to index 36to match"ements"Diff
File changed:
src/compiler/lexer/scanner.c— 3 lines changedTesting
Before fix:
implementsparsed as identifier, parser errors or silently skips interface binding.After fix: tokenizes correctly as
TOKEN_IMPLEMENTS, parser enforces interface contract as expected.