eiffel.py 2.6 KB

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