comparison docs/lexer-algpseudocode.rst @ 286:051c8877ee22

Implement lexer option "strict_tokentype". It allows the \ttX command to synthesize not yet existing token types.
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 21 May 2026 09:32:35 +0200
parents afbca50b7dc1
children 298841bc4dee
comparison
equal deleted inserted replaced
285:afbca50b7dc1 286:051c8877ee22
120 120
121 **Default:** :py:obj:`False` 121 **Default:** :py:obj:`False`
122 122
123 If :py:obj:`True` all the ``\ENDxxx`` commands will be skipped and yield 123 If :py:obj:`True` all the ``\ENDxxx`` commands will be skipped and yield
124 no output. 124 no output.
125
126 .. describe:: strict_tokentype
127
128 **Type::** :py:class:`bool`
129
130 **Default:** :py:obj:`True`
131
132 Control whether `Explicit Token Types`_ yield
133 :py:class:`pygments.token.Token.Generic.Error` tokens
134 (when ``True``, this is the default)
135 or a token type that is synthesized on the fly by
136 :py:func:`pygments.token.string_to_tokentype`
137 (when ``False``).
125 138
126 .. describe:: gets 139 .. describe:: gets
127 140
128 **Type:** :py:class:`str` or :py:obj:`None` 141 **Type:** :py:class:`str` or :py:obj:`None`
129 142
474 #. The content of the first argument `ARG1` must be a `value` in the 487 #. The content of the first argument `ARG1` must be a `value` in the
475 :py:data:`pygments.token.STANDARD_TYPES` dict. 488 :py:data:`pygments.token.STANDARD_TYPES` dict.
476 Its corresponding token type (the associated `key` in this dictionary) 489 Its corresponding token type (the associated `key` in this dictionary)
477 will be used as token type for the token. 490 will be used as token type for the token.
478 491
492 If a corresponding token type is not found the lexer's behaviour depends
493 on the lexer option ``strict_tokentype`` (see `Lexer Options`_):
494
495 If ``True`` (the default) the command yields a
496 :py:class:`pygments.token.Token.Generic.Error` token type for the
497 given command's content.
498
499 If ``False`` then the `Pygments`_ function
500 :py:func:`pygments.token.string_to_tokentype` will be called.
501 This function yields either an existing token type or synthesizes
502 a new one on the fly.
503 The associated highlighting in the output may not be well defined.
504
505 For this argument escaping is neither needed nor supported.
506
479 #. The content of the second argument will given the token type of 507 #. The content of the second argument will given the token type of
480 the first parameter. 508 the first parameter.
481 509
482 Standard `Escaping Rules`_ apply to this argument! 510 Standard `Escaping Rules`_ apply to this argument!
483 511
515 * Escaping is allowed and needed for the closing brace! 543 * Escaping is allowed and needed for the closing brace!
516 * The example token type is a "String". 544 * The example token type is a "String".
517 */ 545 */
518 \text{• \\ttX{s\}{Escaping brace \\\} and backslash \\\\!\}} \ttX{s}{Escaping brace \} and backslash \\!} 546 \text{• \\ttX{s\}{Escaping brace \\\} and backslash \\\\!\}} \ttX{s}{Escaping brace \} and backslash \\!}
519 /* 547 /*
520 * This is a non-existing token type: you get some generic error markup 548 * This is a non-existing token type:
521 * with a Generic.Error token and no expansion. 549 * by default you get some generic error markup with a Generic.Error
550 * token and no expansion.
551 * See also `Lexer Options` and `strict_tokentype`.
522 */ 552 */
523 \text{• \\ttX{NON-EXISTING\}{∈_∌\}(p1, p2)} \ttX{NON_EXISTING}{∈_∌}(p1, p2) 553 \text{• \\ttX{NON-EXISTING\}{∈_∌\}(p1, p2)} \ttX{NON_EXISTING}{∈_∌}(p1, p2)
554
555 An example with a lexer and ``strict_tokentype=False``
556 (highlighting obviously is like standard text with the templates used):
557
558 .. code-block:: nonstrict-algpseudocode
559
560 \text{• \\ttX{Generic.Not.Yet.Existing\}{∈_∌\}(p1, p2)} \ttX{Generic.Not.Yet.Existing}{∈_∌}(p1, p2)
524 561
525 562
526 563
527 Old Syntax (Deprecated) 564 Old Syntax (Deprecated)
528 ----------------------- 565 -----------------------