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