yex.parse.Tokeniser
yex.parse.Tokeniser(doc, source, pushback=None)
#
A tokeniser takes characters from a source, such as a file, and produces tokens of the correct categories.
Then, an parser will request tokens from the tokeniser, and do something with them. Hopefully, it'll be something useful.
Source code in yex/parse/tokeniser.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
correct_line_number()
#
Assigns the correct line number to \inputlineno.
You only need to call this if you've already changed it temporarily: for example, by doing an \input. Otherwise, it updates automatically.
Source code in yex/parse/tokeniser.py
117 118 119 120 121 122 123 124 125 126 | |
eat_optional_char(ch)
#
If the next token stands for the given character, we eat and return it. Otherwise, no character is consumed, and we return None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ch
|
str
|
the character, to check whether token.ch==ch |
required |
Returns:
| Type | Description |
|---|---|
typing.Union[yex.parse.token.Token, None]
|
Token, or None. |
Source code in yex/parse/tokeniser.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
eat_optional_spaces()
#
Eats zero or more space tokens.
This is
Returns:
| Type | Description |
|---|---|
typing.List[yex.parse.token.Token]
|
a list of the Tokens consumed. |
Source code in yex/parse/tokeniser.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
eat_whitespace_after_control()
#
Eats all the next tokens which disappear after a control-- these being spaces and newlines.
Source code in yex/parse/tokeniser.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
peek()
#
Returns the next character to be produced by next(), but doesn't consume it. When you next call next(), or call peek() again, the result will be the same.
Source code in yex/parse/tokeniser.py
470 471 472 473 474 475 476 477 478 479 480 481 | |
push(thing)
#
Pushes something back. Next time someone reads the tokeniser, they will get this item-- unless someone pushes something else back, which will come out first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thing
|
typing.Any
|
anything you like, which gets pushed back. |
required |
Source code in yex/parse/tokeniser.py
75 76 77 78 79 80 81 82 83 84 | |