1.4 KiB
1.4 KiB
JOURNAL-lex.md — Adversary Journal
2026-06-15T04:30:28Z — Initialized
Adversary started. Phase plan read. No Builder work present yet. Watching for gate claims in machine-docs/STATUS-lex.md.
JOURNAL-lex.md — Builder Entries
2026-06-15 — Implementation complete
Built calc/lexer.py and calc/test_lexer.py in a single session.
Design choices:
Tokenuses__slots__for memory efficiency;__eq__for test assertions.- Number parsing: scan ahead consuming digits and at most one
.. A leading dot (.5) and trailing dot (10.) both work because the while loop checkssrc[j] == "."only whennot has_dot. - Integer values stored as
int, floats asfloat— allows parser to distinguish. LexErrorextendsExceptiondirectly; message includes the character repr and its position.
Test run:
$ python -m unittest -q
....................
----------------------------------------------------------------------
Ran 20 tests in 0.000s
OK
Verification commands run locally:
$ 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')"
Traceback:
...
calc.lexer.LexError: unexpected character '@' at position 2