|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.supercollider |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexer for SuperCollider |
|
7 |
|
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 import re |
|
13 |
|
14 from pygments.lexer import RegexLexer, include, words |
|
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
16 Number, Punctuation |
|
17 |
|
18 __all__ = ['SuperColliderLexer'] |
|
19 |
|
20 |
|
21 class SuperColliderLexer(RegexLexer): |
|
22 """ |
|
23 For `SuperCollider <http://supercollider.github.io/>`_ source code. |
|
24 |
|
25 .. versionadded:: 2.1 |
|
26 """ |
|
27 |
|
28 name = 'SuperCollider' |
|
29 aliases = ['sc', 'supercollider'] |
|
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 (r'', Text, '#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', 'Error', |
|
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_][a-zA-Z0-9_]*', Name.Other), |
|
83 (r'\\?[$a-zA-Z_][a-zA-Z0-9_]*', 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 } |