ambient.py 2.5 KB

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