Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
oberon.py121 linesDownload Raw Back to lexers
1"""2    pygments.lexers.oberon3    ~~~~~~~~~~~~~~~~~~~~~~4 5    Lexers for Oberon family languages.6 7    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10 11import re12 13from pygments.lexer import RegexLexer, include, words14from pygments.token import Text, Comment, Operator, Keyword, Name, String, \15    Number, Punctuation16 17__all__ = ['ComponentPascalLexer']18 19 20class ComponentPascalLexer(RegexLexer):21    """22    For Component Pascal source code.23    """24    name = 'Component Pascal'25    aliases = ['componentpascal', 'cp']26    filenames = ['*.cp', '*.cps']27    mimetypes = ['text/x-component-pascal']28    url = 'https://blackboxframework.org'29    version_added = '2.1'30 31    flags = re.MULTILINE | re.DOTALL32 33    tokens = {34        'root': [35            include('whitespace'),36            include('comments'),37            include('punctuation'),38            include('numliterals'),39            include('strings'),40            include('operators'),41            include('builtins'),42            include('identifiers'),43        ],44        'whitespace': [45            (r'\n+', Text),  # blank lines46            (r'\s+', Text),  # whitespace47        ],48        'comments': [49            (r'\(\*([^$].*?)\*\)', Comment.Multiline),50            # TODO: nested comments (* (* ... *) ... (* ... *) *) not supported!51        ],52        'punctuation': [53            (r'[()\[\]{},.:;|]', Punctuation),54        ],55        'numliterals': [56            (r'[0-9A-F]+X\b', Number.Hex),                 # char code57            (r'[0-9A-F]+[HL]\b', Number.Hex),              # hexadecimal number58            (r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float),  # real number59            (r'[0-9]+\.[0-9]+', Number.Float),             # real number60            (r'[0-9]+', Number.Integer),                   # decimal whole number61        ],62        'strings': [63            (r"'[^\n']*'", String),  # single quoted string64            (r'"[^\n"]*"', String),  # double quoted string65        ],66        'operators': [67            # Arithmetic Operators68            (r'[+-]', Operator),69            (r'[*/]', Operator),70            # Relational Operators71            (r'[=#<>]', Operator),72            # Dereferencing Operator73            (r'\^', Operator),74            # Logical AND Operator75            (r'&', Operator),76            # Logical NOT Operator77            (r'~', Operator),78            # Assignment Symbol79            (r':=', Operator),80            # Range Constructor81            (r'\.\.', Operator),82            (r'\$', Operator),83        ],84        'identifiers': [85            (r'([a-zA-Z_$][\w$]*)', Name),86        ],87        'builtins': [88            (words((89                'ANYPTR', 'ANYREC', 'BOOLEAN', 'BYTE', 'CHAR', 'INTEGER', 'LONGINT',90                'REAL', 'SET', 'SHORTCHAR', 'SHORTINT', 'SHORTREAL'91                ), suffix=r'\b'), Keyword.Type),92            (words((93                'ABS', 'ABSTRACT', 'ARRAY', 'ASH', 'ASSERT', 'BEGIN', 'BITS', 'BY',94                'CAP', 'CASE', 'CHR', 'CLOSE', 'CONST', 'DEC', 'DIV', 'DO', 'ELSE',95                'ELSIF', 'EMPTY', 'END', 'ENTIER', 'EXCL', 'EXIT', 'EXTENSIBLE', 'FOR',96                'HALT', 'IF', 'IMPORT', 'IN', 'INC', 'INCL', 'IS', 'LEN', 'LIMITED',97                'LONG', 'LOOP', 'MAX', 'MIN', 'MOD', 'MODULE', 'NEW', 'ODD', 'OF',98                'OR', 'ORD', 'OUT', 'POINTER', 'PROCEDURE', 'RECORD', 'REPEAT', 'RETURN',99                'SHORT', 'SHORTCHAR', 'SHORTINT', 'SIZE', 'THEN', 'TYPE', 'TO', 'UNTIL',100                'VAR', 'WHILE', 'WITH'101                ), suffix=r'\b'), Keyword.Reserved),102            (r'(TRUE|FALSE|NIL|INF)\b', Keyword.Constant),103        ]104    }105 106    def analyse_text(text):107        """The only other lexer using .cp is the C++ one, so we check if for108        a few common Pascal keywords here. Those are unfortunately quite109        common across various business languages as well."""110        result = 0111        if 'BEGIN' in text:112            result += 0.01113        if 'END' in text:114            result += 0.01115        if 'PROCEDURE' in text:116            result += 0.01117        if 'END' in text:118            result += 0.01119 120        return result121 
codekingpro/portable-devtools · Team Ai