supercollider.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.supercollider
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Lexer for SuperCollider
  6. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. import re
  10. from pygments.lexer import RegexLexer, include, words, default
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  12. Number, Punctuation
  13. __all__ = ['SuperColliderLexer']
  14. class SuperColliderLexer(RegexLexer):
  15. """
  16. For `SuperCollider <http://supercollider.github.io/>`_ source code.
  17. .. versionadded:: 2.1
  18. """
  19. name = 'SuperCollider'
  20. aliases = ['sc', 'supercollider']
  21. filenames = ['*.sc', '*.scd']
  22. mimetypes = ['application/supercollider', 'text/supercollider', ]
  23. flags = re.DOTALL | re.MULTILINE
  24. tokens = {
  25. 'commentsandwhitespace': [
  26. (r'\s+', Text),
  27. (r'<!--', Comment),
  28. (r'//.*?\n', Comment.Single),
  29. (r'/\*.*?\*/', Comment.Multiline)
  30. ],
  31. 'slashstartsregex': [
  32. include('commentsandwhitespace'),
  33. (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
  34. r'([gim]+\b|\B)', String.Regex, '#pop'),
  35. (r'(?=/)', Text, ('#pop', 'badregex')),
  36. default('#pop'),
  37. ],
  38. 'badregex': [
  39. (r'\n', Text, '#pop')
  40. ],
  41. 'root': [
  42. (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
  43. include('commentsandwhitespace'),
  44. (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
  45. r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
  46. (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
  47. (r'[})\].]', Punctuation),
  48. (words((
  49. 'for', 'in', 'while', 'do', 'break', 'return', 'continue',
  50. 'switch', 'case', 'default', 'if', 'else', 'throw', 'try',
  51. 'catch', 'finally', 'new', 'delete', 'typeof', 'instanceof',
  52. 'void'), suffix=r'\b'),
  53. Keyword, 'slashstartsregex'),
  54. (words(('var', 'let', 'with', 'function', 'arg'), suffix=r'\b'),
  55. Keyword.Declaration, 'slashstartsregex'),
  56. (words((
  57. '(abstract', 'boolean', 'byte', 'char', 'class', 'const',
  58. 'debugger', 'double', 'enum', 'export', 'extends', 'final',
  59. 'float', 'goto', 'implements', 'import', 'int', 'interface',
  60. 'long', 'native', 'package', 'private', 'protected', 'public',
  61. 'short', 'static', 'super', 'synchronized', 'throws',
  62. 'transient', 'volatile'), suffix=r'\b'),
  63. Keyword.Reserved),
  64. (words(('true', 'false', 'nil', 'inf'), suffix=r'\b'), Keyword.Constant),
  65. (words((
  66. 'Array', 'Boolean', 'Date', 'Error', 'Function', 'Number',
  67. 'Object', 'Packages', 'RegExp', 'String',
  68. 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'super',
  69. 'thisFunctionDef', 'thisFunction', 'thisMethod', 'thisProcess',
  70. 'thisThread', 'this'), suffix=r'\b'),
  71. Name.Builtin),
  72. (r'[$a-zA-Z_]\w*', Name.Other),
  73. (r'\\?[$a-zA-Z_]\w*', String.Symbol),
  74. (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  75. (r'0x[0-9a-fA-F]+', Number.Hex),
  76. (r'[0-9]+', Number.Integer),
  77. (r'"(\\\\|\\"|[^"])*"', String.Double),
  78. (r"'(\\\\|\\'|[^'])*'", String.Single),
  79. ]
  80. }