diff options
author | xuan <jypercent@gmail.com> | 2021-11-28 01:25:49 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-27 15:55:49 +0100 |
commit | 97e5c04a61334b0840077f2a59de9dd8bb401e96 (patch) | |
tree | 1d1ed84e191f46909c4b01b985f58480a59b3443 | |
parent | e025989fb0b6c35493bbe8dd7882a1fdf43de82e (diff) | |
download | pygments-git-97e5c04a61334b0840077f2a59de9dd8bb401e96.tar.gz |
Add support for BDD features / stories (#1803)
* Create BDD.py
Initialize the lexer file of BDD
Add keywords of BDD
* Update the 'RegexLexer'
* Edit and test
* Update BDD.py
* Update BDD.py
* Update the BddLexer file
* Update the BddLexer of root tokens
* edit bdd
Add regular expression for tokens
* edit bdd
Add regular expression for tokens
* add .gitignore
* updata bdd.lexer
* Delete bdd.py
* Update the Keywords, Numbers, Punctuation token
* bdd.py
Assign different colors to keywords, punctuation, numbers, and variables.
* Update the BddLexer file
* Update bdd.py
Fix the file name.
* Add the detection for '@'
Co-Authored-By: OMGJL <8707895+OMGJL@users.noreply.github.com>
* Update bdd.py
Add detection of double quotes.
Co-Authored-By: OMGJL <8707895+OMGJL@users.noreply.github.com>
* Fix the double quotes
* fix the quote recognition
* add comments
* update the root dir
* add bdd test cases
* Delete .DS_Store
* Delete .DS_Store
* Delete .DS_Store
* remove DS file
* restore the gitignore file
* update the bdd lexer
* update the bdd lexer
* update the whitespace highlight
* update the whitespace highlight
* refactor the bdd.py
* update the punctuation
* update the punctuation
* update bdd token
Change "." to the "\S+",
Which reduce the test output file size.
Co-Authored-By: OMGJL <8707895+OMGJL@users.noreply.github.com>
* Update bdd.py
Reduce the new token for each space
Co-authored-by: Hongyuan Yan <hongyuan.yan@student.adelaide.edu.au>
Co-authored-by: OMGJL <lzhsjunkmail@gmail.com>
Co-authored-by: Hongyuan Yan <54675432+kirito330824@users.noreply.github.com>
Co-authored-by: Jessie2110 <71688609+Jessie2110@users.noreply.github.com>
Co-authored-by: Jessie2110 <wuqiong2110@gmail.com>
Co-authored-by: OMGJL <8707895+OMGJL@users.noreply.github.com>
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | doc/languages.rst | 1 | ||||
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/bdd.py | 53 | ||||
-rw-r--r-- | tests/examplefiles/bdd/example.feature | 31 | ||||
-rw-r--r-- | tests/examplefiles/bdd/example.feature.output | 344 |
6 files changed, 431 insertions, 0 deletions
@@ -221,6 +221,7 @@ Other contributors, listed alphabetically, are: * Brian Tiffin -- OpenCOBOL lexer * Bob Tolbert -- Hy lexer * Matthias Trute -- Forth lexer +* Tuoa Spi T4 -- Bdd lexer * Erick Tryzelaar -- Felix lexer * Alexander Udalov -- Kotlin lexer improvements * Thomas Van Doren -- Chapel lexer diff --git a/doc/languages.rst b/doc/languages.rst index ecd8ff56..bfb84374 100644 --- a/doc/languages.rst +++ b/doc/languages.rst @@ -221,6 +221,7 @@ Other markup * Apache config files * Apache Pig * BBCode +* Bdd * CapDL * `Cap'n Proto <https://capnproto.org>`_ * `CDDL <https://datatracker.ietf.org/doc/rfc8610/>`_ diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index ae42b7bc..ab7be87d 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -57,6 +57,7 @@ LEXERS = { 'BashLexer': ('pygments.lexers.shell', 'Bash', ('bash', 'sh', 'ksh', 'zsh', 'shell'), ('*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass', '*.exheres-0', '*.exlib', '*.zsh', '.bashrc', 'bashrc', '.bash_*', 'bash_*', 'zshrc', '.zshrc', '.kshrc', 'kshrc', 'PKGBUILD'), ('application/x-sh', 'application/x-shellscript', 'text/x-shellscript')), 'BashSessionLexer': ('pygments.lexers.shell', 'Bash Session', ('console', 'shell-session'), ('*.sh-session', '*.shell-session'), ('application/x-shell-session', 'application/x-sh-session')), 'BatchLexer': ('pygments.lexers.shell', 'Batchfile', ('batch', 'bat', 'dosbatch', 'winbatch'), ('*.bat', '*.cmd'), ('application/x-dos-batch',)), + 'BddLexer': ('pygments.lexers.bdd', 'Bdd', ('bdd',), ('*.feature',), ('text/x-bdd',)), 'BefungeLexer': ('pygments.lexers.esoteric', 'Befunge', ('befunge',), ('*.befunge',), ('application/x-befunge',)), 'BibTeXLexer': ('pygments.lexers.bibtex', 'BibTeX', ('bibtex', 'bib'), ('*.bib',), ('text/x-bibtex',)), 'BlitzBasicLexer': ('pygments.lexers.basic', 'BlitzBasic', ('blitzbasic', 'b3d', 'bplus'), ('*.bb', '*.decls'), ('text/x-bb',)), diff --git a/pygments/lexers/bdd.py b/pygments/lexers/bdd.py new file mode 100644 index 00000000..f65745b0 --- /dev/null +++ b/pygments/lexers/bdd.py @@ -0,0 +1,53 @@ +""" + pygments.lexers.bdd + ~~~~~~~~~~~~~~~~~~~~~ + + Lexer for BDD(Behavior-driven development). + More information: https://en.wikipedia.org/wiki/Behavior-driven_development + + :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, include +from pygments.token import Comment, Keyword, Name, String, Number, Text, Punctuation, Whitespace + +__all__ = ['BddLexer'] + +class BddLexer(RegexLexer): + """ + Lexer for BDD(Behavior-driven development), which highlights not only keywords, + but also comments, punctuations, strings, numbers, and variables. + + .. versionadded:: 2.10 + """ + + name = 'Bdd' + aliases = ['bdd'] + filenames = ['*.feature'] + mimetypes = ['text/x-bdd'] + + step_keywords = r'Given|When|Then|Add|And|Feature|Scenario Outline|Scenario|Background|Examples|But' + + tokens = { + 'comments': [ + (r'^\s*#.*$', Comment), + ], + 'miscellaneous': [ + (r'(<|>|\[|\]|=|\||:|\(|\)|\{|\}|,|\.|;|-|_|\$)', Punctuation), + (r'((?<=\<)[^\\>]+(?=\>))', Name.Variable), + (r'"([^\"]*)"', String), + (r'^@\S+', Name.Label), + ], + 'numbers': [ + (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number), + ], + 'root': [ + (r'\n|\s+', Whitespace), + (step_keywords, Keyword), + include('comments'), + include('miscellaneous'), + include('numbers'), + (r'\S+', Text), + ] + }
\ No newline at end of file diff --git a/tests/examplefiles/bdd/example.feature b/tests/examplefiles/bdd/example.feature new file mode 100644 index 00000000..e819dd27 --- /dev/null +++ b/tests/examplefiles/bdd/example.feature @@ -0,0 +1,31 @@ +#!text +View Quotes should do something +Meta: +@verifies G989 + +Feature: Serve coffee + Coffee should not be served until paid for + Coffee should not be served until the button has been pressed + If there is no coffee left then money should be refunded + + Background: + Given a global administrator named "Greg" + And a blog named "Greg's anti-tax rants" + And a customer named "Dr. Bill" + And a blog named "Expensive Therapy" owned by "Dr. Bill" + + Scenario: Buy last coffee + Given there are 1 coffees left in the machine + And I have deposited 1$ + When I press the coffee button + Then I should be served a coffee + + Scenario Outline: eating + Given there are <start> cucumbers + When I eat <eat> cucumbers + Then I should have <left> cucumbers + + Examples: + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 15 |
\ No newline at end of file diff --git a/tests/examplefiles/bdd/example.feature.output b/tests/examplefiles/bdd/example.feature.output new file mode 100644 index 00000000..3946f1c4 --- /dev/null +++ b/tests/examplefiles/bdd/example.feature.output @@ -0,0 +1,344 @@ +'#!text' Comment +'\n' Text.Whitespace + +'View' Text +' ' Text.Whitespace +'Quotes' Text +' ' Text.Whitespace +'should' Text +' ' Text.Whitespace +'do' Text +' ' Text.Whitespace +'something' Text +'\n' Text.Whitespace + +'Meta:' Text +'\n' Text.Whitespace + +'@verifies' Name.Label +' ' Text.Whitespace +'G989' Text +'\n' Text.Whitespace + +'\n' Text.Whitespace + +'Feature' Keyword +':' Punctuation +' ' Text.Whitespace +'Serve' Text +' ' Text.Whitespace +'coffee' Text +'\n' Text.Whitespace + +' ' Text.Whitespace +'Coffee' Text +' ' Text.Whitespace +'should' Text +' ' Text.Whitespace +'not' Text +' ' Text.Whitespace +'be' Text +' ' Text.Whitespace +'served' Text +' ' Text.Whitespace +'until' Text +' ' Text.Whitespace +'paid' Text +' ' Text.Whitespace +'for' Text +'\n' Text.Whitespace + +' ' Text.Whitespace +'Coffee' Text +' ' Text.Whitespace +'should' Text +' ' Text.Whitespace +'not' Text +' ' Text.Whitespace +'be' Text +' ' Text.Whitespace +'served' Text +' ' Text.Whitespace +'until' Text +' ' Text.Whitespace +'the' Text +' ' Text.Whitespace +'button' Text +' ' Text.Whitespace +'has' Text +' ' Text.Whitespace +'been' Text +' ' Text.Whitespace +'pressed' Text +'\n' Text.Whitespace + +' ' Text.Whitespace +'If' Text +' ' Text.Whitespace +'there' Text +' ' Text.Whitespace +'is' Text +' ' Text.Whitespace +'no' Text +' ' Text.Whitespace +'coffee' Text +' ' Text.Whitespace +'left' Text +' ' Text.Whitespace +'then' Text +' ' Text.Whitespace +'money' Text +' ' Text.Whitespace +'should' Text +' ' Text.Whitespace +'be' Text +' ' Text.Whitespace +'refunded' Text +'\n' Text.Whitespace + +'\n' Text.Whitespace + +' ' Text.Whitespace +'Background' Keyword +':' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'Given' Keyword +' ' Text.Whitespace +'a' Text +' ' Text.Whitespace +'global' Text +' ' Text.Whitespace +'administrator' Text +' ' Text.Whitespace +'named' Text +' ' Text.Whitespace +'"Greg"' Literal.String +'\n' Text.Whitespace + +' ' Text.Whitespace +'And' Keyword +' ' Text.Whitespace +'a' Text +' ' Text.Whitespace +'blog' Text +' ' Text.Whitespace +'named' Text +' ' Text.Whitespace +'"Greg\'s anti-tax rants"' Literal.String +'\n' Text.Whitespace + +' ' Text.Whitespace +'And' Keyword +' ' Text.Whitespace +'a' Text +' ' Text.Whitespace +'customer' Text +' ' Text.Whitespace +'named' Text +' ' Text.Whitespace +'"Dr. Bill"' Literal.String +'\n' Text.Whitespace + +' ' Text.Whitespace +'And' Keyword +' ' Text.Whitespace +'a' Text +' ' Text.Whitespace +'blog' Text +' ' Text.Whitespace +'named' Text +' ' Text.Whitespace +'"Expensive Therapy"' Literal.String +' ' Text.Whitespace +'owned' Text +' ' Text.Whitespace +'by' Text +' ' Text.Whitespace +'"Dr. Bill"' Literal.String +'\n' Text.Whitespace + +'\n' Text.Whitespace + +' ' Text.Whitespace +'Scenario' Keyword +':' Punctuation +' ' Text.Whitespace +'Buy' Text +' ' Text.Whitespace +'last' Text +' ' Text.Whitespace +'coffee' Text +'\n' Text.Whitespace + +' ' Text.Whitespace +'Given' Keyword +' ' Text.Whitespace +'there' Text +' ' Text.Whitespace +'are' Text +' ' Text.Whitespace +'1' Literal.Number +' ' Text.Whitespace +'coffees' Text +' ' Text.Whitespace +'left' Text +' ' Text.Whitespace +'in' Text +' ' Text.Whitespace +'the' Text +' ' Text.Whitespace +'machine' Text +'\n' Text.Whitespace + +' ' Text.Whitespace +'And' Keyword +' ' Text.Whitespace +'I' Text +' ' Text.Whitespace +'have' Text +' ' Text.Whitespace +'deposited' Text +' ' Text.Whitespace +'1' Literal.Number +'$' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'When' Keyword +' ' Text.Whitespace +'I' Text +' ' Text.Whitespace +'press' Text +' ' Text.Whitespace +'the' Text +' ' Text.Whitespace +'coffee' Text +' ' Text.Whitespace +'button' Text +'\n' Text.Whitespace + +' ' Text.Whitespace +'Then' Keyword +' ' Text.Whitespace +'I' Text +' ' Text.Whitespace +'should' Text +' ' Text.Whitespace +'be' Text +' ' Text.Whitespace +'served' Text +' ' Text.Whitespace +'a' Text +' ' Text.Whitespace +'coffee' Text +'\n' Text.Whitespace + +'\n' Text.Whitespace + +' ' Text.Whitespace +'Scenario Outline' Keyword +':' Punctuation +' ' Text.Whitespace +'eating' Text +'\n' Text.Whitespace + +' ' Text.Whitespace +'Given' Keyword +' ' Text.Whitespace +'there' Text +' ' Text.Whitespace +'are' Text +' ' Text.Whitespace +'<' Punctuation +'start' Name.Variable +'>' Punctuation +' ' Text.Whitespace +'cucumbers' Text +'\n' Text.Whitespace + +' ' Text.Whitespace +'When' Keyword +' ' Text.Whitespace +'I' Text +' ' Text.Whitespace +'eat' Text +' ' Text.Whitespace +'<' Punctuation +'eat' Name.Variable +'>' Punctuation +' ' Text.Whitespace +'cucumbers' Text +'\n' Text.Whitespace + +' ' Text.Whitespace +'Then' Keyword +' ' Text.Whitespace +'I' Text +' ' Text.Whitespace +'should' Text +' ' Text.Whitespace +'have' Text +' ' Text.Whitespace +'<' Punctuation +'left' Name.Variable +'>' Punctuation +' ' Text.Whitespace +'cucumbers' Text +'\n' Text.Whitespace + +'\n' Text.Whitespace + +' ' Text.Whitespace +'Examples' Keyword +':' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'|' Punctuation +' ' Text.Whitespace +'start' Text +' ' Text.Whitespace +'|' Punctuation +' ' Text.Whitespace +'eat' Text +' ' Text.Whitespace +'|' Punctuation +' ' Text.Whitespace +'left' Text +' ' Text.Whitespace +'|' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'|' Punctuation +' ' Text.Whitespace +'12' Literal.Number +' ' Text.Whitespace +'|' Punctuation +' ' Text.Whitespace +'5' Literal.Number +' ' Text.Whitespace +'|' Punctuation +' ' Text.Whitespace +'7' Literal.Number +' ' Text.Whitespace +'|' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'|' Punctuation +' ' Text.Whitespace +'20' Literal.Number +' ' Text.Whitespace +'|' Punctuation +' ' Text.Whitespace +'5' Literal.Number +' ' Text.Whitespace +'|' Punctuation +' ' Text.Whitespace +'15' Literal.Number +' ' Text.Whitespace +'|' Punctuation +'\n' Text.Whitespace |