2.1 KiB
2.1 KiB
STATUS — lex phase
DONE
All DoD gates D1–D4 implemented and self-certified (BUILD phase — DEFERRED review protocol).
What was built
calc/__init__.py— makescalca packagecalc/lexer.py—Token,LexError,tokenize(src) -> list[Token]calc/test_lexer.py— 20 unittest cases covering D1–D4
D1 — Numbers ✓
Integers and floats tokenize to NUMBER with correct Python type (int / float).
Verify:
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('42')])"
# Expected: [('NUMBER', 42), ('EOF', None)]
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('.5')])"
# Expected: [('NUMBER', 0.5), ('EOF', None)]
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('10.')])"
# Expected: [('NUMBER', 10.0), ('EOF', None)]
D2 — Operators & Parens ✓
All six single-char operators tokenize to the right kind.
Verify:
python -c "from calc.lexer import tokenize; print([t.kind for t in tokenize('1+2*3')])"
# Expected: ['NUMBER', 'PLUS', 'NUMBER', 'STAR', 'NUMBER', 'EOF']
D3 — Whitespace & Errors ✓
Spaces/tabs skipped; invalid chars raise LexError with char + position.
Verify:
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
# Expected: raises calc.lexer.LexError: Unexpected character '@' at position 2
D4 — Tests green ✓
20 tests, 0 failures.
Verify:
python -m unittest -q
# Expected: Ran 20 tests in 0.00xs / OK
Plan verify commands (from lex.md)
python -m unittest -q
# → Ran 20 tests in 0.001s / OK
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"
# → [('NUMBER', 3.5), ('STAR', '*'), ('LPAREN', '('), ('NUMBER', 1), ('MINUS', '-'), ('NUMBER', 2), ('RPAREN', ')'), ('EOF', None)]
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
# → LexError: Unexpected character '@' at position 2
Commit sha: 0092890 (chore: add .gitignore, remove tracked pycache) 009755c (feat(lex): implement lexer, Token, LexError, and test suite)