# HG changeset patch # User Franz Glasner # Date 1779290621 -7200 # Node ID ee512932d60346435b3edf42c2d11cc796c08dee # Parent 1b0e58f60f73af0567c357bca1f576da612529bd Make "\T" and "\E" aliases for "\TEXT" and "\EXPRESSION" diff -r 1b0e58f60f73 -r ee512932d603 docs/lexer-algpseudocode.rst --- a/docs/lexer-algpseudocode.rst Wed May 20 12:54:06 2026 +0200 +++ b/docs/lexer-algpseudocode.rst Wed May 20 17:23:41 2026 +0200 @@ -61,7 +61,7 @@ triple-double-quote, `Python`_ style) - Numbers (also `Python`_ style) - (Mathematical) operators and symbols - - ``\TEXT{...}`` + - ``\TEXT{...}`` or ``\T{...}`` Used to switch to a text-mode that prohibits automatic expression highlighting. @@ -69,7 +69,7 @@ A closing curly brace can be quoted with ``\}`` to not end the text mode prematurely. - - ``\EXPR`` or ``\EXPRESSION`` as nested construct + - ``\EXPR``, ``\EXPRESSION`` or ``\E`` as nested construct - ``\NAME``, ``\CALL`` and ``\GETS`` @@ -85,14 +85,14 @@ In `text` context it recognizes: - - ``\EXPR`` or ``\EXPRESSION`` + - ``\EXPRESSION``, ``\EXPR`` or ``\E`` Use to switch to expression-mode. A closing curly brace can be quoted with ``\}`` to not end the expression mode prematurely. - - ``\TEXT`` as nested construct + - ``\TEXT`` (aka ``\T``) as nested construct - ``\REM`` and ``\REMARK`` for remarks (aka comments) diff -r 1b0e58f60f73 -r ee512932d603 pygments_lexer_pseudocode2/lexers/algpseudocode.py --- a/pygments_lexer_pseudocode2/lexers/algpseudocode.py Wed May 20 12:54:06 2026 +0200 +++ b/pygments_lexer_pseudocode2/lexers/algpseudocode.py Wed May 20 17:23:41 2026 +0200 @@ -364,11 +364,11 @@ include("py-numbers"), (r"(?i)\\(call|name)[ \t]*(\{)", LexBase.op_ignore, "entity-name"), (r"(?i)\\gets\b", op_gets), - (r"(?i)\\text[ \t]*\{", LexBase.op_ignore, "text-statement"), - (r"(?i)\\expr(?:ession)?[ \t]*\{", + (r"(?i)\\e(?:xpr(?:ession)?)?[ \t]*\{", LexBase.op_ignore, "block-expr"), include("explicit-tokentype"), + (r"(?i)\\t(?:ext)?[ \t]*\{", LexBase.op_ignore, "text-statement"), include("remark"), include("keyword-constants"), include("word-operators"), @@ -384,11 +384,11 @@ include("py-numbers"), (r"(?i)\\(call|name)[ \t]*(\{)", LexBase.op_ignore, "entity-name"), (r"(?i)\\gets\b", op_gets), - (r"(?i)\\text[ \t]*\{", LexBase.op_ignore, "text-statement"), - (r"(?i)\\expr(?:ession)?[ \t]*\{", + (r"(?i)\\e(?:xpr(?:ession)?)?[ \t]*\{", LexBase.op_ignore, "block-expr"), include("explicit-tokentype"), + (r"(?i)\\t(?:ext)?[ \t]*\{", LexBase.op_ignore, "text-statement"), include("remark"), include("keyword-constants"), include("word-operators"), @@ -411,11 +411,11 @@ (r"\}", LexBase.op_ignore, "#pop"), (r"\n", Whitespace), (r"\\\}", LexBase.op_fixed(Text, "}")), - (r"(?i)\\expr(?:ession)?[ \t]*\{", + (r"(?i)\\e(?:xpr(?:ession)?)?[ \t]*\{", LexBase.op_ignore, "block-expr"), - (r"(?i)\\text[ \t]*\{", LexBase.op_ignore, "#push"), include("explicit-tokentype"), + (r"(?i)\\t(?:ext)?[ \t]*\{", LexBase.op_ignore, "#push"), include("remark"), (r"\\\\", LexBase.op_fixed(Text, "\\")), (r"\\", LexBase.op_fixed(Text, "\\")), # in text-mode: leave Text diff -r 1b0e58f60f73 -r ee512932d603 tests/test_algpseudo.py --- a/tests/test_algpseudo.py Wed May 20 12:54:06 2026 +0200 +++ b/tests/test_algpseudo.py Wed May 20 17:23:41 2026 +0200 @@ -365,6 +365,17 @@ """\\TEXT{the text \\rem the remark\nthe next text line}""", self.lexer)) + def test_text_short_alias(self): + self.assertTokenStreamEqualComplete( + [("Text", "the text "), + ("Text", "nested"), + ("Text", " trailer"), + ("Text.Whitespace", "\n"), + ], + pygments.lex( + """\\T{the text \\t{nested} trailer}""", + self.lexer)) + def test_comment_single_1(self): self.assertTokenStreamEqualComplete( [("Comment.Single", "// foo bar"), @@ -535,6 +546,17 @@ ], pygments.lex(r"\tstate{a 1.2 \\expr{x in X\} c}", self.lexer)) + def test_expr_short_alias(self): + self.assertTokenStreamEqualComplete( + [("Name.Entity", "foo"), + ("Text", " "), + ("Name.Entity", "bar"), + ("Text", " "), + ("Text", "bar +"), + ("Text.Whitespace", "\n"), + ], + pygments.lex(r"foo \e{bar} \t{bar +}", self.lexer)) + def test_text_in_expr(self): self.assertTokenStreamEqualComplete( [("Name.Entity", "first"),