bdd.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """
  2. pygments.lexers.bdd
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexer for BDD(Behavior-driven development).
  5. More information: https://en.wikipedia.org/wiki/Behavior-driven_development
  6. :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. from pygments.lexer import RegexLexer, include
  10. from pygments.token import Comment, Keyword, Name, String, Number, Text, \
  11. Punctuation, Whitespace
  12. __all__ = ['BddLexer']
  13. class BddLexer(RegexLexer):
  14. """
  15. Lexer for BDD(Behavior-driven development), which highlights not only
  16. keywords, but also comments, punctuations, strings, numbers, and variables.
  17. .. versionadded:: 2.11
  18. """
  19. name = 'Bdd'
  20. aliases = ['bdd']
  21. filenames = ['*.feature']
  22. mimetypes = ['text/x-bdd']
  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