Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.
matthewfranglen edited this page Apr 23, 2015 · 20 revisions

The Gherkin syntax is not really specified anywhere except as Treetop files in Cucumber. One of the aims of the project is to define Gherkin in BNF.

Not exact BNF yet but massaging into valid BNF.


feature ::= white comment tags header background? feature_elements comment?
header ::= (!(scenario_outline | scenario | background) .)*
feature_elements ::= (scenario | scenario_outline)*
scenario ::= comment tags scenario_keyword space* lines_to_keyword white steps
scenario_outline ::= comment tags scenario_outline_keyword space* lines_to_keyword white steps examples_sections white
background ::= comment background_keyword space* lines_to_keyword? (eol+ | eof) steps
tags ::= white (tag (space|eol)+)*
tag ::= '@' ([^@\r\n\t ])+
comment ::= (comment_line white)*
comment_line ::= space* '#' line_to_eol
steps ::= step*
step ::= comment step_keyword keyword_space line_to_eol (eol+ | eof) multiline_arg? white
examples_sections ::= examples*
examples ::= comment space* examples_keyword space* lines_to_keyword? eol table white
multiline_arg ::=  table | py_string
py_string ::= open_py_string (!close_py_string .)* close_py_string
open_py_string ::= space* '"""' space* eol
close_py_string ::= eol space* '"""' white
cell ::= [^\r\n|]+ '|'
row ::= space* '|' cell+ eol
table ::= row+
step_keyword ::= 'Given' | 'When' | 'Then' | 'And' | 'But'
examples_keyword ::= 'Examples:'
scenario_outline_keyword ::= 'Scenario Outline:'
scenario_keyword ::= 'Scenario:'
background_keyword ::= 'Background:'
lines_to_keyword ::= (!(eol space* reserved_words_and_symbols) .)*
reserved_words_and_symbols ::= (step_keyword keyword_space) | scenario_keyword | scenario_outline_keyword | table | tag | comment_line
line_to_eol ::= (!eol .)*
space ::= ' ' | '\t'
eol ::= '\r'? '\n'
white ::= (space | eol)*
keyword_space ::= ' '
 

Not much, but it’s a start. One suggestion has been to specify Gherkin in the LBNF format used by bnfc and defined in great detail here [PDF]. This would allow others to easily create parser generators in any of the languages bnfc supports.

Clone this wiki locally