Repository navigation
fix(pre-parser): refuse two names of a scope that differ by a particle - #48
Merged
Merged
Conversation
…in cutted_name The search for the longest declared name followed by a name particle moves out of tokenize_names, unchanged. Refs #18
With 사 and 사과 declared in the same function, 사과 can be read as 사 + 과: declared_names now stops with AmbiguousName when a new name is another name of its scope followed by a name particle (가득 next to 가 stays allowed). The scope is the globals plus the current function: it ends at the closing brace, and a new header drops the parameters of one without a body (외부). Fixes #18
고치다(정수 사, 정수 사과) was accepted: a parameter in parentheses was added to the scope without the check the other declarations get. Unit tests cover AmbiguousName for variables, both kinds of parameters, globals, the scope of a function and a rest that is no name particle (가득, 사로, 사의, 사과일). Refs #18
This file contains hidden or 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
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.
Closes #18.
What changed
With
사and사과declared in the same scope,사과can be read as the name사과or as사+과, and the pre-parser silently picked one. A name carries one particle only, so사과는alone is not ambiguous: the conflict is a rest that is exactly a name particle.declared_names,src/parser/preparser/pre_parser.rs), withAmbiguousName:'사과' can be read as another declared name followed by a particle. The check covers variables, parameters in parentheses and sentence parameters.가and가득(sample/13_operators.kr),사로,사의,사과일. The rest is checked withis_name_particle.외부). Two functions can use사and사과.tokenize_namesintocutted_name, unchanged.AmbiguousName: variables in both orders, parameters, globals, two functions, rests that are no particle.Known limits: nested blocks (
만약 { }) share the scope of their function; a sentence declaration without a body keeps its parameters until the next(or}. Found while testing: #47, a name ending in 다 used alone is read as a verb (not caused by this change).How it was tested
cargo fmt --check: clean.cargo clippy --all-targets: no warning.cargo test: 1385 passed, 0 failed.scripts/run_samples.sh: 62 passed, 0 failed.scripts/missing.sh 18: 3 passed, 0 missing.Use of AI
The extraction of
cutted_name,is_word_ambiguous, the check indeclared_namesand the check of the parameters in parentheses are by the maintainer. Claude Code fixed the signature ofcutted_name, made the error go up fromdeclared_names, added the scope with the braces, wrote the unit tests, opened #47, made the commits and opened this pull request.