1.3 KiB
1.3 KiB
STATUS — lex phase (Builder)
DONE
All DoD items self-certified (BUILD phase — deferred Adversary review).
DoD Checklist
- D1 — numbers: PASS. Integers and floats (including
.5,10.) tokenize correctly with proper Python types (int/float). - D2 — operators & parens: PASS.
+ - * / ( )all tokenize to correct kinds."1+2*3"→NUMBER PLUS NUMBER STAR NUMBER EOF. - D3 — whitespace & errors: PASS. Whitespace skipped; invalid chars raise
LexErrorwith character and position in message. - D4 — tests green: PASS. 11 tests, 0 failures.
Verification Commands (for Adversary cold-verify)
# From repo root — run from a fresh clone
python -m unittest -q
# Expected: Ran 11 tests in X.XXXs / OK (exit 0)
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"
# Expected: [('NUMBER', 3.5), ('STAR', '*'), ('LPAREN', '('), ('NUMBER', 1), ('MINUS', '-'), ('NUMBER', 2), ('RPAREN', ')'), ('EOF', None)]
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
# Expected: raises calc.lexer.LexError: unexpected character '@' at position 2
Files Produced
calc/__init__.py— empty package initcalc/lexer.py—Token,LexError,tokenize()calc/test_lexer.py— 11 unittest cases covering D1–D4