Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
annotate pygments_lexer_pseudocode2/algpseudocode.py @ 82:36a0ef76a6d7
Implement "\WITH"
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 30 Apr 2026 12:29:08 +0200 |
| parents | 6d8b813fb296 |
| children | cd79d2c76347 |
| 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", |
| 82 | 58 "WITH": "WITH", |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
59 } |
| 57 | 60 END_TRANSLATIONS = { |
| 61 "PROG": "END OF PROGRAM", | |
| 62 "PROGRAM": "END OF PROGRAM", | |
| 63 "ALGO": "END OF ALGORITHM", | |
| 64 "ALGORITHM": "END OF ALGORITHM", | |
| 65 "PROC": "END OF PROCEDURE", | |
| 66 "PROCEDURE": "END OF PROCEDURE", | |
| 67 "FUNC": "END OF FUNCTION", | |
| 68 "FUNCTION": "END OF FUNCTION", | |
| 69 "FN": "END OF FUNCTION", | |
| 70 "CLASS": "END OF CLASS", | |
| 71 } | |
| 72 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
|
73 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
|
74 # 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
|
75 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
|
76 # 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
|
77 # 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
|
78 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
|
79 # 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
|
80 SYMBOLS = { |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
81 # 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
|
82 "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
|
83 "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
|
84 # Group STATEMENT |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
85 "STATEMENT": SYMBOL_BLOCK, |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
86 "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
|
87 "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
|
88 # 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
|
89 "TEXTSTATEMENT": SYMBOL_TEXTSTATEMENT, |
|
78
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
90 "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
|
91 "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
|
92 "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
|
93 "TEXTBLOCK": SYMBOL_TEXTSTATEMENT, |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
94 "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
|
95 } |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
96 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
97 def op_translate(toktype): |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
98 |
|
40
df08226a6984
Names for some entities (program, algorithm, function, procedure, class).
Franz Glasner <fzglas.hg@dom66.de>
parents:
39
diff
changeset
|
99 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
|
100 kw = match.group().upper() |
|
38
69522d4cafac
Remove another unneeded local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
35
diff
changeset
|
101 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
|
102 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
103 return _op_translate |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
104 |
| 57 | 105 def op_opt_end_translate(toktype): |
| 106 | |
| 107 def _op_end_translate(lexer, match, ctx=None): | |
| 108 if not lexer.no_end: | |
| 109 kw = match.group().upper() | |
| 110 yield (match.start(), | |
| 111 toktype, | |
| 112 lexer.END_TRANSLATIONS.get( | |
| 113 kw, | |
| 114 lexer.DEFAULT_END_PREFIX + kw)) | |
| 115 | |
| 116 return _op_end_translate | |
| 117 | |
|
62
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(toktype): |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
119 |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
124 return _op_opt_ignore |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
125 |
|
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
|
126 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
|
127 """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
|
128 `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
|
129 |
|
3f4223a79d2b
Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents:
64
diff
changeset
|
130 """ |
|
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
|
131 |
|
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 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
|
133 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
|
134 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
|
135 |
|
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
|
136 return _op_opt_ignore_or_fixed |
|
65
3f4223a79d2b
Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents:
64
diff
changeset
|
137 |
|
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
|
138 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
|
139 |
|
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 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
|
141 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
|
142 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
|
143 |
|
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
|
144 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
|
145 |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
146 tokens = { |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
147 "root": [ |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
148 (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
|
149 (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
|
150 (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
|
151 include("remark"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
152 (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
|
153 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
|
154 "block-expr"), |
|
78
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
155 (r"(?i)\\(" |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
156 r"(?:textstate(?:ment)?)" |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
157 r"|(?:tstate(?:ment)?)" |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
158 r"|(?:textblock)" |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
159 r"|(?:tblock)" |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
160 r")\s*(\{)", |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
161 bygroups(op_symbol(Text), LexBase.op_fixed(Whitespace, " ")), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
162 "text-statement"), |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
163 (r"\\\n", Text), |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
164 (r"(?i)\\(" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
165 r"(?:prog(?:ram)?)" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
166 r"|(?:algo(?:rithm)?)" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
167 r"|(?:proc(?:edure)?)" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
168 r"|(?:func(?:tion)?|(?:fn))" |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
169 r"|(?:class)" |
|
65
3f4223a79d2b
Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents:
64
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 "entity-name"), |
| 57 | 174 # ENDxxx keywords with optional entity name |
| 175 # with name | |
| 176 (r"(?i)\\end(?:_|-)?(" | |
| 177 r"(?:prog(?:ram)?)" | |
| 178 r"|(?:algo(?:rithm)?)" | |
| 179 r"|(?:proc(?:edure)?)" | |
| 180 r"|(?:func(?:tion)?)" | |
| 181 r"|(?:class)" | |
|
65
3f4223a79d2b
Normalize whitespace handling for entity names
Franz Glasner <fzglas.hg@dom66.de>
parents:
64
diff
changeset
|
182 r")\s*(\{)", |
|
62
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
183 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
|
184 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
|
185 "entity-name-end"), |
| 57 | 186 # without name |
| 187 (r"(?i)\\end(?:_|-)?(" | |
| 188 r"(?:prog(?:ram)?)" | |
| 189 r"|(?:algo(?:rithm)?)" | |
| 190 r"|(?:proc(?:edure)?)" | |
| 191 r"|(?:func(?:tion)?)" | |
| 192 r"|(?:class)" | |
|
62
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
193 r")\b", |
| 57 | 194 bygroups(op_opt_end_translate(Keyword))), |
|
61
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
195 # Keywords |
|
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
196 (r"(?i)\\(" |
|
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
197 r"(?:is)" |
| 82 | 198 r"|(?:with)" |
|
61
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
199 r")\b", |
|
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
200 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
|
201 include("expr"), |
|
52
5bfa9113d3c4
First tests with "py-name": names from the Python lexer
Franz Glasner <fzglas.hg@dom66.de>
parents:
41
diff
changeset
|
202 (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
|
203 ], |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
204 "remark": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
205 (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
|
206 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
|
207 ], |
|
62
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
208 "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
|
209 (r"[^\\}]+", Name.Entity), |
|
77
1a5e192aa950
Move popping states consistently more to the begin
Franz Glasner <fzglas.hg@dom66.de>
parents:
76
diff
changeset
|
210 (r"\}", LexBase.op_ignore, "#pop"), |
|
74
c1357674622d
Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents:
72
diff
changeset
|
211 (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
|
212 (r"\\\\", LexBase.op_fixed(Name.Entity, "\\")), |
|
74
c1357674622d
Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents:
72
diff
changeset
|
213 (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
|
214 ], |
|
7153e945a3d6
Implement ignoring of \ENDxxx including its optional name parts
Franz Glasner <fzglas.hg@dom66.de>
parents:
61
diff
changeset
|
215 "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
|
216 (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
|
217 (r"\}", LexBase.op_ignore, "#pop"), |
|
74
c1357674622d
Remove an escaping backslash where appropriate
Franz Glasner <fzglas.hg@dom66.de>
parents:
72
diff
changeset
|
218 (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
|
219 (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
|
220 (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
|
221 ], |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
222 "expr": [ |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
223 include("punctuation"), |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
224 include("py-strings"), |
|
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
225 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
|
226 (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
|
227 include("remark"), |
|
81
6d8b813fb296
Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
228 include("keyword-constants"), |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
229 include("text-operators"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
230 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
|
231 include("py-name"), |
|
70
5517b0be67f0
Basic "\TEXT" escape for expressions
Franz Glasner <fzglas.hg@dom66.de>
parents:
65
diff
changeset
|
232 ], |
|
80
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
233 "expr-in-braces": [ |
|
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
234 include("punctuation-in-braces"), |
|
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
235 include("py-strings"), |
|
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
236 include("py-numbers"), |
|
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
237 (r"(?i)\\text\s*\{", LexBase.op_ignore, "text-in-expr"), |
|
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
238 include("remark"), |
|
81
6d8b813fb296
Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
239 include("keyword-constants"), |
|
80
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
240 include("text-operators"), |
|
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
241 include("math-builtins"), |
|
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
242 include("py-name"), |
|
f487f0d322a5
Move "expr-in-braces" up to "expr".
Franz Glasner <fzglas.hg@dom66.de>
parents:
78
diff
changeset
|
243 ], |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
244 "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
|
245 (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
|
246 (r"\n", Whitespace), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
247 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
|
248 (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
|
249 (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
|
250 (r"\s+", Text), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
251 ], |
|
78
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
252 "text-statement": [ # like block but default to text-mode |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
253 (r"[^\\}\n]+", Text), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
254 (r"\}", LexBase.op_ignore, "#pop"), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
255 (r"\n", Whitespace), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
256 (r"\\\}", LexBase.op_fixed(Text, "}")), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
257 (r"(?i)\\expr(?:ession)?\s*\{", |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
258 LexBase.op_ignore, |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
259 "block-expr"), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
260 include("remark"), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
261 (r"\\\\", LexBase.op_fixed(Text, "\\")), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
262 (r"\\", LexBase.op_fixed(Text, "\\")), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
263 ], |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
264 "text-in-expr": [ |
|
77
1a5e192aa950
Move popping states consistently more to the begin
Franz Glasner <fzglas.hg@dom66.de>
parents:
76
diff
changeset
|
265 (r"[^\\}\n]+", Text), |
|
1a5e192aa950
Move popping states consistently more to the begin
Franz Glasner <fzglas.hg@dom66.de>
parents:
76
diff
changeset
|
266 (r"\}", LexBase.op_ignore, "#pop"), |
|
1a5e192aa950
Move popping states consistently more to the begin
Franz Glasner <fzglas.hg@dom66.de>
parents:
76
diff
changeset
|
267 (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
|
268 (r"\\\}", LexBase.op_fixed(Text, "}")), |
|
78
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
269 (r"(?:i)\\(expr(?:ession)?)\s*(\{)", |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
270 bygroups(LexBase.op_ignore, LexBase.op_ignore), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
271 "expr-in-braces"), |
|
abb2e8c65d0f
Implement "TEXTSTATEMENT"
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
272 (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
|
273 (r"\\", LexBase.op_fixed(Text, "\\")), |
|
70
5517b0be67f0
Basic "\TEXT" escape for expressions
Franz Glasner <fzglas.hg@dom66.de>
parents:
65
diff
changeset
|
274 ], |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
275 "math-builtins": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
276 (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
|
277 "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
|
278 prefix=r"(?<!\.)", |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
279 suffix=r"\b"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
280 Name.Builtin), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
281 ], |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
282 "text-operators": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
283 (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
|
284 prefix=r"(?<!\.)", |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
285 suffix=r"\b"), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
286 Operator.Word), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
287 ], |
|
81
6d8b813fb296
Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
288 "keyword-constants": [ |
|
6d8b813fb296
Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
289 (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
|
290 "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
|
291 "Null", "NULL", "null", |
|
6d8b813fb296
Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
292 "Empty", "EMPTY", "empty"), |
|
6d8b813fb296
Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
293 prefix=r"(?<!\.)", |
|
6d8b813fb296
Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
294 suffix=r"\b"), |
|
6d8b813fb296
Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
295 Keyword.Constant), |
|
6d8b813fb296
Keyword constants like "True", "False", "Nil", "None", "Null" and "Empty"
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
296 ], |
|
75
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
297 "punctuation": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
298 (r"[{}:(),;[\]]", Punctuation), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
299 ], |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
300 "punctuation-in-braces": [ |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
301 # 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
|
302 (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
|
303 (r"[{:(),;[\]]", Punctuation), |
|
711f8d19e27a
New implementation of "STATEMENT" (also aliased to "STATE" and "BLOCK").
Franz Glasner <fzglas.hg@dom66.de>
parents:
74
diff
changeset
|
304 ], |
|
34
1f741934205e
Begin a new Pseudocode lexer using numbers and strings from Python
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
305 } |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
306 |
| 57 | 307 def __init__(self, **options): |
| 308 val = pygments.util.get_bool_opt(options, "no_end", default=False) | |
| 309 self.no_end = val | |
| 310 LexBase.__init__(self, **options) | |
| 311 | |
|
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 class AlgPseudocodeLexer_DE(AlgPseudocodeLexer): |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
314 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
315 name = "AlgPseudocodeDE" |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
316 aliases = ["algpseudocode-de", "algpseudo-de"] |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
317 filenames = ["*.algpseudo-de", "*.algpseudocode-de"] |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
318 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
319 LANG = "de" |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
320 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
|
321 TRANSLATIONS.update({ |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
322 "PROG": "PROGRAMM", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
323 "PROGRAM": "PROGRAMM", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
324 "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
|
325 "ALGORITHM": "ALGORITHMUS", |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
326 "PROC": "PROZEDUR", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
327 "PROCEDURE": "PROZEDUR", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
328 "FUNC": "FUNKTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
329 "FUNCTION": "FUNKTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
330 "FN": "FUNKTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
331 "CLASS": "KLASSE", |
|
61
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
332 "IS": "IST", |
| 82 | 333 "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
|
334 }) |
| 57 | 335 END_TRANSLATIONS = AlgPseudocodeLexer.END_TRANSLATIONS.copy() |
| 336 END_TRANSLATIONS.update({ | |
| 337 "PROG": "ENDE DES PROGRAMMS", | |
| 338 "PROGRAM": "ENDE VON PROGRAMMS", | |
| 339 "ALGO": "ENDE DES ALGORITHMUS", | |
| 340 "ALGORITHM": "ENDE DES ALGORITHMUS", | |
| 341 "PROC": "ENDE DER PROZEDUR", | |
| 342 "PROCEDURE": "ENDE DER PROZEDUR", | |
| 343 "FUNC": "ENDE DER FUNKTION", | |
| 344 "FUNCTION": "ENDE DER FUNKTION", | |
| 345 "FN": "ENDE DER FUNKTION", | |
| 346 "CLASS": "ENDE DER KLASSE", | |
| 347 }) | |
| 348 DEFAULT_END_PREFIX = "ENDE VON " | |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
349 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
350 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
351 class AlgPseudocodeLexer_FR(AlgPseudocodeLexer): |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
352 |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
353 name = "AlgPseudocodeFR" |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
354 aliases = ["algpseudocode-fr", "algpseudo-fr"] |
|
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
355 filenames = ["*.algpseudo-fr", "*.algpseudocode-fr"] |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
356 |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
357 LANG = "de" |
|
53
39151225fb84
Rename the new pseudocode implementation to AlgPseudocode.
Franz Glasner <fzglas.hg@dom66.de>
parents:
52
diff
changeset
|
358 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
|
359 TRANSLATIONS.update({ |
|
35
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
360 "PROG": "PROGRAMME", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
361 "PROGRAM": "PROGRAMME", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
362 "ALGO": "ALGORITHME", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
363 "ALGORITHM": "ALGORITHME", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
364 "PROC": "PROCÉDURE", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
365 "PROCEDURE": "PROCÉDURE", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
366 "FUNC": "FONCTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
367 "FUNCTION": "FOUNCTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
368 "FN": "FONCTION", |
|
d9a3551a1038
Basics of translating some keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
34
diff
changeset
|
369 "CLASS": "CLASSE", |
|
61
392745b66969
The "\IS" keyword expansion
Franz Glasner <fzglas.hg@dom66.de>
parents:
58
diff
changeset
|
370 "IS": "EST", |
| 82 | 371 "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
|
372 }) |
| 57 | 373 END_TRANSLATIONS = AlgPseudocodeLexer.END_TRANSLATIONS.copy() |
| 374 END_TRANSLATIONS.update({ | |
| 375 "PROG": "FIN DE PROGRAMME", | |
| 376 "PROGRAM": "FIN DE PROGRAMME", | |
| 377 "ALGO": "FIN D'ALGORITHME", | |
| 378 "ALGORITHM": "FIN D'ALGORITHME", | |
| 379 "PROC": "FIN DE PROCÉDURE", | |
| 380 "PROCEDURE": "FIN DE PROCÉDURE", | |
| 381 "FUNC": "FIN DE FONCTION", | |
| 382 "FUNCTION": "FIN DE FOUNCTION", | |
| 383 "FN": "FIN DE FONCTION", | |
| 384 "CLASS": "FIN DE CLASSE", | |
| 385 }) | |
| 386 DEFAULT_END_PREFIX = "FIN DE " |
