iolang.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.iolang
  4. ~~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for the Io language.
  6. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. from pygments.lexer import RegexLexer
  10. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  11. Number
  12. __all__ = ['IoLexer']
  13. class IoLexer(RegexLexer):
  14. """
  15. For `Io <http://iolanguage.com/>`_ (a small, prototype-based
  16. programming language) source.
  17. .. versionadded:: 0.10
  18. """
  19. name = 'Io'
  20. filenames = ['*.io']
  21. aliases = ['io']
  22. mimetypes = ['text/x-iosrc']
  23. tokens = {
  24. 'root': [
  25. (r'\n', Text),
  26. (r'\s+', Text),
  27. # Comments
  28. (r'//(.*?)\n', Comment.Single),
  29. (r'#(.*?)\n', Comment.Single),
  30. (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
  31. (r'/\+', Comment.Multiline, 'nestedcomment'),
  32. # DoubleQuotedString
  33. (r'"(\\\\|\\"|[^"])*"', String),
  34. # Operators
  35. (r'::=|:=|=|\(|\)|;|,|\*|-|\+|>|<|@|!|/|\||\^|\.|%|&|\[|\]|\{|\}',
  36. Operator),
  37. # keywords
  38. (r'(clone|do|doFile|doString|method|for|if|else|elseif|then)\b',
  39. Keyword),
  40. # constants
  41. (r'(nil|false|true)\b', Name.Constant),
  42. # names
  43. (r'(Object|list|List|Map|args|Sequence|Coroutine|File)\b',
  44. Name.Builtin),
  45. (r'[a-zA-Z_]\w*', Name),
  46. # numbers
  47. (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
  48. (r'\d+', Number.Integer)
  49. ],
  50. 'nestedcomment': [
  51. (r'[^+/]+', Comment.Multiline),
  52. (r'/\+', Comment.Multiline, '#push'),
  53. (r'\+/', Comment.Multiline, '#pop'),
  54. (r'[+/]', Comment.Multiline),
  55. ]
  56. }