Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/supercollider.py: 87%

15 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-01 06:54 +0000

1""" 

2 pygments.lexers.supercollider 

3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexer for SuperCollider 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12 

13from pygments.lexer import RegexLexer, include, words, default 

14from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 

15 Number, Punctuation 

16 

17__all__ = ['SuperColliderLexer'] 

18 

19 

20class SuperColliderLexer(RegexLexer): 

21 """ 

22 For SuperCollider source code. 

23 

24 .. versionadded:: 2.1 

25 """ 

26 

27 name = 'SuperCollider' 

28 url = 'http://supercollider.github.io/' 

29 aliases = ['supercollider', 'sc'] 

30 filenames = ['*.sc', '*.scd'] 

31 mimetypes = ['application/supercollider', 'text/supercollider'] 

32 

33 flags = re.DOTALL | re.MULTILINE 

34 tokens = { 

35 'commentsandwhitespace': [ 

36 (r'\s+', Text), 

37 (r'<!--', Comment), 

38 (r'//.*?\n', Comment.Single), 

39 (r'/\*.*?\*/', Comment.Multiline) 

40 ], 

41 'slashstartsregex': [ 

42 include('commentsandwhitespace'), 

43 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' 

44 r'([gim]+\b|\B)', String.Regex, '#pop'), 

45 (r'(?=/)', Text, ('#pop', 'badregex')), 

46 default('#pop'), 

47 ], 

48 'badregex': [ 

49 (r'\n', Text, '#pop') 

50 ], 

51 'root': [ 

52 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), 

53 include('commentsandwhitespace'), 

54 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' 

55 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), 

56 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 

57 (r'[})\].]', Punctuation), 

58 (words(( 

59 'for', 'in', 'while', 'do', 'break', 'return', 'continue', 

60 'switch', 'case', 'default', 'if', 'else', 'throw', 'try', 

61 'catch', 'finally', 'new', 'delete', 'typeof', 'instanceof', 

62 'void'), suffix=r'\b'), 

63 Keyword, 'slashstartsregex'), 

64 (words(('var', 'let', 'with', 'function', 'arg'), suffix=r'\b'), 

65 Keyword.Declaration, 'slashstartsregex'), 

66 (words(( 

67 '(abstract', 'boolean', 'byte', 'char', 'class', 'const', 

68 'debugger', 'double', 'enum', 'export', 'extends', 'final', 

69 'float', 'goto', 'implements', 'import', 'int', 'interface', 

70 'long', 'native', 'package', 'private', 'protected', 'public', 

71 'short', 'static', 'super', 'synchronized', 'throws', 

72 'transient', 'volatile'), suffix=r'\b'), 

73 Keyword.Reserved), 

74 (words(('true', 'false', 'nil', 'inf'), suffix=r'\b'), Keyword.Constant), 

75 (words(( 

76 'Array', 'Boolean', 'Date', 'Error', 'Function', 'Number', 

77 'Object', 'Packages', 'RegExp', 'String', 

78 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'super', 

79 'thisFunctionDef', 'thisFunction', 'thisMethod', 'thisProcess', 

80 'thisThread', 'this'), suffix=r'\b'), 

81 Name.Builtin), 

82 (r'[$a-zA-Z_]\w*', Name.Other), 

83 (r'\\?[$a-zA-Z_]\w*', String.Symbol), 

84 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

85 (r'0x[0-9a-fA-F]+', Number.Hex), 

86 (r'[0-9]+', Number.Integer), 

87 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double), 

88 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single), 

89 ] 

90 } 

91 

92 def analyse_text(text): 

93 """We're searching for a common function and a unique keyword here.""" 

94 if 'SinOsc' in text or 'thisFunctionDef' in text: 

95 return 0.1