eiffel.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.eiffel
  4. ~~~~~~~~~~~~~~~~~~~~~~
  5. Lexer for the Eiffel 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, include, words
  10. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  11. Number, Punctuation
  12. __all__ = ['EiffelLexer']
  13. class EiffelLexer(RegexLexer):
  14. """
  15. For `Eiffel <http://www.eiffel.com>`_ source code.
  16. .. versionadded:: 2.0
  17. """
  18. name = 'Eiffel'
  19. aliases = ['eiffel']
  20. filenames = ['*.e']
  21. mimetypes = ['text/x-eiffel']
  22. tokens = {
  23. 'root': [
  24. (r'[^\S\n]+', Text),
  25. (r'--.*?\n', Comment.Single),
  26. (r'[^\S\n]+', Text),
  27. # Please note that keyword and operator are case insensitive.
  28. (r'(?i)(true|false|void|current|result|precursor)\b', Keyword.Constant),
  29. (r'(?i)(and(\s+then)?|not|xor|implies|or(\s+else)?)\b', Operator.Word),
  30. (words((
  31. 'across', 'agent', 'alias', 'all', 'as', 'assign', 'attached',
  32. 'attribute', 'check', 'class', 'convert', 'create', 'debug',
  33. 'deferred', 'detachable', 'do', 'else', 'elseif', 'end', 'ensure',
  34. 'expanded', 'export', 'external', 'feature', 'from', 'frozen', 'if',
  35. 'inherit', 'inspect', 'invariant', 'like', 'local', 'loop', 'none',
  36. 'note', 'obsolete', 'old', 'once', 'only', 'redefine', 'rename',
  37. 'require', 'rescue', 'retry', 'select', 'separate', 'then',
  38. 'undefine', 'until', 'variant', 'when'), prefix=r'(?i)\b', suffix=r'\b'),
  39. Keyword.Reserved),
  40. (r'"\[(([^\]%]|\n)|%(.|\n)|\][^"])*?\]"', String),
  41. (r'"([^"%\n]|%.)*?"', String),
  42. include('numbers'),
  43. (r"'([^'%]|%'|%%)'", String.Char),
  44. (r"(//|\\\\|>=|<=|:=|/=|~|/~|[\\?!#%&@|+/\-=>*$<^\[\]])", Operator),
  45. (r"([{}():;,.])", Punctuation),
  46. (r'([a-z]\w*)|([A-Z][A-Z0-9_]*[a-z]\w*)', Name),
  47. (r'([A-Z][A-Z0-9_]*)', Name.Class),
  48. (r'\n+', Text),
  49. ],
  50. 'numbers': [
  51. (r'0[xX][a-fA-F0-9]+', Number.Hex),
  52. (r'0[bB][01]+', Number.Bin),
  53. (r'0[cC][0-7]+', Number.Oct),
  54. (r'([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+)', Number.Float),
  55. (r'[0-9]+', Number.Integer),
  56. ],
  57. }