changeset 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 e310a29a391b
files .gitignore README.md pygments_lexer_pseudocode/__init__.py setup.cfg setup.py
diffstat 5 files changed, 150 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Sun Apr 19 16:44:06 2026 +0200
@@ -0,0 +1,3 @@
+/build
+/dist
+/*.egg-info
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Sun Apr 19 16:44:06 2026 +0200
@@ -0,0 +1,31 @@
+# (French) Pseudocode syntax lexer for Pygments
+
+This package contains a Pygments Lexer for some basic pseudocode algorithmics.
+
+## Installation
+
+The lexer is available as a Pip package:
+
+    pip install pygments-lexer-pseudocode
+
+Alternatively, to install from the git repository: (you may need to sudo depending on your Python environment)
+
+    python setup.py install
+
+## Usage
+
+After installation the Pseudocode lexer automatically registers itself for files with the `.algo` and `.pseudocode` extensions. Therefore, usage is easy:
+
+    pygmentize document.algo
+
+You can also manally indicate you want to use the Pseudocode lexer by using a command line flag:
+
+    pygmentize -l pseudocode somefile 
+
+## Contribute
+
+If you found a bug, don't hesitate to make a pull request.
+
+## License
+
+The Pseudocode lexer is licensed under the terms of the MIT licence
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pygments_lexer_pseudocode/__init__.py	Sun Apr 19 16:44:06 2026 +0200
@@ -0,0 +1,93 @@
+import re
+
+from pygments.lexer import RegexLexer, include, bygroups, using, this
+from pygments.token import Error, Punctuation, Text, Comment, Operator, Keyword, Name, String, Number
+
+
+class PseudocodeLexer(RegexLexer):
+    '''
+    A Pseudo code (fr) lexer
+    '''
+    name = 'Pseudocode'
+    aliases = ['pseudocode', 'pseudo', 'algorithm', 'algo']
+    filenames = ['*.algo', '*.pseudocode']
+    mimetypes = []
+    flags = re.IGNORECASE
+
+    def op_replace(lexer, match):
+        op = match.group(0)
+        
+        S = ('<=', '>=', '<>', '<-', '^')
+        R = ('≤',  '≥',  '≠',  '←',  '↑')
+
+        if op in S:
+            op = R[S.index(op)]
+
+        yield match.start(), Operator, op
+
+    def scomment(lexer, match):
+        s = match.group(1).lower().strip()
+        c = Comment
+
+        directives = ['passage par copie', 'passage par valeur', 'passage par référence', 'passage par reference', 'passage par adresse', 've', 'vs', 've/s']
+
+        if s in directives:
+            c = Comment.Special
+        
+        yield match.start(), c, match.group(0)
+     
+    tokens = {
+        'root': [
+                 (r'\/\*.*\*\/', Comment),
+                 (r'(\/\/|#).*\n', Comment),
+                 (r'\|', Comment),
+                 (r'\{(.*)\}', scomment),
+                 include('strings'),
+                 include('core'),
+                 (r'[a-zéàùçèÉÀÙÇÈ][a-z0-9éàùçèÉÀÙÇÈ_]*', Name.Variable),
+                 include('nums'),
+                 (r'[\s]+', Text)
+        ],
+        'core':[ # Statements
+                 (r'\b(debut|début|fin|si|alors|sinon|fin[_ ]si|tant[ _]que|tantque|fin[ _]tantque|faire|répéter'
+                  r'repeter|type|structure|fin[ _]structure|fonction|procédure|procedure|retourner|renvoyer|'
+                  r'pour|fin[ _]pour|à|déclarations?|juqsque|spécialise|specialise|comporte|super|public|privé|protégé|'
+                  r'classe'
+                  r')\s*\b', Keyword),
+
+                 # Data Types
+                 (r'\b(entiers?|chaines?|chaînes?|réels?|reels?|caractères?|caracteres?|booléens?|'
+                  r'booleens?|tableaux?|rien)\s*\b', 
+                  Keyword.Type),
+
+                  (r'\b(vrai|faux|nil)\s*\b',
+                   Name.Constant),
+                  
+                 # Operators
+                 (r'(<=|>=|<>|<-|\^|\*|\+|-|\/|<|>|=|\\\\|mod|←|↑|≤|≥|≠|÷|×|\.\.|\[|\]|\.|non|xou|et|ou)',
+                  op_replace),
+                  
+                 (r'(\(|\)|\,|\;|:)',
+                  Punctuation),
+                  
+                 #(r'\b(\[(VE|VS|VE/S)\])\s*\b',
+                 # Keyword.Declaration),
+
+                  # Intrinsics
+                 (r'\b(sqrt|pow|cos|sin|tan|arccos|arcsin|arctan|arctan2|lire|ecrire|écrire|'
+                  r'exp|ln|log|détruire|detruire'
+                  r')\s*\b', Name.Builtin)
+                ],
+
+        'strings': [
+                 (r'"([^"])*"', String.Double),
+                 (r"'([^'])*'", String.Single),
+                ],
+
+        'nums': [
+                 (r'\d+(?![.Ee])', Number.Integer),
+                 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float),
+                 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float)
+                ],
+        }
+        
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.cfg	Sun Apr 19 16:44:06 2026 +0200
@@ -0,0 +1,2 @@
+[metadata]
+description-file = README.md
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py	Sun Apr 19 16:44:06 2026 +0200
@@ -0,0 +1,21 @@
+from setuptools import setup
+
+setup(
+    name="pygments-lexer-pseudocode",
+    packages=["pygments_lexer_pseudocode"],
+    version="2.0.1",
+    description="Pygments Lexer for a french pseudocode",
+    author="Simon Wachter",
+    author_email="simon@wachter.me",
+    url="https://github.com/svvac/pseudocode-pygments-lexer",
+    license="MIT",
+    entry_points="[pygments.lexers]\npseudocodelexer = pygments_lexer_pseudocode:PseudocodeLexer",
+    install_requires=[ "pygments" ],
+    classifiers=[
+        "Development Status :: 4 - Beta",
+        "License :: OSI Approved :: MIT License",
+        "Natural Language :: French",
+        "Topic :: Text Processing",
+        "Topic :: Utilities",
+    ]
+)