codekingpro/portable-devtools
114k
1"""2 pygments.lexers.supercollider3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~4 5 Lexer for SuperCollider6 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, words, default14from pygments.token import Text, Comment, Operator, Keyword, Name, String, \15 Number, Punctuation16 17__all__ = ['SuperColliderLexer']18 19 20class SuperColliderLexer(RegexLexer):21 """22 For SuperCollider source code.23 """24 25 name = 'SuperCollider'26 url = 'http://supercollider.github.io/'27 aliases = ['supercollider', 'sc']28 filenames = ['*.sc', '*.scd']29 mimetypes = ['application/supercollider', 'text/supercollider']30 version_added = '2.1'31 32 flags = re.DOTALL | re.MULTILINE33 tokens = {34 'commentsandwhitespace': [35 (r'\s+', Text),36 (r'<!--', Comment),37 (r'//.*?\n', Comment.Single),38 (r'/\*.*?\*/', Comment.Multiline)39 ],40 'slashstartsregex': [41 include('commentsandwhitespace'),42 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'43 r'([gim]+\b|\B)', String.Regex, '#pop'),44 (r'(?=/)', Text, ('#pop', 'badregex')),45 default('#pop'),46 ],47 'badregex': [48 (r'\n', Text, '#pop')49 ],50 'root': [51 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),52 include('commentsandwhitespace'),53 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'54 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),55 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),56 (r'[})\].]', Punctuation),57 (words((58 'for', 'in', 'while', 'do', 'break', 'return', 'continue',59 'switch', 'case', 'default', 'if', 'else', 'throw', 'try',60 'catch', 'finally', 'new', 'delete', 'typeof', 'instanceof',61 'void'), suffix=r'\b'),62 Keyword, 'slashstartsregex'),63 (words(('var', 'let', 'with', 'function', 'arg'), suffix=r'\b'),64 Keyword.Declaration, 'slashstartsregex'),65 (words((66 '(abstract', 'boolean', 'byte', 'char', 'class', 'const',67 'debugger', 'double', 'enum', 'export', 'extends', 'final',68 'float', 'goto', 'implements', 'import', 'int', 'interface',69 'long', 'native', 'package', 'private', 'protected', 'public',70 'short', 'static', 'super', 'synchronized', 'throws',71 'transient', 'volatile'), suffix=r'\b'),72 Keyword.Reserved),73 (words(('true', 'false', 'nil', 'inf'), suffix=r'\b'), Keyword.Constant),74 (words((75 'Array', 'Boolean', 'Date', 'Error', 'Function', 'Number',76 'Object', 'Packages', 'RegExp', 'String',77 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'super',78 'thisFunctionDef', 'thisFunction', 'thisMethod', 'thisProcess',79 'thisThread', 'this'), suffix=r'\b'),80 Name.Builtin),81 (r'[$a-zA-Z_]\w*', Name.Other),82 (r'\\?[$a-zA-Z_]\w*', String.Symbol),83 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),84 (r'0x[0-9a-fA-F]+', Number.Hex),85 (r'[0-9]+', Number.Integer),86 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),87 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),88 ]89 }90 91 def analyse_text(text):92 """We're searching for a common function and a unique keyword here."""93 if 'SinOsc' in text or 'thisFunctionDef' in text:94 return 0.195 