ambient.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.ambient
  4. ~~~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for AmbientTalk language.
  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
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  12. Number, Punctuation
  13. __all__ = ['AmbientTalkLexer']
  14. class AmbientTalkLexer(RegexLexer):
  15. """
  16. Lexer for `AmbientTalk <https://code.google.com/p/ambienttalk>`_ source code.
  17. .. versionadded:: 2.0
  18. """
  19. name = 'AmbientTalk'
  20. filenames = ['*.at']
  21. aliases = ['at', 'ambienttalk', 'ambienttalk/2']
  22. mimetypes = ['text/x-ambienttalk']
  23. flags = re.MULTILINE | re.DOTALL
  24. builtin = words(('if:', 'then:', 'else:', 'when:', 'whenever:', 'discovered:',
  25. 'disconnected:', 'reconnected:', 'takenOffline:', 'becomes:',
  26. 'export:', 'as:', 'object:', 'actor:', 'mirror:', 'taggedAs:',
  27. 'mirroredBy:', 'is:'))
  28. tokens = {
  29. 'root': [
  30. (r'\s+', Text),
  31. (r'//.*?\n', Comment.Single),
  32. (r'/\*.*?\*/', Comment.Multiline),
  33. (r'(def|deftype|import|alias|exclude)\b', Keyword),
  34. (builtin, Name.Builtin),
  35. (r'(true|false|nil)\b', Keyword.Constant),
  36. (r'(~|lobby|jlobby|/)\.', Keyword.Constant, 'namespace'),
  37. (r'"(\\\\|\\"|[^"])*"', String),
  38. (r'\|', Punctuation, 'arglist'),
  39. (r'<:|[*^!%&<>+=,./?-]|:=', Operator),
  40. (r"`[a-zA-Z_]\w*", String.Symbol),
  41. (r"[a-zA-Z_]\w*:", Name.Function),
  42. (r"[{}()\[\];`]", Punctuation),
  43. (r'(self|super)\b', Name.Variable.Instance),
  44. (r"[a-zA-Z_]\w*", Name.Variable),
  45. (r"@[a-zA-Z_]\w*", Name.Class),
  46. (r"@\[", Name.Class, 'annotations'),
  47. include('numbers'),
  48. ],
  49. 'numbers': [
  50. (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
  51. (r'\d+', Number.Integer)
  52. ],
  53. 'namespace': [
  54. (r'[a-zA-Z_]\w*\.', Name.Namespace),
  55. (r'[a-zA-Z_]\w*:', Name.Function, '#pop'),
  56. (r'[a-zA-Z_]\w*(?!\.)', Name.Function, '#pop')
  57. ],
  58. 'annotations': [
  59. (r"(.*?)\]", Name.Class, '#pop')
  60. ],
  61. 'arglist': [
  62. (r'\|', Punctuation, '#pop'),
  63. (r'\s*(,)\s*', Punctuation),
  64. (r'[a-zA-Z_]\w*', Name.Variable),
  65. ],
  66. }