Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
annotate pygments_lexer_pseudocode2/algpseudocode.py @ 76:27e12387154d
FIX: Handle escape character more thoroughly: also explicitely handle "\\"
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 30 Apr 2026 09:20:35 +0200 |
| parents | 711f8d19e27a |
| children | 1a5e192aa950 |
| rev | line source |
|---|---|
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
1 |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
3 # :- |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
4 # 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
|
5 # 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
|
6 # :- |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
7 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
|
8 algpseudocodex. |
|
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 """ |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
11 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
12 __all__ = ["AlgPseudocodeLexer", |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
13 "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
|
14 |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
15 |
|
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 | 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 |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
20 from pygments.token import (Comment, Keyword, Name, Operator, Punctuation, |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
21 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 |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
28 |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
29 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
30 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
|
31 |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
32 """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
|
33 algpseudocodex. |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
34 |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
35 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
|
36 |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
37 """ |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
38 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
39 name = "AlgPseudocode" |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
40 aliases = ["algpseudocode", "algpseudo"] |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
41 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
|
42 mimetypes = [] |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
43 flags = re.MULTILINE |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
44 |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
45 LANG = "en" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
46 TRANSLATIONS = { |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
47 "PROG": "PROGRAM", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
48 "PROGRAM": "PROGRAM", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
49 "ALGO": "ALGORITHM", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
50 "ALGORITHM": "ALGORITHM", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
51 "PROC": "PROCEDURE", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
52 "PROCEDURE": "PROCEDURE", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
53 "FUNC": "FUNCTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
54 "FUNCTION": "FUNCTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
55 "FN": "FUNCTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
56 "CLASS": "CLASS", |
|
61
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
57 "IS": "IS", |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
58 } |
| 57 | 59 END_TRANSLATIONS = { |
| 60 "PROG": "END OF PROGRAM", | |
| 61 "PROGRAM": "END OF PROGRAM", | |
| 62 "ALGO": "END OF ALGORITHM", | |
| 63 "ALGORITHM": "END OF ALGORITHM", | |
| 64 "PROC": "END OF PROCEDURE", | |
| 65 "PROCEDURE": "END OF PROCEDURE", | |
| 66 "FUNC": "END OF FUNCTION", | |
| 67 "FUNCTION": "END OF FUNCTION", | |
| 68 "FN": "END OF FUNCTION", | |
| 69 "CLASS": "END OF CLASS", | |
| 70 } | |
| 71 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
|
72 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
|
73 # 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
|
74 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
|
75 # 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
|
76 # 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
|
77 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
|
78 # 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
|
79 SYMBOLS = { |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
80 # 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
|
81 "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
|
82 "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
|
83 # Group STATEMENT |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
84 "STATEMENT": SYMBOL_BLOCK, |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
85 "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
|
86 "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
|
87 # 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
|
88 "TEXTSTATEMENT": SYMBOL_TEXTSTATEMENT, |
|
be065e5c8042
Prepare symbols for a statement which defaults to token type "Text".
Franz Glasner <fzglas.hg@dom66.de>
parents:
57
diff
changeset
|
89 "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
|
90 "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
|
91 "TEXTBLOCK": SYMBOL_TEXTSTATEMENT, |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
92 "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
|
93 } |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
94 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
95 def op_translate(toktype): |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
96 |
|
40
df08226a6984
Names for some entities (program, algorithm, function, procedure, class).
Franz Glasner <fzglas.hg@dom66.de>
parents:
39
diff
changeset
|
97 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
|
98 kw = match.group().upper() |
|
38
69522d4cafac
Remove another unneeded local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
35
diff
changeset
|
99 yield match.start(), toktype, lexer.TRANSLATIONS.get(kw, kw) |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
100 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
101 return _op_translate |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
102 |
| 57 | 103 def op_opt_end_translate(toktype): |
| 104 | |
| 105 def _op_end_translate(lexer, match, ctx=None): | |
| 106 if not lexer.no_end: | |
| 107 kw = match.group().upper() | |
| 108 yield (match.start(), | |
| 109 toktype, | |
| 110 lexer.END_TRANSLATIONS.get( | |
| 111 kw, | |
| 112 lexer.DEFAULT_END_PREFIX + kw)) | |
| 113 | |
| 114 return _op_end_translate | |
| 115 | |
|
62
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
116 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
|
117 |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
118 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
|
119 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
|
120 yield match.start(), toktype, match.group() |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
121 |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
122 return _op_opt_ignore |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
123 |
|
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
|
124 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
|
125 """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
|
126 `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
|
127 |
|
3f4223a79d2b
Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents:
64
diff
changeset
|
128 """ |
|
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
|
129 |
|
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
|
130 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
|
131 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
|
132 yield match.start(), 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
|
133 |
|
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
|
134 return _op_opt_ignore_or_fixed |
|
65
3f4223a79d2b
Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents:
64
diff
changeset
|
135 |
|
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
|
136 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
|
137 |
|
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
|
138 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
|
139 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
|
140 yield match.start(), toktype, lexer.SYMBOLS.get(kw, kw) |
|
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
|
141 |
|
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
|
142 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
|
143 |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
144 tokens = { |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
145 "root": [ |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
146 (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
|
147 (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
|
148 (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
|
149 include("remark"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
150 (r"(?i)\\(block|state(?:ment)?)\s*(\{)", |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
151 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
|
152 "block-expr"), |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
153 (r"\\\n", Text), |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
154 (r"(?i)\\(" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
155 r"(?:prog(?:ram)?)" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
156 r"|(?:algo(?:rithm)?)" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
157 r"|(?:proc(?:edure)?)" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
158 r"|(?:func(?:tion)?|(?:fn))" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
159 r"|(?:class)" |
|
65
3f4223a79d2b
Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents:
64
diff
changeset
|
160 r")\s*(\{)", |
|
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
|
161 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
|
162 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
|
163 "entity-name"), |
| 57 | 164 # ENDxxx keywords with optional entity name |
| 165 # with name | |
| 166 (r"(?i)\\end(?:_|-)?(" | |
| 167 r"(?:prog(?:ram)?)" | |
| 168 r"|(?:algo(?:rithm)?)" | |
| 169 r"|(?:proc(?:edure)?)" | |
| 170 r"|(?:func(?:tion)?)" | |
| 171 r"|(?:class)" | |
|
65
3f4223a79d2b
Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents:
64
diff
changeset
|
172 r")\s*(\{)", |
|
62
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
173 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
|
174 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
|
175 "entity-name-end"), |
| 57 | 176 # without name |
| 177 (r"(?i)\\end(?:_|-)?(" | |
| 178 r"(?:prog(?:ram)?)" | |
| 179 r"|(?:algo(?:rithm)?)" | |
| 180 r"|(?:proc(?:edure)?)" | |
| 181 r"|(?:func(?:tion)?)" | |
| 182 r"|(?:class)" | |
|
62
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
183 r")\b", |
| 57 | 184 bygroups(op_opt_end_translate(Keyword))), |
|
61
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
185 # Keywords |
|
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
186 (r"(?i)\\(" |
|
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
187 r"(?:is)" |
|
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
188 r")\b", |
|
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
189 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
|
190 include("expr"), |
|
52
5bfa9113d3c4
First tests with "py-name": names from the Python lexer
Franz Glasner <fzglas.hg@dom66.de>
parents:
41
diff
changeset
|
191 (r"\s+", Text), |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
192 ], |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
193 "remark": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
194 (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
|
195 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
|
196 ], |
|
62
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
197 "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
|
198 (r"[^\\}]+", Name.Entity), |
|
74
c1357674622d
Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents:
72
diff
changeset
|
199 (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
|
200 (r"\\\\", LexBase.op_fixed(Name.Entity, "\\")), |
|
74
c1357674622d
Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents:
72
diff
changeset
|
201 (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
|
202 (r"\}", LexBase.op_ignore, "#pop"), |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
203 ], |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
204 "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
|
205 (r"[^\\}]+", op_opt_ignore(Name.Entity)), |
|
74
c1357674622d
Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents:
72
diff
changeset
|
206 (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
|
207 (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
|
208 (r"\\", op_opt_ignore_or_fixed(Name.Entity, "\\")), |
|
62
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
209 (r"\}", LexBase.op_ignore, "#pop"), |
|
40
df08226a6984
Names for some entities (program, algorithm, function, procedure, class).
Franz Glasner <fzglas.hg@dom66.de>
parents:
39
diff
changeset
|
210 ], |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
211 "expr": [ |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
212 include("punctuation"), |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
213 include("py-strings"), |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
214 include("py-numbers"), |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
215 (r"(?i)\\text\s*\{", LexBase.op_ignore, "text-in-expr"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
216 include("remark"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
217 include("text-operators"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
218 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
|
219 include("py-name"), |
|
70
5517b0be67f0
Basic "\TEXT" escape for expressions
Franz Glasner <fzglas.hg@dom66.de>
parents:
65
diff
changeset
|
220 ], |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
221 "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
|
222 (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
|
223 (r"\n", Whitespace), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
224 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
|
225 (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
|
226 (r"\\", LexBase.op_fixed(Text, "\\")), |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
227 (r"\s+", Text), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
228 ], |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
229 "expr-in-braces": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
230 include("punctuation-in-braces"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
231 include("py-strings"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
232 include("py-numbers"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
233 (r"(?i)\\text\s*\{", LexBase.op_ignore, "text-in-expr"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
234 include("remark"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
235 include("text-operators"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
236 include("math-builtins"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
237 include("py-name"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
238 ], |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
239 "text-in-expr": [ |
|
70
5517b0be67f0
Basic "\TEXT" escape for expressions
Franz Glasner <fzglas.hg@dom66.de>
parents:
65
diff
changeset
|
240 (r"[^\\}]+", 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
|
241 (r"\\\}", LexBase.op_fixed(Text, "}")), |
|
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
|
242 (r"\\", LexBase.op_fixed(Text, "\\")), |
|
70
5517b0be67f0
Basic "\TEXT" escape for expressions
Franz Glasner <fzglas.hg@dom66.de>
parents:
65
diff
changeset
|
243 (r"\}", LexBase.op_ignore, "#pop"), |
|
5517b0be67f0
Basic "\TEXT" escape for expressions
Franz Glasner <fzglas.hg@dom66.de>
parents:
65
diff
changeset
|
244 ], |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
245 "math-builtins": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
246 (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
|
247 "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
|
248 prefix=r"(?<!\.)", |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
249 suffix=r"\b"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
250 Name.Builtin), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
251 ], |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
252 "text-operators": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
253 (words(("in", "is", "and", "or", "xor", "not"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
254 prefix=r"(?<!\.)", |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
255 suffix=r"\b"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
256 Operator.Word), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
257 ], |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
258 "punctuation": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
259 (r"[{}:(),;[\]]", Punctuation), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
260 ], |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
261 "punctuation-in-braces": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
262 # 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
|
263 (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
|
264 (r"[{:(),;[\]]", Punctuation), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
265 ], |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
266 } |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
267 |
| 57 | 268 def __init__(self, **options): |
| 269 val = pygments.util.get_bool_opt(options, "no_end", default=False) | |
| 270 self.no_end = val | |
| 271 LexBase.__init__(self, **options) | |
| 272 | |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
273 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
274 class AlgPseudocodeLexer_DE(AlgPseudocodeLexer): |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
275 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
276 name = "AlgPseudocodeDE" |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
277 aliases = ["algpseudocode-de", "algpseudo-de"] |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
278 filenames = ["*.algpseudo-de", "*.algpseudocode-de"] |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
279 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
280 LANG = "de" |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
281 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
|
282 TRANSLATIONS.update({ |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
283 "PROG": "PROGRAMM", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
284 "PROGRAM": "PROGRAMM", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
285 "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
|
286 "ALGORITHM": "ALGORITHMUS", |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
287 "PROC": "PROZEDUR", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
288 "PROCEDURE": "PROZEDUR", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
289 "FUNC": "FUNKTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
290 "FUNCTION": "FUNKTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
291 "FN": "FUNKTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
292 "CLASS": "KLASSE", |
|
61
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
293 "IS": "IST", |
|
41
4ccf9a8d0bf2
For the german and french PseudocodeLexer: Use en translations as fallback.
Franz Glasner <fzglas.hg@dom66.de>
parents:
40
diff
changeset
|
294 }) |
| 57 | 295 END_TRANSLATIONS = AlgPseudocodeLexer.END_TRANSLATIONS.copy() |
| 296 END_TRANSLATIONS.update({ | |
| 297 "PROG": "ENDE DES PROGRAMMS", | |
| 298 "PROGRAM": "ENDE VON PROGRAMMS", | |
| 299 "ALGO": "ENDE DES ALGORITHMUS", | |
| 300 "ALGORITHM": "ENDE DES ALGORITHMUS", | |
| 301 "PROC": "ENDE DER PROZEDUR", | |
| 302 "PROCEDURE": "ENDE DER PROZEDUR", | |
| 303 "FUNC": "ENDE DER FUNKTION", | |
| 304 "FUNCTION": "ENDE DER FUNKTION", | |
| 305 "FN": "ENDE DER FUNKTION", | |
| 306 "CLASS": "ENDE DER KLASSE", | |
| 307 }) | |
| 308 DEFAULT_END_PREFIX = "ENDE VON " | |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
309 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
310 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
311 class AlgPseudocodeLexer_FR(AlgPseudocodeLexer): |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
312 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
313 name = "AlgPseudocodeFR" |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
314 aliases = ["algpseudocode-fr", "algpseudo-fr"] |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
315 filenames = ["*.algpseudo-fr", "*.algpseudocode-fr"] |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
316 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
317 LANG = "de" |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
318 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
|
319 TRANSLATIONS.update({ |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
320 "PROG": "PROGRAMME", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
321 "PROGRAM": "PROGRAMME", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
322 "ALGO": "ALGORITHME", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
323 "ALGORITHM": "ALGORITHME", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
324 "PROC": "PROCÉDURE", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
325 "PROCEDURE": "PROCÉDURE", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
326 "FUNC": "FONCTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
327 "FUNCTION": "FOUNCTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
328 "FN": "FONCTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
329 "CLASS": "CLASSE", |
|
61
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
330 "IS": "EST", |
|
41
4ccf9a8d0bf2
For the german and french PseudocodeLexer: Use en translations as fallback.
Franz Glasner <fzglas.hg@dom66.de>
parents:
40
diff
changeset
|
331 }) |
| 57 | 332 END_TRANSLATIONS = AlgPseudocodeLexer.END_TRANSLATIONS.copy() |
| 333 END_TRANSLATIONS.update({ | |
| 334 "PROG": "FIN DE PROGRAMME", | |
| 335 "PROGRAM": "FIN DE PROGRAMME", | |
| 336 "ALGO": "FIN D'ALGORITHME", | |
| 337 "ALGORITHM": "FIN D'ALGORITHME", | |
| 338 "PROC": "FIN DE PROCÉDURE", | |
| 339 "PROCEDURE": "FIN DE PROCÉDURE", | |
| 340 "FUNC": "FIN DE FONCTION", | |
| 341 "FUNCTION": "FIN DE FOUNCTION", | |
| 342 "FN": "FIN DE FONCTION", | |
| 343 "CLASS": "FIN DE CLASSE", | |
| 344 }) | |
| 345 DEFAULT_END_PREFIX = "FIN DE " |
