Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
elm.py124 linesDownload Raw Back to lexers
1"""2    pygments.lexers.elm3    ~~~~~~~~~~~~~~~~~~~4 5    Lexer for the Elm programming language.6 7    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10 11from pygments.lexer import RegexLexer, words, include, bygroups12from pygments.token import Comment, Keyword, Name, Number, Punctuation, \13    String, Whitespace14 15__all__ = ['ElmLexer']16 17 18class ElmLexer(RegexLexer):19    """20    For Elm source code.21    """22 23    name = 'Elm'24    url = 'https://elm-lang.org/'25    aliases = ['elm']26    filenames = ['*.elm']27    mimetypes = ['text/x-elm']28    version_added = '2.1'29 30    validName = r'[a-z_][a-zA-Z0-9_\']*'31 32    specialName = r'^main '33 34    builtinOps = (35        '~', '||', '|>', '|', '`', '^', '\\', '\'', '>>', '>=', '>', '==',36        '=', '<~', '<|', '<=', '<<', '<-', '<', '::', ':', '/=', '//', '/',37        '..', '.', '->', '-', '++', '+', '*', '&&', '%',38    )39 40    reservedWords = words((41        'alias', 'as', 'case', 'else', 'if', 'import', 'in',42        'let', 'module', 'of', 'port', 'then', 'type', 'where',43    ), suffix=r'\b')44 45    tokens = {46        'root': [47 48            # Comments49            (r'\{-', Comment.Multiline, 'comment'),50            (r'--.*', Comment.Single),51 52            # Whitespace53            (r'\s+', Whitespace),54 55            # Strings56            (r'"', String, 'doublequote'),57 58            # Modules59            (r'^(\s*)(module)(\s*)', bygroups(Whitespace, Keyword.Namespace,60                Whitespace), 'imports'),61 62            # Imports63            (r'^(\s*)(import)(\s*)', bygroups(Whitespace, Keyword.Namespace,64                Whitespace), 'imports'),65 66            # Shaders67            (r'\[glsl\|.*', Name.Entity, 'shader'),68 69            # Keywords70            (reservedWords, Keyword.Reserved),71 72            # Types73            (r'[A-Z][a-zA-Z0-9_]*', Keyword.Type),74 75            # Main76            (specialName, Keyword.Reserved),77 78            # Prefix Operators79            (words((builtinOps), prefix=r'\(', suffix=r'\)'), Name.Function),80 81            # Infix Operators82            (words(builtinOps), Name.Function),83 84            # Numbers85            include('numbers'),86 87            # Variable Names88            (validName, Name.Variable),89 90            # Parens91            (r'[,()\[\]{}]', Punctuation),92 93        ],94 95        'comment': [96            (r'-(?!\})', Comment.Multiline),97            (r'\{-', Comment.Multiline, 'comment'),98            (r'[^-}]', Comment.Multiline),99            (r'-\}', Comment.Multiline, '#pop'),100        ],101 102        'doublequote': [103            (r'\\u[0-9a-fA-F]{4}', String.Escape),104            (r'\\[nrfvb\\"]', String.Escape),105            (r'[^"]', String),106            (r'"', String, '#pop'),107        ],108 109        'imports': [110            (r'\w+(\.\w+)*', Name.Class, '#pop'),111        ],112 113        'numbers': [114            (r'_?\d+\.(?=\d+)', Number.Float),115            (r'_?\d+', Number.Integer),116        ],117 118        'shader': [119            (r'\|(?!\])', Name.Entity),120            (r'\|\]', Name.Entity, '#pop'),121            (r'(.*)(\n)', bygroups(Name.Entity, Whitespace)),122        ],123    }124 
codekingpro/portable-devtools · Team Ai