2.4 KiB
STATUS-lex
Commit: 70b71caacd1f7334e387ff15b007573201b524b6
Gate Results
D1 — numbers
Check: tokenize("42") → [NUMBER(42), EOF]; also .5, 3.14, 10. tokenize to float NUMBER.
Command:
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('42')])"
Expected: [('NUMBER', 42), ('EOF', None)]
Observed: [('NUMBER', 42), ('EOF', None)] ✓
Additional verified: .5 → NUMBER(0.5, float), 10. → NUMBER(10.0, float), 3.14 → NUMBER(3.14, float)
Result: PASS
D2 — operators & parens
Check: tokenize("1+2*3") → NUMBER PLUS NUMBER STAR NUMBER EOF
Command:
python -c "from calc.lexer import tokenize; print([t.kind for t in tokenize('1+2*3')])"
Expected: ['NUMBER', 'PLUS', 'NUMBER', 'STAR', 'NUMBER', 'EOF']
Observed: ['NUMBER', 'PLUS', 'NUMBER', 'STAR', 'NUMBER', 'EOF'] ✓
All operator kinds verified: PLUS, MINUS, STAR, SLASH, LPAREN, RPAREN.
Result: PASS
D3 — whitespace & errors
Check 1 (whitespace): " 12 + 3 " → NUMBER PLUS NUMBER EOF
Command:
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize(' 12 + 3 ')])"
Expected: [('NUMBER', 12), ('PLUS', '+'), ('NUMBER', 3), ('EOF', None)]
Observed: [('NUMBER', 12), ('PLUS', '+'), ('NUMBER', 3), ('EOF', None)] ✓
Check 2 (LexError): "1 @ 2" raises LexError with @ and position in message.
Command:
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
Expected: LexError: Invalid character '@' at position 2
Observed:
calc.lexer.LexError: Invalid character '@' at position 2
✓
Result: PASS
D4 — tests green
Command:
python -m unittest -q
Expected: 0 failures
Observed:
----------------------------------------------------------------------
Ran 18 tests in 0.000s
OK
✓
Result: PASS
Plan verification commands
python -m unittest -q
# Ran 18 tests in 0.000s / 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')"
# calc.lexer.LexError: Invalid character '@' at position 2