Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
arturo.py250 linesDownload Raw Back to lexers
1"""2    pygments.lexers.arturo3    ~~~~~~~~~~~~~~~~~~~~~~4 5    Lexer for the Arturo language.6 7    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10 11from pygments.lexer import RegexLexer, bygroups, do_insertions, include, \12    this, using, words13from pygments.token import Comment, Error, Keyword, Name, Number, Operator, \14    Punctuation, String, Text15 16from pygments.util import ClassNotFound, get_bool_opt17 18__all__ = ['ArturoLexer']19 20 21class ArturoLexer(RegexLexer):22    """23    For Arturo source code.24 25    See `Arturo's Github <https://github.com/arturo-lang/arturo>`_26    and `Arturo's Website <https://arturo-lang.io/>`_.27    """28 29    name = 'Arturo'30    aliases = ['arturo', 'art']31    filenames = ['*.art']32    url = 'https://arturo-lang.io/'33    version_added = '2.14'34 35    def __init__(self, **options):36        self.handle_annotateds = get_bool_opt(options, 'handle_annotateds',37                                              True)38        RegexLexer.__init__(self, **options)39 40    def handle_annotated_strings(self, match):41        """Adds syntax from another languages inside annotated strings42 43        match args:44            1:open_string,45            2:exclamation_mark,46            3:lang_name,47            4:space_or_newline,48            5:code,49            6:close_string50        """51        from pygments.lexers import get_lexer_by_name52 53        # Header's section54        yield match.start(1), String.Double,   match.group(1)55        yield match.start(2), String.Interpol, match.group(2)56        yield match.start(3), String.Interpol, match.group(3)57        yield match.start(4), Text.Whitespace, match.group(4)58 59        lexer = None60        if self.handle_annotateds:61            try:62                lexer = get_lexer_by_name(match.group(3).strip())63            except ClassNotFound:64                pass65        code = match.group(5)66 67        if lexer is None:68            yield match.group(5), String, code69        else:70            yield from do_insertions([], lexer.get_tokens_unprocessed(code))71 72        yield match.start(6), String.Double, match.group(6)73 74    tokens = {75        'root': [76            (r';.*?$', Comment.Single),77            (r'^((\s#!)|(#!)).*?$', Comment.Hashbang),78 79            # Constants80            (words(('false', 'true', 'maybe'),      # boolean81                   suffix=r'\b'), Name.Constant),82            (words(('this', 'init'),                # class related keywords83                   prefix=r'\b', suffix=r'\b\??:?'), Name.Builtin.Pseudo),84            (r'`.`', String.Char),                  # character85            (r'\\\w+\b\??:?', Name.Property),       # array index86            (r'#\w+', Name.Constant),               # color87            (r'\b[0-9]+\.[0-9]+', Number.Float),    # float88            (r'\b[0-9]+', Number.Integer),          # integer89            (r'\w+\b\??:', Name.Label),             # label90            # Note: Literals can be labeled too91            (r'\'(?:\w+\b\??:?)', Keyword.Declaration),  # literal92            (r'\:\w+', Keyword.Type),               # type93            # Note: Attributes can be labeled too94            (r'\.\w+\??:?', Name.Attribute),        # attributes95 96            # Switch structure97            (r'(\()(.*?)(\)\?)',98             bygroups(Punctuation, using(this), Punctuation)),99 100            # Single Line Strings101            (r'"',   String.Double, 'inside-simple-string'),102            (r'»',   String.Single, 'inside-smart-string'),103            (r'«««', String.Double, 'inside-safe-string'),104            (r'\{\/', String.Single, 'inside-regex-string'),105 106            # Multi Line Strings107            (r'\{\:', String.Double, 'inside-curly-verb-string'),108            (r'(\{)(\!)(\w+)(\s|\n)([\w\W]*?)(^\})', handle_annotated_strings),109            (r'\{', String.Single, 'inside-curly-string'),110            (r'\-{3,}', String.Single, 'inside-eof-string'),111 112            include('builtin-functions'),113 114            # Operators115            (r'[()[\],]', Punctuation),116            (words(('->', '==>', '|', '::', '@', '#',  # sugar syntax117                    '$', '&', '!', '!!', './')), Name.Decorator),118            (words(('<:', ':>', ':<', '>:', '<\\', '<>', '<', '>',119                    'ø', '∞',120                    '+', '-', '*', '~', '=', '^', '%', '/', '//',121                    '==>', '<=>', '<==>',122                    '=>>', '<<=>>', '<<==>>',123                    '-->', '<->', '<-->',124                    '=|', '|=', '-:', ':-',125                    '_', '.', '..', '\\')), Operator),126 127            (r'\b\w+', Name),128            (r'\s+', Text.Whitespace),129            (r'.+$', Error),130        ],131 132        'inside-interpol': [133            (r'\|', String.Interpol, '#pop'),134            (r'[^|]+', using(this)),135        ],136        'inside-template': [137            (r'\|\|\>', String.Interpol, '#pop'),138            (r'[^|]+', using(this)),139        ],140        'string-escape': [141            (words(('\\\\', '\\n', '\\t', '\\"')), String.Escape),142        ],143 144        'inside-simple-string': [145            include('string-escape'),146            (r'\|', String.Interpol, 'inside-interpol'),        # Interpolation147            (r'\<\|\|', String.Interpol, 'inside-template'),    # Templates148            (r'"', String.Double, '#pop'),   # Closing Quote149            (r'[^|"]+', String)              # String Content150        ],151        'inside-smart-string': [152            include('string-escape'),153            (r'\|', String.Interpol, 'inside-interpol'),        # Interpolation154            (r'\<\|\|', String.Interpol, 'inside-template'),    # Templates155            (r'\n', String.Single, '#pop'),  # Closing Quote156            (r'[^|\n]+', String)             # String Content157        ],158        'inside-safe-string': [159            include('string-escape'),160            (r'\|', String.Interpol, 'inside-interpol'),        # Interpolation161            (r'\<\|\|', String.Interpol, 'inside-template'),    # Templates162            (r'»»»', String.Double, '#pop'),    # Closing Quote163            (r'[^|»]+', String)                 # String Content164        ],165        'inside-regex-string': [166            (r'\\[sSwWdDbBZApPxucItnvfr0]+', String.Escape),167            (r'\|', String.Interpol, 'inside-interpol'),        # Interpolation168            (r'\<\|\|', String.Interpol, 'inside-template'),    # Templates169            (r'\/\}', String.Single, '#pop'),  # Closing Quote170            (r'[^|\/]+', String.Regex),        # String Content171        ],172        'inside-curly-verb-string': [173            include('string-escape'),174            (r'\|', String.Interpol, 'inside-interpol'),        # Interpolation175            (r'\<\|\|', String.Interpol, 'inside-template'),    # Templates176            (r'\:\}', String.Double, '#pop'),  # Closing Quote177            (r'[^|<:]+', String),              # String Content178        ],179        'inside-curly-string': [180            include('string-escape'),181            (r'\|', String.Interpol, 'inside-interpol'),        # Interpolation182            (r'\<\|\|', String.Interpol, 'inside-template'),    # Templates183            (r'\}', String.Single, '#pop'),   # Closing Quote184            (r'[^|<}]+', String),             # String Content185        ],186        'inside-eof-string': [187            include('string-escape'),188            (r'\|', String.Interpol, 'inside-interpol'),        # Interpolation189            (r'\<\|\|', String.Interpol, 'inside-template'),    # Templates190            (r'\Z', String.Single, '#pop'),   # Closing Quote191            (r'[^|<]+', String),              # String Content192        ],193 194        'builtin-functions': [195            (words((196                'all', 'and', 'any', 'ascii', 'attr', 'attribute',197                'attributeLabel', 'binary', 'block' 'char', 'contains',198                'database', 'date', 'dictionary', 'empty', 'equal', 'even',199                'every', 'exists', 'false', 'floatin', 'function', 'greater',200                'greaterOrEqual', 'if', 'in', 'inline', 'integer', 'is',201                'key', 'label', 'leap', 'less', 'lessOrEqual', 'literal',202                'logical', 'lower', 'nand', 'negative', 'nor', 'not',203                'notEqual', 'null', 'numeric', 'odd', 'or', 'path',204                'pathLabel', 'positive', 'prefix', 'prime', 'set', 'some',205                'sorted', 'standalone', 'string', 'subset', 'suffix',206                'superset', 'ymbol', 'true', 'try', 'type', 'unless', 'upper',207                'when', 'whitespace', 'word', 'xnor', 'xor', 'zero',208            ), prefix=r'\b', suffix=r'\b\?'), Name.Builtin),209            (words((210                'abs', 'acos', 'acosh', 'acsec', 'acsech', 'actan', 'actanh',211                'add', 'after', 'alphabet', 'and', 'angle', 'append', 'arg',212                'args', 'arity', 'array', 'as', 'asec', 'asech', 'asin',213                'asinh', 'atan', 'atan2', 'atanh', 'attr', 'attrs', 'average',214                'before', 'benchmark', 'blend', 'break', 'builtins1',215                'builtins2', 'call', 'capitalize', 'case', 'ceil', 'chop',216                'chunk', 'clear', 'close', 'cluster', 'color', 'combine',217                'conj', 'continue', 'copy', 'cos', 'cosh', 'couple', 'csec',218                'csech', 'ctan', 'ctanh', 'cursor', 'darken', 'dec', 'decode',219                'decouple', 'define', 'delete', 'desaturate', 'deviation',220                'dictionary', 'difference', 'digest', 'digits', 'div', 'do',221                'download', 'drop', 'dup', 'e', 'else', 'empty', 'encode',222                'ensure', 'env', 'epsilon', 'escape', 'execute', 'exit', 'exp',223                'extend', 'extract', 'factors', 'false', 'fdiv', 'filter',224                'first', 'flatten', 'floor', 'fold', 'from', 'function',225                'gamma', 'gcd', 'get', 'goto', 'hash', 'help', 'hypot', 'if',226                'in', 'inc', 'indent', 'index', 'infinity', 'info', 'input',227                'insert', 'inspect', 'intersection', 'invert', 'join', 'keys',228                'kurtosis', 'last', 'let', 'levenshtein', 'lighten', 'list',229                'ln', 'log', 'loop', 'lower', 'mail', 'map', 'match', 'max',230                'maybe', 'median', 'min', 'mod', 'module', 'mul', 'nand',231                'neg', 'new', 'nor', 'normalize', 'not', 'now', 'null', 'open',232                'or', 'outdent', 'pad', 'panic', 'path', 'pause',233                'permissions', 'permutate', 'pi', 'pop', 'pow', 'powerset',234                'powmod', 'prefix', 'print', 'prints', 'process', 'product',235                'query', 'random', 'range', 'read', 'relative', 'remove',236                'rename', 'render', 'repeat', 'replace', 'request', 'return',237                'reverse', 'round', 'sample', 'saturate', 'script', 'sec',238                'sech', 'select', 'serve', 'set', 'shl', 'shr', 'shuffle',239                'sin', 'sinh', 'size', 'skewness', 'slice', 'sort', 'split',240                'sqrt', 'squeeze', 'stack', 'strip', 'sub', 'suffix', 'sum',241                'switch', 'symbols', 'symlink', 'sys', 'take', 'tan', 'tanh',242                'terminal', 'to', 'true', 'truncate', 'try', 'type', 'union',243                'unique', 'unless', 'until', 'unzip', 'upper', 'values', 'var',244                'variance', 'volume', 'webview', 'while', 'with', 'wordwrap',245                'write', 'xnor', 'xor', 'zip'246            ), prefix=r'\b', suffix=r'\b'), Name.Builtin)247        ],248 249    }250