eiffel.py 2.4 KB

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