annotate pygments_lexer_pseudocode2/algpseudocode.py @ 96:98cd0787f62f

FIX: FN alias for function
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 03 May 2026 15:15:34 +0200
parents dc17b778a52b
children dd4eb937485c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2 # :-
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
3 # SPDX-FileCopyrightText: © 2026 Franz Glasner
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
4 # SPDX-License-Identifier: MIT
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
5 # :-
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
6 r"""A pseudocode lexer along the lines of CTAN's algpseudocode or
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
7 algpseudocodex.
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
8
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
9 """
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
10
53
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
11 __all__ = ["AlgPseudocodeLexer",
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
12 "AlgPseudocodeLexer_DE", "AlgPseudocodeLexer_FR"]
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
13
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
14
89
7414eed7b275 Introduce logging for unhandled explicit token types
Franz Glasner <fzglas.hg@dom66.de>
parents: 87
diff changeset
15 import logging
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16 import re
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
18 import pygments.util
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
19 from pygments.lexer import bygroups, include, words
87
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
20 from pygments.token import (Comment, Generic, Keyword, Name, Operator,
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
21 Punctuation, Text, Whitespace)
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
22
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
23 #
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
24 # Relative imports do not work with pygments.lexers.load_lexer_from_file()
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
25 # in all of our supported Python releases.
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
26 #
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
27 from pygments_lexer_pseudocode2.bases import LexBase
85
ae5e741d2a9b Optimize op_explicit_tokentype(): use a pref-computed reversed pygments.token.STANDARD_TYPES
Franz Glasner <fzglas.hg@dom66.de>
parents: 84
diff changeset
28 from pygments_lexer_pseudocode2.utils import REVERSED_STANDARD_TYPES
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
30
89
7414eed7b275 Introduce logging for unhandled explicit token types
Franz Glasner <fzglas.hg@dom66.de>
parents: 87
diff changeset
31 #
7414eed7b275 Introduce logging for unhandled explicit token types
Franz Glasner <fzglas.hg@dom66.de>
parents: 87
diff changeset
32 # As in the local imports: use an explicit name because __name__ is
7414eed7b275 Introduce logging for unhandled explicit token types
Franz Glasner <fzglas.hg@dom66.de>
parents: 87
diff changeset
33 # __builtins__
7414eed7b275 Introduce logging for unhandled explicit token types
Franz Glasner <fzglas.hg@dom66.de>
parents: 87
diff changeset
34 #
7414eed7b275 Introduce logging for unhandled explicit token types
Franz Glasner <fzglas.hg@dom66.de>
parents: 87
diff changeset
35 _logger = logging.getLogger("pygments_lexer_pseudocode2.algpseudocode")
7414eed7b275 Introduce logging for unhandled explicit token types
Franz Glasner <fzglas.hg@dom66.de>
parents: 87
diff changeset
36
7414eed7b275 Introduce logging for unhandled explicit token types
Franz Glasner <fzglas.hg@dom66.de>
parents: 87
diff changeset
37
53
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
38 class AlgPseudocodeLexer(LexBase):
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
39
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
40 """A pseudocode lexer along the lines of CTAN's algpseudocode or
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
41 algpseudocodex.
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
42
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
43 Some ideas (e.g. strings) are borrowed from Pygment's Python lexer.
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
44
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
45 """
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
46
53
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
47 name = "AlgPseudocode"
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
48 aliases = ["algpseudocode", "algpseudo"]
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
49 filenames = ["*.algpseudo", "*.algpseudocode"]
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
50 mimetypes = []
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
51 flags = re.MULTILINE
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
52
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
53 LANG = "en"
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
54 TRANSLATIONS = {
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
55 "PROG": "PROGRAM",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
56 "PROGRAM": "PROGRAM",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
57 "ALGO": "ALGORITHM",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
58 "ALGORITHM": "ALGORITHM",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
59 "PROC": "PROCEDURE",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
60 "PROCEDURE": "PROCEDURE",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
61 "FUNC": "FUNCTION",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
62 "FUNCTION": "FUNCTION",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
63 "FN": "FUNCTION",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
64 "CLASS": "CLASS",
61
392745b66969 The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 58
diff changeset
65 "IS": "IS",
82
36a0ef76a6d7 Implement "\WITH"
Franz Glasner <fzglas.hg@dom66.de>
parents: 81
diff changeset
66 "WITH": "WITH",
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
67 }
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
68 END_TRANSLATIONS = {
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
69 "PROG": "END OF PROGRAM",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
70 "PROGRAM": "END OF PROGRAM",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
71 "ALGO": "END OF ALGORITHM",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
72 "ALGORITHM": "END OF ALGORITHM",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
73 "PROC": "END OF PROCEDURE",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
74 "PROCEDURE": "END OF PROCEDURE",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
75 "FUNC": "END OF FUNCTION",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
76 "FUNCTION": "END OF FUNCTION",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
77 "FN": "END OF FUNCTION",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
78 "CLASS": "END OF CLASS",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
79 }
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
80 DEFAULT_END_PREFIX = "END OF "
58
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
81 SYMBOL_REMARK = "▷" # U+25B7: Unicode 1.0 (Geometric Shapes)
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
82 # SYMBOL_REMARK = "▻" # U+25BB: Unicode 1.0 (Geometric Shapes)
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
83 SYMBOL_BLOCK = "◆" # U+25C6: Unicode 1.0 (Geometric Shapes)
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
84 # SYMBOL_BLOCK = "┃" # U+2503: Unicode 1.0 (Bow Drawing)
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
85 # SYMBOL_BLOCK = "●" # U+25CF: Unicode 1.0 (Geometric Shapes)
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
86 SYMBOL_TEXTSTATEMENT = "▪" # U+25AA: Unicode 1.0 (Geometric Shapes)
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
87 # SYMBOL_TEXTSTATEMENT = "■" # U+25A0: Unicode 1.0 (Geometric Shapes)
39
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
88 SYMBOLS = {
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
89 # Group REMARK
58
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
90 "REMARK": SYMBOL_REMARK,
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
91 "REM": SYMBOL_REMARK,
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
92 # Group STATEMENT
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
93 "STATEMENT": SYMBOL_BLOCK,
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
94 "STATE": SYMBOL_BLOCK,
58
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
95 "BLOCK": SYMBOL_BLOCK,
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
96 # Group TEXTSTATEMENT
58
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
97 "TEXTSTATEMENT": SYMBOL_TEXTSTATEMENT,
78
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
98 "TEXTSTATE": SYMBOL_TEXTSTATEMENT,
58
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
99 "TSTATEMENT": SYMBOL_TEXTSTATEMENT,
be065e5c8042 Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents: 57
diff changeset
100 "TSTATE": SYMBOL_TEXTSTATEMENT,
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
101 "TEXTBLOCK": SYMBOL_TEXTSTATEMENT,
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
102 "TBLOCK": SYMBOL_TEXTSTATEMENT,
39
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
103 }
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
104
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
105 def op_translate(toktype):
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
106
40
df08226a6984 Names for some entities (program, algorithm, function, procedure, class).
Franz Glasner <fzglas.hg@dom66.de>
parents: 39
diff changeset
107 def _op_translate(lexer, match, ctx=None):
df08226a6984 Names for some entities (program, algorithm, function, procedure, class).
Franz Glasner <fzglas.hg@dom66.de>
parents: 39
diff changeset
108 kw = match.group().upper()
38
69522d4cafac Remove another unneeded local variable
Franz Glasner <fzglas.hg@dom66.de>
parents: 35
diff changeset
109 yield match.start(), toktype, lexer.TRANSLATIONS.get(kw, kw)
83
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
110 if ctx:
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
111 ctx.pos = match.end()
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
112
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
113 return _op_translate
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
114
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
115 def op_opt_end_translate(toktype):
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
116
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
117 def _op_end_translate(lexer, match, ctx=None):
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
118 if not lexer.no_end:
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
119 kw = match.group().upper()
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
120 yield (match.start(),
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
121 toktype,
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
122 lexer.END_TRANSLATIONS.get(
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
123 kw,
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
124 lexer.DEFAULT_END_PREFIX + kw))
83
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
125 if ctx:
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
126 ctx.pos = match.end()
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
127
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
128 return _op_end_translate
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
129
62
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
130 def op_opt_ignore(toktype):
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
131
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
132 def _op_opt_ignore(lexer, match, ctx=None):
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
133 if not lexer.no_end:
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
134 yield match.start(), toktype, match.group()
83
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
135 if ctx:
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
136 ctx.pos = match.end()
62
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
137
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
138 return _op_opt_ignore
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
139
72
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
140 def op_opt_ignore_or_fixed(toktype, value):
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
141 """Yield a fixed given token type and value or -- if the lexer's
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
142 `no_end` setting evals to ``True`` nothing.
65
3f4223a79d2b Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents: 64
diff changeset
143
3f4223a79d2b Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents: 64
diff changeset
144 """
72
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
145
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
146 def _op_opt_ignore_or_fixed(lexer, match, ctx=None):
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
147 if not lexer.no_end:
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
148 yield match.start(), toktype, value
83
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
149 if ctx:
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
150 ctx.pos = match.end()
72
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
151
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
152 return _op_opt_ignore_or_fixed
65
3f4223a79d2b Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents: 64
diff changeset
153
39
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
154 def op_symbol(toktype):
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
155
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
156 def _op_symbol(lexer, match, ctx=None):
64
05c53e431c88 Simplify case-handling for "BLOCK" and "REMARK"
Franz Glasner <fzglas.hg@dom66.de>
parents: 62
diff changeset
157 kw = match.group().upper()
39
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
158 yield match.start(), toktype, lexer.SYMBOLS.get(kw, kw)
83
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
159 if ctx:
cd79d2c76347 If a Pygments callback gets a "Context" it must set the new position explicitely.
Franz Glasner <fzglas.hg@dom66.de>
parents: 82
diff changeset
160 ctx.pos = match.end()
39
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
161
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
162 return _op_symbol
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
163
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
164 def op_explicit_tokentype(lexer, match, ctx=None):
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
165 needed_css = match.group("type")
87
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
166 toktype = REVERSED_STANDARD_TYPES.get(needed_css, None)
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
167 if toktype is None:
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
168 # Be more error friendly
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
169 toktype = Generic.Error
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
170 val = match.group()
89
7414eed7b275 Introduce logging for unhandled explicit token types
Franz Glasner <fzglas.hg@dom66.de>
parents: 87
diff changeset
171 _logger.warning("Unhandled explicit token type: %s", val)
87
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
172 else:
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
173 val = match.group("character")
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
174 yield match.start(), toktype, val
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
175 if ctx:
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
176 ctx.pos = match.end()
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
177
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
178 tokens = {
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
179 "root": [
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
180 (r"\n", Whitespace),
39
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
181 (r"/\*", Comment.Multiline, "multiline-nested-comment"),
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
182 (r"//.*$", Comment.Single),
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
183 include("remark"),
90
2af4684c8e78 Restrict whitespace before required and optional arguments.
Franz Glasner <fzglas.hg@dom66.de>
parents: 89
diff changeset
184 (r"(?i)\\(block|state(?:ment)?)[ \t]*(\{)",
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
185 bygroups(op_symbol(Text), LexBase.op_fixed(Whitespace, " ")),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
186 "block-expr"),
78
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
187 (r"(?i)\\("
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
188 r"(?:textstate(?:ment)?)"
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
189 r"|(?:tstate(?:ment)?)"
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
190 r"|(?:textblock)"
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
191 r"|(?:tblock)"
90
2af4684c8e78 Restrict whitespace before required and optional arguments.
Franz Glasner <fzglas.hg@dom66.de>
parents: 89
diff changeset
192 r")[ \t]*(\{)",
78
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
193 bygroups(op_symbol(Text), LexBase.op_fixed(Whitespace, " ")),
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
194 "text-statement"),
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
195 (r"\\\n", Text),
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
196 (r"(?i)\\("
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
197 r"(?:prog(?:ram)?)"
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
198 r"|(?:algo(?:rithm)?)"
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
199 r"|(?:proc(?:edure)?)"
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
200 r"|(?:func(?:tion)?|(?:fn))"
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
201 r"|(?:class)"
90
2af4684c8e78 Restrict whitespace before required and optional arguments.
Franz Glasner <fzglas.hg@dom66.de>
parents: 89
diff changeset
202 r")[ \t]*(\{)",
72
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
203 bygroups(op_translate(Keyword),
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
204 LexBase.op_fixed(Whitespace, " ")),
40
df08226a6984 Names for some entities (program, algorithm, function, procedure, class).
Franz Glasner <fzglas.hg@dom66.de>
parents: 39
diff changeset
205 "entity-name"),
94
dc17b778a52b Refactor \END variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 93
diff changeset
206 # ENDxxx keywords with optional entity name in two parts:
dc17b778a52b Refactor \END variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 93
diff changeset
207 # 1. with name
dc17b778a52b Refactor \END variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 93
diff changeset
208 (r"(?i)\\end(?:[_\-]|(?:[ \t]+))?("
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
209 r"(?:prog(?:ram)?)"
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
210 r"|(?:algo(?:rithm)?)"
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
211 r"|(?:proc(?:edure)?)"
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
212 r"|(?:func(?:tion)?)"
96
98cd0787f62f FIX: FN alias for function
Franz Glasner <fzglas.hg@dom66.de>
parents: 94
diff changeset
213 r"|(?:fn)"
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
214 r"|(?:class)"
94
dc17b778a52b Refactor \END variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 93
diff changeset
215 r")(?:[_\-]|(?:[\t ]+))?(\{)",
62
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
216 bygroups(op_opt_end_translate(Keyword),
72
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
217 op_opt_ignore_or_fixed(Whitespace, " ")),
62
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
218 "entity-name-end"),
94
dc17b778a52b Refactor \END variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 93
diff changeset
219 # 2. without name
dc17b778a52b Refactor \END variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 93
diff changeset
220 # 3. AND keywords that do not allow a param (e.g. endif)
dc17b778a52b Refactor \END variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 93
diff changeset
221 (r"(?i)\\end(?:[_\-]|(?:[ \t]+))?("
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
222 r"(?:prog(?:ram)?)"
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
223 r"|(?:algo(?:rithm)?)"
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
224 r"|(?:proc(?:edure)?)"
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
225 r"|(?:func(?:tion)?)"
96
98cd0787f62f FIX: FN alias for function
Franz Glasner <fzglas.hg@dom66.de>
parents: 94
diff changeset
226 r"|(?:fn)"
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
227 r"|(?:class)"
62
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
228 r")\b",
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
229 bygroups(op_opt_end_translate(Keyword))),
61
392745b66969 The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 58
diff changeset
230 # Keywords
392745b66969 The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 58
diff changeset
231 (r"(?i)\\("
392745b66969 The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 58
diff changeset
232 r"(?:is)"
82
36a0ef76a6d7 Implement "\WITH"
Franz Glasner <fzglas.hg@dom66.de>
parents: 81
diff changeset
233 r"|(?:with)"
61
392745b66969 The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 58
diff changeset
234 r")\b",
392745b66969 The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 58
diff changeset
235 bygroups(op_translate(Keyword))),
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
236 include("expr"),
91
feb41c8d72d2 Instead of "\s+" use "[^\S\n]+" because a \n is not wanted really in this match.
Franz Glasner <fzglas.hg@dom66.de>
parents: 90
diff changeset
237 (r"[^\S\n]+", Text),
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
238 ],
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
239 "remark": [
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
240 (r"(?i)\\(remark|rem)\b(.*)$",
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
241 bygroups(op_symbol(Comment.Single), Comment.Single)),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
242 ],
62
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
243 "entity-name": [ # may be multiline
40
df08226a6984 Names for some entities (program, algorithm, function, procedure, class).
Franz Glasner <fzglas.hg@dom66.de>
parents: 39
diff changeset
244 (r"[^\\}]+", Name.Entity),
77
1a5e192aa950 Move popping states consistently more to the begin
Franz Glasner <fzglas.hg@dom66.de>
parents: 76
diff changeset
245 (r"\}", LexBase.op_ignore, "#pop"),
74
c1357674622d Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents: 72
diff changeset
246 (r"\\\}", LexBase.op_fixed(Name.Entity, "}")),
76
27e12387154d FIX: Handle escape character more thoroughly: also explicitely handle "\\"
Franz Glasner <fzglas.hg@dom66.de>
parents: 75
diff changeset
247 (r"\\\\", LexBase.op_fixed(Name.Entity, "\\")),
74
c1357674622d Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents: 72
diff changeset
248 (r"\\", LexBase.op_fixed(Name.Entity, "\\")),
62
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
249 ],
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
250 "entity-name-end": [ # may be multiline -- suppressed if no_end
7153e945a3d6 Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents: 61
diff changeset
251 (r"[^\\}]+", op_opt_ignore(Name.Entity)),
77
1a5e192aa950 Move popping states consistently more to the begin
Franz Glasner <fzglas.hg@dom66.de>
parents: 76
diff changeset
252 (r"\}", LexBase.op_ignore, "#pop"),
74
c1357674622d Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents: 72
diff changeset
253 (r"\\\}", op_opt_ignore_or_fixed(Name.Entity, "}")),
76
27e12387154d FIX: Handle escape character more thoroughly: also explicitely handle "\\"
Franz Glasner <fzglas.hg@dom66.de>
parents: 75
diff changeset
254 (r"\\\\", op_opt_ignore_or_fixed(Name.Entity, "\\")),
74
c1357674622d Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents: 72
diff changeset
255 (r"\\", op_opt_ignore_or_fixed(Name.Entity, "\\")),
40
df08226a6984 Names for some entities (program, algorithm, function, procedure, class).
Franz Glasner <fzglas.hg@dom66.de>
parents: 39
diff changeset
256 ],
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
257 "expr": [
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
258 include("punctuation"),
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
259 include("py-strings"),
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
260 include("py-numbers"),
90
2af4684c8e78 Restrict whitespace before required and optional arguments.
Franz Glasner <fzglas.hg@dom66.de>
parents: 89
diff changeset
261 (r"(?i)\\text[ \t]*\{", LexBase.op_ignore, "text-in-expr"),
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
262 include("explicit-tokentype"),
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
263 include("remark"),
81
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
264 include("keyword-constants"),
93
84c0f761c836 Renamed "text-operators" to "word-operators" and allow more case-variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
265 include("word-operators"),
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
266 include("math-builtins"),
52
5bfa9113d3c4 First tests with "py-name": names from the Python lexer
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
267 include("py-name"),
70
5517b0be67f0 Basic "\TEXT" escape for expressions
Franz Glasner <fzglas.hg@dom66.de>
parents: 65
diff changeset
268 ],
80
f487f0d322a5 Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents: 78
diff changeset
269 "expr-in-braces": [
f487f0d322a5 Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents: 78
diff changeset
270 include("punctuation-in-braces"),
f487f0d322a5 Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents: 78
diff changeset
271 include("py-strings"),
f487f0d322a5 Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents: 78
diff changeset
272 include("py-numbers"),
90
2af4684c8e78 Restrict whitespace before required and optional arguments.
Franz Glasner <fzglas.hg@dom66.de>
parents: 89
diff changeset
273 (r"(?i)\\text[ \t]*\{", LexBase.op_ignore, "text-in-expr"),
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
274 include("explicit-tokentype"),
80
f487f0d322a5 Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents: 78
diff changeset
275 include("remark"),
81
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
276 include("keyword-constants"),
93
84c0f761c836 Renamed "text-operators" to "word-operators" and allow more case-variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
277 include("word-operators"),
80
f487f0d322a5 Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents: 78
diff changeset
278 include("math-builtins"),
f487f0d322a5 Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents: 78
diff changeset
279 include("py-name"),
f487f0d322a5 Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents: 78
diff changeset
280 ],
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
281 "block-expr": [ # somewhat similar to "root"
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
282 (r"\}", LexBase.op_ignore, "#pop"),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
283 (r"\n", Whitespace),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
284 include("expr-in-braces"),
76
27e12387154d FIX: Handle escape character more thoroughly: also explicitely handle "\\"
Franz Glasner <fzglas.hg@dom66.de>
parents: 75
diff changeset
285 (r"\\\\", LexBase.op_fixed(Text, "\\")),
27e12387154d FIX: Handle escape character more thoroughly: also explicitely handle "\\"
Franz Glasner <fzglas.hg@dom66.de>
parents: 75
diff changeset
286 (r"\\", LexBase.op_fixed(Text, "\\")),
91
feb41c8d72d2 Instead of "\s+" use "[^\S\n]+" because a \n is not wanted really in this match.
Franz Glasner <fzglas.hg@dom66.de>
parents: 90
diff changeset
287 (r"[^\S\n]+", Text),
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
288 ],
78
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
289 "text-statement": [ # like block but default to text-mode
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
290 (r"[^\\}\n]+", Text),
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
291 (r"\}", LexBase.op_ignore, "#pop"),
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
292 (r"\n", Whitespace),
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
293 (r"\\\}", LexBase.op_fixed(Text, "}")),
90
2af4684c8e78 Restrict whitespace before required and optional arguments.
Franz Glasner <fzglas.hg@dom66.de>
parents: 89
diff changeset
294 (r"(?i)\\expr(?:ession)?[ \t]*\{",
78
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
295 LexBase.op_ignore,
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
296 "block-expr"),
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
297 include("explicit-tokentype"),
78
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
298 include("remark"),
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
299 (r"\\\\", LexBase.op_fixed(Text, "\\")),
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
300 (r"\\", LexBase.op_fixed(Text, "\\")),
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
301 ],
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
302 "text-in-expr": [
77
1a5e192aa950 Move popping states consistently more to the begin
Franz Glasner <fzglas.hg@dom66.de>
parents: 76
diff changeset
303 (r"[^\\}\n]+", Text),
1a5e192aa950 Move popping states consistently more to the begin
Franz Glasner <fzglas.hg@dom66.de>
parents: 76
diff changeset
304 (r"\}", LexBase.op_ignore, "#pop"),
1a5e192aa950 Move popping states consistently more to the begin
Franz Glasner <fzglas.hg@dom66.de>
parents: 76
diff changeset
305 (r"\n", Whitespace),
72
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
306 (r"\\\}", LexBase.op_fixed(Text, "}")),
92
3f37832c405d FIX: Wrong state for \TEXT command
Franz Glasner <fzglas.hg@dom66.de>
parents: 91
diff changeset
307 (r"(?i)\\expr(?:ession)?[ \t]*\{",
3f37832c405d FIX: Wrong state for \TEXT command
Franz Glasner <fzglas.hg@dom66.de>
parents: 91
diff changeset
308 LexBase.op_ignore,
3f37832c405d FIX: Wrong state for \TEXT command
Franz Glasner <fzglas.hg@dom66.de>
parents: 91
diff changeset
309 "block-expr"),
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
310 include("explicit-tokentype"),
78
abb2e8c65d0f Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
311 (r"\\\\", LexBase.op_fixed(Text, "\\")),
72
206017a08ed7 Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
Franz Glasner <fzglas.hg@dom66.de>
parents: 70
diff changeset
312 (r"\\", LexBase.op_fixed(Text, "\\")),
70
5517b0be67f0 Basic "\TEXT" escape for expressions
Franz Glasner <fzglas.hg@dom66.de>
parents: 65
diff changeset
313 ],
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
314 "math-builtins": [
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
315 (words(("sqrt", "pow", "cos", "sin", "tan", "arcos", "arcsin",
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
316 "arctan", "arctan2", "mod", "exp", "ln", "log"),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
317 prefix=r"(?<!\.)",
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
318 suffix=r"\b"),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
319 Name.Builtin),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
320 ],
93
84c0f761c836 Renamed "text-operators" to "word-operators" and allow more case-variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
321 "word-operators": [
84c0f761c836 Renamed "text-operators" to "word-operators" and allow more case-variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
322 (words(("IN", "In", "in",
84c0f761c836 Renamed "text-operators" to "word-operators" and allow more case-variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
323 "IS", "Is", "is",
84c0f761c836 Renamed "text-operators" to "word-operators" and allow more case-variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
324 "AND", "And", "and",
84c0f761c836 Renamed "text-operators" to "word-operators" and allow more case-variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
325 "OR", "Or", "or",
84c0f761c836 Renamed "text-operators" to "word-operators" and allow more case-variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
326 "XOR", "Xor", "xor",
84c0f761c836 Renamed "text-operators" to "word-operators" and allow more case-variants
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
327 "NOT", "Not", "not"),
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
328 prefix=r"(?<!\.)",
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
329 suffix=r"\b"),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
330 Operator.Word),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
331 ],
81
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
332 "keyword-constants": [
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
333 (words(("True", "TRUE", "true", "False", "FALSE", "false",
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
334 "None", "NONE", "non", "Nil", "NIL", "nil",
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
335 "Null", "NULL", "null",
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
336 "Empty", "EMPTY", "empty"),
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
337 prefix=r"(?<!\.)",
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
338 suffix=r"\b"),
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
339 Keyword.Constant),
6d8b813fb296 Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents: 80
diff changeset
340 ],
75
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
341 "punctuation": [
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
342 (r"[{}:(),;[\]]", Punctuation),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
343 ],
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
344 "punctuation-in-braces": [
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
345 # like "punctuation" but needs an escaped curly brace for }
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
346 (r"\\\}", LexBase.op_fixed(Punctuation, "}")),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
347 (r"[{:(),;[\]]", Punctuation),
711f8d19e27a New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents: 74
diff changeset
348 ],
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
349 "explicit-tokentype": [
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
350 # All these REs are CASE-SENSITIVE!
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
351
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
352 # Multiple characters possible, but no escaping!
87
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
353 (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)(?P<sep>[/:|=*+!\$~])"
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
354 r"(?P<character>(.|\n)+?)(?P=sep)",
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
355 op_explicit_tokentype),
87
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
356 (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)\{(?P<character>[^}]+?)\}",
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
357 op_explicit_tokentype),
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
358 (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)\((?P<character>[^)]+?)\)",
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
359 op_explicit_tokentype),
87
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
360 (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)<(?P<character>[^>]+?)>",
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
361 op_explicit_tokentype),
87
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
362 (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)\[(?P<character>[^\]]+?)\]",
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
363 op_explicit_tokentype),
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
364
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
365 # Every character is possible: no escaping needed!
87
d8ca835c74ea FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
366 (r"\\tt-(?P<type>[^/]+?)/(?P<character>(?:.|\n))",
84
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
367 op_explicit_tokentype),
3ac1c4502ad0 Implement "\tt-XXX" and "ttx-XXX" for explicit token types.
Franz Glasner <fzglas.hg@dom66.de>
parents: 83
diff changeset
368 ],
34
1f741934205e Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
369 }
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
370
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
371 def __init__(self, **options):
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
372 val = pygments.util.get_bool_opt(options, "no_end", default=False)
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
373 self.no_end = val
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
374 LexBase.__init__(self, **options)
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
375
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
376
53
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
377 class AlgPseudocodeLexer_DE(AlgPseudocodeLexer):
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
378
53
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
379 name = "AlgPseudocodeDE"
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
380 aliases = ["algpseudocode-de", "algpseudo-de"]
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
381 filenames = ["*.algpseudo-de", "*.algpseudocode-de"]
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
382
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
383 LANG = "de"
53
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
384 TRANSLATIONS = AlgPseudocodeLexer.TRANSLATIONS.copy()
41
4ccf9a8d0bf2 For the german and french PseudocodeLexer: Use en translations as fallback.
Franz Glasner <fzglas.hg@dom66.de>
parents: 40
diff changeset
385 TRANSLATIONS.update({
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
386 "PROG": "PROGRAMM",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
387 "PROGRAM": "PROGRAMM",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
388 "ALGO": "ALGORITHMUS",
39
a3151d837258 Some basic keywords for programs, algorithms, procedures and functions; also comments (single and multiline) and "remarks"
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
389 "ALGORITHM": "ALGORITHMUS",
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
390 "PROC": "PROZEDUR",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
391 "PROCEDURE": "PROZEDUR",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
392 "FUNC": "FUNKTION",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
393 "FUNCTION": "FUNKTION",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
394 "FN": "FUNKTION",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
395 "CLASS": "KLASSE",
61
392745b66969 The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 58
diff changeset
396 "IS": "IST",
82
36a0ef76a6d7 Implement "\WITH"
Franz Glasner <fzglas.hg@dom66.de>
parents: 81
diff changeset
397 "WITH": "MIT",
41
4ccf9a8d0bf2 For the german and french PseudocodeLexer: Use en translations as fallback.
Franz Glasner <fzglas.hg@dom66.de>
parents: 40
diff changeset
398 })
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
399 END_TRANSLATIONS = AlgPseudocodeLexer.END_TRANSLATIONS.copy()
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
400 END_TRANSLATIONS.update({
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
401 "PROG": "ENDE DES PROGRAMMS",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
402 "PROGRAM": "ENDE VON PROGRAMMS",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
403 "ALGO": "ENDE DES ALGORITHMUS",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
404 "ALGORITHM": "ENDE DES ALGORITHMUS",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
405 "PROC": "ENDE DER PROZEDUR",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
406 "PROCEDURE": "ENDE DER PROZEDUR",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
407 "FUNC": "ENDE DER FUNKTION",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
408 "FUNCTION": "ENDE DER FUNKTION",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
409 "FN": "ENDE DER FUNKTION",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
410 "CLASS": "ENDE DER KLASSE",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
411 })
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
412 DEFAULT_END_PREFIX = "ENDE VON "
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
413
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
414
53
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
415 class AlgPseudocodeLexer_FR(AlgPseudocodeLexer):
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
416
53
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
417 name = "AlgPseudocodeFR"
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
418 aliases = ["algpseudocode-fr", "algpseudo-fr"]
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
419 filenames = ["*.algpseudo-fr", "*.algpseudocode-fr"]
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
420
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
421 LANG = "de"
53
39151225fb84 Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents: 52
diff changeset
422 TRANSLATIONS = AlgPseudocodeLexer.TRANSLATIONS.copy()
41
4ccf9a8d0bf2 For the german and french PseudocodeLexer: Use en translations as fallback.
Franz Glasner <fzglas.hg@dom66.de>
parents: 40
diff changeset
423 TRANSLATIONS.update({
35
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
424 "PROG": "PROGRAMME",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
425 "PROGRAM": "PROGRAMME",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
426 "ALGO": "ALGORITHME",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
427 "ALGORITHM": "ALGORITHME",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
428 "PROC": "PROCÉDURE",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
429 "PROCEDURE": "PROCÉDURE",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
430 "FUNC": "FONCTION",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
431 "FUNCTION": "FOUNCTION",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
432 "FN": "FONCTION",
d9a3551a1038 Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
433 "CLASS": "CLASSE",
61
392745b66969 The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 58
diff changeset
434 "IS": "EST",
82
36a0ef76a6d7 Implement "\WITH"
Franz Glasner <fzglas.hg@dom66.de>
parents: 81
diff changeset
435 "WITH": "AVEC",
41
4ccf9a8d0bf2 For the german and french PseudocodeLexer: Use en translations as fallback.
Franz Glasner <fzglas.hg@dom66.de>
parents: 40
diff changeset
436 })
57
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
437 END_TRANSLATIONS = AlgPseudocodeLexer.END_TRANSLATIONS.copy()
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
438 END_TRANSLATIONS.update({
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
439 "PROG": "FIN DE PROGRAMME",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
440 "PROGRAM": "FIN DE PROGRAMME",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
441 "ALGO": "FIN D'ALGORITHME",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
442 "ALGORITHM": "FIN D'ALGORITHME",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
443 "PROC": "FIN DE PROCÉDURE",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
444 "PROCEDURE": "FIN DE PROCÉDURE",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
445 "FUNC": "FIN DE FONCTION",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
446 "FUNCTION": "FIN DE FOUNCTION",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
447 "FN": "FIN DE FONCTION",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
448 "CLASS": "FIN DE CLASSE",
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
449 })
e8f4af9e20a8 Some "ENDxxx" commands
Franz Glasner <fzglas.hg@dom66.de>
parents: 53
diff changeset
450 DEFAULT_END_PREFIX = "FIN DE "