comparison pygments_lexer_pseudocode2/pseudocode.py @ 34:1f741934205e

Begin a new Pseudocode lexer using numbers and strings from Python
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 21 Apr 2026 19:40:08 +0200
parents
children d9a3551a1038
comparison
equal deleted inserted replaced
33:db1bc740a201 34:1f741934205e
1 # -*- coding: utf-8 -*-
2 # :-
3 # SPDX-FileCopyrightText: © 2026 Franz Glasner
4 # SPDX-License-Identifier: MIT
5 # :-
6 r"""A pseudocode lexer along the lines of CTAN's algpseudocode or
7 algpseudocodex.
8
9 """
10
11 __all__ = ["PseudocodeLexer"]
12
13
14 import re
15
16 from pygments.lexer import include
17 from pygments.token import (Text, Whitespace)
18
19 #
20 # Relative imports do not work with pygments.lexers.load_lexer_from_file()
21 # in all of our supported Python releases.
22 #
23 from pygments_lexer_pseudocode2.bases import LexBase
24
25
26 class PseudocodeLexer(LexBase):
27
28 """A pseudocode lexer along the lines of CTAN's algpseudocode or
29 algpseudocodex.
30
31 Some ideas (e.g. strings) are borrowed from Pygment's Python lexer.
32
33 """
34
35 name = "Pseudocode"
36 aliases = ["pseudocode", "pseudo", "algorithm", "algo"]
37 filenames = ["*.algo", "*.pseudocode"]
38 mimetypes = []
39 flags = re.MULTILINE
40
41 tokens = {
42 "root": [
43 (r"\n", Whitespace),
44 (r"\\\n", Text),
45 include("expr"),
46 ],
47 "expr": [
48 include("py-strings"),
49 include("py-numbers"),
50 ]
51 }