bdd.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """
  2. pygments.lexers.bdd
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexer for BDD(Behavior-driven development).
  5. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, include
  9. from pygments.token import Comment, Keyword, Name, String, Number, Text, \
  10. Punctuation, Whitespace
  11. __all__ = ['BddLexer']
  12. class BddLexer(RegexLexer):
  13. """
  14. Lexer for BDD(Behavior-driven development), which highlights not only
  15. keywords, but also comments, punctuations, strings, numbers, and variables.
  16. """
  17. name = 'Bdd'
  18. aliases = ['bdd']
  19. filenames = ['*.feature']
  20. mimetypes = ['text/x-bdd']
  21. url = 'https://en.wikipedia.org/wiki/Behavior-driven_development'
  22. version_added = '2.11'
  23. step_keywords = (r'Given|When|Then|Add|And|Feature|Scenario Outline|'
  24. r'Scenario|Background|Examples|But')
  25. tokens = {
  26. 'comments': [
  27. (r'^\s*#.*$', Comment),
  28. ],
  29. 'miscellaneous': [
  30. (r'(<|>|\[|\]|=|\||:|\(|\)|\{|\}|,|\.|;|-|_|\$)', Punctuation),
  31. (r'((?<=\<)[^\\>]+(?=\>))', Name.Variable),
  32. (r'"([^\"]*)"', String),
  33. (r'^@\S+', Name.Label),
  34. ],
  35. 'numbers': [
  36. (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number),
  37. ],
  38. 'root': [
  39. (r'\n|\s+', Whitespace),
  40. (step_keywords, Keyword),
  41. include('comments'),
  42. include('miscellaneous'),
  43. include('numbers'),
  44. (r'\S+', Text),
  45. ]
  46. }
  47. def analyse_text(self, text):
  48. return