iolang.py 1.8 KB

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