Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison pygments_lexer_pseudocode/__init__.py @ 1:4615d6df8293 origin
ADD: The original pygments-lexer-pseudocode project from GitHub.
The commit is c455f4e283788932cf010b189e4b915871f3cff2.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 19 Apr 2026 16:44:06 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 1:4615d6df8293 |
|---|---|
| 1 import re | |
| 2 | |
| 3 from pygments.lexer import RegexLexer, include, bygroups, using, this | |
| 4 from pygments.token import Error, Punctuation, Text, Comment, Operator, Keyword, Name, String, Number | |
| 5 | |
| 6 | |
| 7 class PseudocodeLexer(RegexLexer): | |
| 8 ''' | |
| 9 A Pseudo code (fr) lexer | |
| 10 ''' | |
| 11 name = 'Pseudocode' | |
| 12 aliases = ['pseudocode', 'pseudo', 'algorithm', 'algo'] | |
| 13 filenames = ['*.algo', '*.pseudocode'] | |
| 14 mimetypes = [] | |
| 15 flags = re.IGNORECASE | |
| 16 | |
| 17 def op_replace(lexer, match): | |
| 18 op = match.group(0) | |
| 19 | |
| 20 S = ('<=', '>=', '<>', '<-', '^') | |
| 21 R = ('≤', '≥', '≠', '←', '↑') | |
| 22 | |
| 23 if op in S: | |
| 24 op = R[S.index(op)] | |
| 25 | |
| 26 yield match.start(), Operator, op | |
| 27 | |
| 28 def scomment(lexer, match): | |
| 29 s = match.group(1).lower().strip() | |
| 30 c = Comment | |
| 31 | |
| 32 directives = ['passage par copie', 'passage par valeur', 'passage par référence', 'passage par reference', 'passage par adresse', 've', 'vs', 've/s'] | |
| 33 | |
| 34 if s in directives: | |
| 35 c = Comment.Special | |
| 36 | |
| 37 yield match.start(), c, match.group(0) | |
| 38 | |
| 39 tokens = { | |
| 40 'root': [ | |
| 41 (r'\/\*.*\*\/', Comment), | |
| 42 (r'(\/\/|#).*\n', Comment), | |
| 43 (r'\|', Comment), | |
| 44 (r'\{(.*)\}', scomment), | |
| 45 include('strings'), | |
| 46 include('core'), | |
| 47 (r'[a-zéàùçèÉÀÙÇÈ][a-z0-9éàùçèÉÀÙÇÈ_]*', Name.Variable), | |
| 48 include('nums'), | |
| 49 (r'[\s]+', Text) | |
| 50 ], | |
| 51 'core':[ # Statements | |
| 52 (r'\b(debut|début|fin|si|alors|sinon|fin[_ ]si|tant[ _]que|tantque|fin[ _]tantque|faire|répéter' | |
| 53 r'repeter|type|structure|fin[ _]structure|fonction|procédure|procedure|retourner|renvoyer|' | |
| 54 r'pour|fin[ _]pour|à|déclarations?|juqsque|spécialise|specialise|comporte|super|public|privé|protégé|' | |
| 55 r'classe' | |
| 56 r')\s*\b', Keyword), | |
| 57 | |
| 58 # Data Types | |
| 59 (r'\b(entiers?|chaines?|chaînes?|réels?|reels?|caractères?|caracteres?|booléens?|' | |
| 60 r'booleens?|tableaux?|rien)\s*\b', | |
| 61 Keyword.Type), | |
| 62 | |
| 63 (r'\b(vrai|faux|nil)\s*\b', | |
| 64 Name.Constant), | |
| 65 | |
| 66 # Operators | |
| 67 (r'(<=|>=|<>|<-|\^|\*|\+|-|\/|<|>|=|\\\\|mod|←|↑|≤|≥|≠|÷|×|\.\.|\[|\]|\.|non|xou|et|ou)', | |
| 68 op_replace), | |
| 69 | |
| 70 (r'(\(|\)|\,|\;|:)', | |
| 71 Punctuation), | |
| 72 | |
| 73 #(r'\b(\[(VE|VS|VE/S)\])\s*\b', | |
| 74 # Keyword.Declaration), | |
| 75 | |
| 76 # Intrinsics | |
| 77 (r'\b(sqrt|pow|cos|sin|tan|arccos|arcsin|arctan|arctan2|lire|ecrire|écrire|' | |
| 78 r'exp|ln|log|détruire|detruire' | |
| 79 r')\s*\b', Name.Builtin) | |
| 80 ], | |
| 81 | |
| 82 'strings': [ | |
| 83 (r'"([^"])*"', String.Double), | |
| 84 (r"'([^'])*'", String.Single), | |
| 85 ], | |
| 86 | |
| 87 'nums': [ | |
| 88 (r'\d+(?![.Ee])', Number.Integer), | |
| 89 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float), | |
| 90 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float) | |
| 91 ], | |
| 92 } | |
| 93 |
