Repository navigation
feat: read 5'10" as feet and inches - #24
Merged
Merged
Conversation
A quote glued to a number is now a prime mark instead of a string opener,
so 5' is 5 ft, 5" is 5 in and 5'10" (or 5'10) is 5 ft + 10 in. Quotes
anywhere else still delimit string literals.
An empty name no longer resolves to parsec: matchExact("") matched every
unit without a symbol, parsec first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Part of #12
What was wrong
5'10"evaluated to5. The quote opened an unterminated string literal, and the rest of the input was dropped.5'and5"evaluated to5parsec. The empty string literal was looked up as a unit name.UnitDatabase::matchExact("")matched every unit with an emptysymbol, and parsec comes first.What changed
lexer.cpp, +5 lines): a'or"directly after a digit becomes a one-character unit token (a prime mark). It no longer opens a string literal there. Quotes anywhere else still delimit strings.parsePrimes, called after a number inparseTerm):N'isN ftandN"isN in.N'M"becomesN' + M". The closing inch mark can be left off (5'10). Inside the compound, the inches must be glued to the foot mark. The whole compound is consumed, so5'2"is never read as ft². This uses the existing'→ foot and"→ inch aliases.unit.cpp):matchExactreturns nothing for an empty name, so an empty name never resolves to a unit.No interpreter or unit-table changes.
Not done: the minutes and seconds reading
Giving minute the
'alias and second the"alias does not work with the current ambiguity mechanism. With both marks ambiguous,resolvePairreturnsnullopt,reconcileUnitsleaves both sides alone, andadd()sums the raw numbers. So5'10"came out as15in, and the length reading broke too. I tried this and reverted it.5'10" to sis now an error ("Incompatible units"), not a wrong number.To support time, the interpreter would need two things:
resolvePairpicks a default pairing when both sides are ambiguous: the first reading of the left side that shares a dimension with the right side, which gives feet and inches.1m + 1m to sis.Tests
New
tests/corpus/prime.corpus:5',5",5'10",5'10,6'0", and5'2/5'3"(not read as squared units)5'10" to s→!error Incompatible units: foot (length) to second (duration)5 ''→5(it used to be parsec)"5'10"→5'10,'5"',5 'abc','hello world',upper('a1'),"12:30",'unfinishedThe new cases fail on
mainand pass with this change. The existing corpus "typing an expression never crashes" test also runs every prefix of the new lines.make && ./build/numen-tests: all tests passed (15337 assertions in 93 test cases)make debug && ./build-debug/numen-tests(ASan+UBSan): all tests passed (15337 assertions in 93 test cases)clang-format -irun on the changed files.make tidywas not run becauserun-clang-tidyisn't installed on this machine.Out of scope: coordinates and angles, and spaced forms like
5' 10", which still evaluates to5ftand ignores the rest.🤖 Generated with Claude Code