Skip to content

fix(pre-parser): refuse two names of a scope that differ by a particle - #48

Merged
Solype merged 4 commits into
mainfrom
fix/18-name-prefix-of-another
Nov 8, 2026
Merged

Solype merged 4 commits into
mainfrom
fix/18-name-prefix-of-another

Conversation

@Solype

@Solype Solype commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

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.

  • Two names of a scope that differ by a name particle are refused (declared_names, src/parser/preparser/pre_parser.rs), with AmbiguousName: '사과' can be read as another declared name followed by a particle. The check covers variables, parameters in parentheses and sentence parameters.
  • A rest that is no name particle is allowed: 가 and 가득 (sample/13_operators.kr), 사로, 사의, 사과일. The rest is checked with is_name_particle.
  • The scope is the globals plus the current function: it ends at the closing brace, and a new header drops the parameters of a header without a body (외부). Two functions can use 사 and 사과.
  • The search of a declared name followed by a particle moves out of tokenize_names into cutted_name, unchanged.
  • Unit tests for 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 in declared_names and the check of the parameters in parentheses are by the maintainer. Claude Code fixed the signature of cutted_name, made the error go up from declared_names, added the scope with the braces, wrote the unit tests, opened #47, made the commits and opened this pull request.

…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
@Solype Solype linked an issue Nov 8, 2026 that may be closed by this pull request
@Solype
Solype merged commit 2d18255 into main Nov 8, 2026
1 check passed
@Solype
Solype deleted the fix/18-name-prefix-of-another branch November 8, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-parser: name that is a prefix of another (사 and 사과)

1 participant