Skip to content

Commit 6eeb596

Browse files
committed
Add String>Equ( to smart tokenization mode
1 parent d724f62 commit 6eeb596

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

tivars/tokenizer/encoder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def encode(string: str, *,
1919
Tokenization is performed using one of three procedures, dictated by ``mode``:
2020
- ``max``: Always munch maximally, i.e. consume the most input possible to produce a token
2121
- ``smart``: Munch maximally or minimally depending on context
22-
- ``string``: Always munch minimally (equivalent to ``smart`` string context)
22+
- ``min``: Always munch minimally (equivalent to ``smart`` string context; may also be passed as ``string``)
2323
2424
The ``smart`` tokenization mode uses the following contexts, munching maximally otherwise:
25-
- Strings: munch minimally, except when interpolating using ``Send(``
25+
- Strings: munch minimally, except when interpolating using ``Send(`` or storing to an equation
2626
- Program names: munch minimally up to 8 tokens
2727
- List names: munch minimally up to 5 tokens
2828
@@ -57,7 +57,7 @@ def encode(string: str, *,
5757
case "smart":
5858
stack = [SmartMode()]
5959

60-
case "string" | "min":
60+
case "min" | "string":
6161
stack = [MinMode()]
6262

6363
case _:

tivars/tokenizer/state.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ def next(self, token: TIToken) -> list[EncoderState]:
171171
return super().next(token)
172172

173173

174-
class InterpolatedString(String):
174+
class MaxString(String):
175175
"""
176-
Strings interpolated via ``Send(``
176+
Maximally munched string
177177
"""
178178

179179
mode = 0
180180

181181

182-
class InterpolationStart(Line):
182+
class MaxStart(Line):
183183
"""
184-
Encoder state to initialize `InterpolatedString`
184+
Encoder state to initialize `MaxString`
185185
186186
If any token besides ``"`` is encountered, this state is immediately exited to avoid cluttering the stack.
187187
"""
@@ -191,7 +191,7 @@ class InterpolationStart(Line):
191191
def next(self, token: TIToken) -> list[EncoderState]:
192192
match token.bits:
193193
case b'\x2A':
194-
return [InterpolatedString()]
194+
return [MaxString()]
195195

196196
case _:
197197
return []
@@ -214,9 +214,9 @@ def next(self, token: TIToken) -> list[EncoderState]:
214214
case b'\x5F':
215215
return [self, ProgramName()]
216216

217-
# Send(
218-
case b'\xE7':
219-
return [self, InterpolationStart()]
217+
# Send( String>Equ(
218+
case b'\xE7' | b'\xBB\x56':
219+
return [self, MaxStart()]
220220

221221
# |L
222222
case b'\xEB':
@@ -228,4 +228,4 @@ def next(self, token: TIToken) -> list[EncoderState]:
228228

229229
__all__ = ["EncoderState", "MaxMode", "MinMode", "SmartMode",
230230
"Line", "Name", "ListName", "ProgramName",
231-
"String", "InterpolatedString", "InterpolationStart"]
231+
"String", "MaxString", "MaxStart"]

0 commit comments

Comments
 (0)