Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison docs/details-algpseudocode.rst @ 150:4acf578ae93f
Much more details in the documentation
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 07 May 2026 16:06:59 +0200 |
| parents | b4688f6cc7b1 |
| children | d475f5e252eb |
comparison
equal
deleted
inserted
replaced
| 149:380d2607d5c7 | 150:4acf578ae93f |
|---|---|
| 41 | 41 |
| 42 | 42 |
| 43 Comments | 43 Comments |
| 44 ======== | 44 ======== |
| 45 | 45 |
| 46 - with the ``\REMARK`` or ``\REM`` keywords | 46 - with the ``\REMARK`` or ``\REM`` keywords (this includes a leading symbol) |
| 47 - multi-line comments with ``/* ... */``; they can be **nested** | 47 - multi-line comments with ``/* ... */``; they can be **nested** |
| 48 - multi-line comments with ``(* ... *)``; they can be **nested** | 48 - multi-line comments with ``(* ... *)``; they can be **nested** |
| 49 - single-line comments with ``//`` or ``#`` (until the end of the line) | 49 - single-line comments with ``//`` or ``#`` (until the end of the line) |
| 50 | 50 |
| 51 .. code-block:: algpseudocode | |
| 52 | |
| 53 /* | |
| 54 * A single multiline comment | |
| 55 */ | |
| 56 | |
| 57 /* | |
| 58 * A multiline comment | |
| 59 * | |
| 60 * /* This is a nested multi-line comment */ | |
| 61 * | |
| 62 */ | |
| 63 | |
| 64 (* | |
| 65 * A multiline comment | |
| 66 * | |
| 67 * (* This is a nested multi-line comment *) | |
| 68 * | |
| 69 *) | |
| 70 | |
| 71 // A single-line comment | |
| 72 | |
| 73 # A single-line comment | |
| 74 | |
| 75 \REM A remark has a leading symbol | |
| 76 | |
| 51 | 77 |
| 52 Literals | 78 Literals |
| 53 ======== | 79 ======== |
| 54 | 80 |
| 55 Strings and numbers as in `Python`_. | 81 Strings and numbers as in `Python`_. String prefixes ``r``, ``f`` and ``t`` |
| 82 are not supported -- ``u`` and ``b`` are. | |
| 56 | 83 |
| 57 To yield non-string-delimiting single- and double-quotes you have to escape them | 84 To yield non-string-delimiting single- and double-quotes you have to escape them |
| 58 using ``\'`` or ``\"``. This must be used to typeset something as | 85 using ``\'`` or ``\"``. This must be used to typeset something as |
| 59 :algpseudocode:`f\\'(x) = 0`. | 86 :algpseudocode:`f\\'(x) = 0`. |
| 87 | |
| 88 .. code-block:: algpseudocode | |
| 89 | |
| 90 0 0xdead 0b100001 0o720 2.7 2.7e-54 | |
| 91 | |
| 92 "A string with an escaped double-quote \" " | |
| 93 | |
| 94 'Another string with an escaped single-quote \' ' | |
| 95 | |
| 96 """A multiline | |
| 97 string | |
| 98 """ | |
| 99 | |
| 100 '''Another multiline string | |
| 101 | |
| 102 ''' | |
| 103 | |
| 104 b"A \x20 byte string" | |
| 105 | |
| 106 u'An explicit Unicode \u1234 string' | |
| 107 | |
| 108 \" a non string | |
| 109 | |
| 110 \' a non string also | |
| 111 | |
| 112 | |
| 113 (Mathematical) Symbols and Operators | |
| 114 ==================================== | |
| 115 | |
| 116 Some ASCII symbol combinations are recognized and replaced by a | |
| 117 Unicode symbol: | |
| 118 | |
| 119 .. code-block:: algpseudocode | |
| 120 | |
| 121 \TEXT{<=>} <=> | |
| 122 \TEXT{<->} <-> | |
| 123 \TEXT{<-} <- | |
| 124 \TEXT{->} -> | |
| 125 \TEXT{=>} => | |
| 126 \TEXT{<=} <= | |
| 127 \TEXT{>=} >= | |
| 128 \TEXT{<>} <> | |
| 129 \TEXT{!=} != | |
| 130 \TEXT{:=} := | |
| 131 \TEXT{=:} =: | |
| 132 \TEXT{?=} ?= | |
| 133 | |
| 134 Unicode codepoints with property ``Sm`` are recognized as mathematical symbol | |
| 135 and highlighted accordingly. | |
| 60 | 136 |
| 61 | 137 |
| 62 Keywords | 138 Keywords |
| 63 ======== | 139 ======== |
| 64 | 140 |
| 106 \TEXT{\REQUIRE{Whatever should be required.\}} \REQUIRE{Whatever should be required.} | 182 \TEXT{\REQUIRE{Whatever should be required.\}} \REQUIRE{Whatever should be required.} |
| 107 | 183 |
| 108 \TEXT{\RETURNS{Return 2\}} \RETURNS{Return 2} | 184 \TEXT{\RETURNS{Return 2\}} \RETURNS{Return 2} |
| 109 | 185 |
| 110 \TEXT{\CALL{a function\}(p1, p2)} \CALL{a function}(p1, p2) | 186 \TEXT{\CALL{a function\}(p1, p2)} \CALL{a function}(p1, p2) |
| 187 | |
| 188 \TEXT{\NAME{an entity name\}} \NAME{an entity name} | |
| 111 | 189 |
| 112 | 190 |
| 113 With Optional Parameters | 191 With Optional Parameters |
| 114 ~~~~~~~~~~~~~~~~~~~~~~~~ | 192 ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 115 | 193 |
| 162 \TEXT{\END} \END | 240 \TEXT{\END} \END |
| 163 | 241 |
| 164 \TEXT{\IS} \IS | 242 \TEXT{\IS} \IS |
| 165 \TEXT{\WITH} \WITH | 243 \TEXT{\WITH} \WITH |
| 166 | 244 |
| 167 \TEXT{\\REMARK or \\REM} \REMARK A comment with a sigil | 245 \TEXT{\GETS} \GETS |
| 246 | |
| 247 \TEXT{\\REMARK or \\REM} \REMARK A comment with a leading symbol | |
| 168 | 248 |
| 169 ``\REMARK`` or ``\REM`` is special: all characters to the end of the | 249 ``\REMARK`` or ``\REM`` is special: all characters to the end of the |
| 170 line are taken as comment; curly braces are not needed -- in fact: | 250 line are taken as comment; curly braces are not needed---in fact: |
| 171 they are interpreted as part of the comment. | 251 they are interpreted to be part of the comment. |
| 172 | 252 |
| 173 | 253 |
| 174 END-Keywords | 254 END-Keywords |
| 175 '''''''''''' | 255 '''''''''''' |
| 176 | 256 |
| 208 \text{\END-FOR} \END-FOR | 288 \text{\END-FOR} \END-FOR |
| 209 \text{\END-FORALL} \END-FORALL | 289 \text{\END-FORALL} \END-FORALL |
| 210 \text{\END-LOOP} \END-LOOP | 290 \text{\END-LOOP} \END-LOOP |
| 211 | 291 |
| 212 | 292 |
| 293 Names and Entities | |
| 294 ================== | |
| 295 | |
| 296 In an expression context all other words are interpreted as entity | |
| 297 names (token type ``Token.Name.Entity``). | |
| 298 | |
| 299 Allowed characters in the words follow the corresponding `Python`_ rules. | |
| 300 As such, many Unicode characters are allowed. | |
| 301 | |
| 302 To highlight entity names with whitespace or other "special" characters in it | |
| 303 use the ``NAME`` command. | |
| 304 | |
| 305 .. code-block:: algpseudocode | |
| 306 | |
| 307 \TEXT{entity_name_1} entity_name_1 | |
| 308 | |
| 309 \TEXT{entity_name_2} entity_name_2 | |
| 310 | |
| 311 \TEXT{\NAME{entity-name 3\}} \NAME{entity-name 3} | |
| 312 | |
| 313 \TEXT{München} München | |
| 314 | |
| 315 \TEXT{Genève} Genève | |
| 316 | |
| 317 .. _explicit-token-types: | |
| 318 | |
| 213 Explicit Token Types | 319 Explicit Token Types |
| 214 ==================== | 320 ==================== |
| 215 | 321 |
| 216 Handle keywords and operators that are not handled by default or change | 322 Handle keywords and operators that are not handled by default or change |
| 217 the default handling of some expressions. | 323 the default handling of some expressions. |
| 252 \text{• \\ttx-nv{A New Variable Name\}} \ttx-nv{A New Variable Name} \rem An explicit Name.Variable | 358 \text{• \\ttx-nv{A New Variable Name\}} \ttx-nv{A New Variable Name} \rem An explicit Name.Variable |
| 253 \text{• \\ttx-k(∈ ∌)} \ttx-k(∈ ∌) \rem ∈ and ∌ as (ordinary) Keywords | 359 \text{• \\ttx-k(∈ ∌)} \ttx-k(∈ ∌) \rem ∈ and ∌ as (ordinary) Keywords |
| 254 \text{• \\ttx-o<∈ ∌>} \ttx-o<∈ ∌> \rem ∈ and ∌ as (ordinary) Operators | 360 \text{• \\ttx-o<∈ ∌>} \ttx-o<∈ ∌> \rem ∈ and ∌ as (ordinary) Operators |
| 255 /* | 361 /* |
| 256 * The line below has ∈_∌ as (peculiar) function name. | 362 * The line below has ∈_∌ as (peculiar) function name. |
| 257 * Their params are automatic. | 363 * Their params are automatic (i.e. a normal expression). |
| 258 */ | 364 */ |
| 259 \text{• \\ttx-nf<∈_∌>(p1, p2)} \ttx-nf<∈_∌>(p1, p2) | 365 \text{• \\ttx-nf<∈_∌>(p1, p2)} \ttx-nf<∈_∌>(p1, p2) |
| 260 /* | 366 /* |
| 261 * The line below has ∈_∌ as (peculiar) decorator name (as used in Python). | 367 * The line below has ∈_∌ as (peculiar) decorator name (as used in Python). |
| 262 * Their params are automatic. | 368 * Their params are automatic (i.e. a normal expression). |
| 263 */ | 369 */ |
| 264 \text{• \\ttx-nd[∈_∌](p1, p2)} \ttx-nd[∈_∌](p1, p2) | 370 \text{• \\ttx-nd[∈_∌](p1, p2)} \ttx-nd[∈_∌](p1, p2) |
| 265 /* | 371 /* |
| 266 * This is a non-existing token type: you get some generic error marking | 372 * This is a non-existing token type: you get some generic error marking |
| 267 * with a Generic.Error token and no expansion. | 373 * with a Generic.Error token and no expansion. |
