ambient.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """
  2. pygments.lexers.ambient
  3. ~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for AmbientTalk language.
  5. :copyright: Copyright 2006-2023 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, bygroups
  10. from pygments.token import Comment, Operator, Keyword, Name, String, \
  11. Number, Punctuation, Whitespace
  12. __all__ = ['AmbientTalkLexer']
  13. class AmbientTalkLexer(RegexLexer):
  14. """
  15. Lexer for AmbientTalk source code.
  16. .. versionadded:: 2.0
  17. """
  18. name = 'AmbientTalk'
  19. url = 'https://code.google.com/p/ambienttalk'
  20. filenames = ['*.at']
  21. aliases = ['ambienttalk', 'ambienttalk/2', 'at']
  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+', Whitespace),
  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*)', bygroups(Whitespace, Punctuation, Whitespace)),
  64. (r'[a-zA-Z_]\w*', Name.Variable),
  65. ],
  66. }