Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cucumber ANTLR grammar
grammar Gherkin;
//options {
// language=Ruby;
//}
feature : NEWLINE* comment? NEWLINE* SPACE* tags? NEWLINE* SPACE* feature_keyword SPACE* line_to_eol NEWLINE+ (feature_elements .)* feature_elements ;
fragment
feature_elements
: (scenario_outline | scenario)* ;
scenario
: comment? tags? scenario_keyword SPACE* line_to_eol NEWLINE+ steps ;
scenario_outline
: comment? tags? scenario_outline_keyword SPACE* line_to_eol NEWLINE+ steps examples_sections ;
steps : step* ;
step : step_keyword SPACE* line_to_eol NEWLINE+ multiline_arg? ;
examples_sections
: examples+ ;
examples
: examples_keyword SPACE* line_to_eol NEWLINE+ table ;
multiline_arg
: table ;
table : table_row+ ;
table_row
: SPACE* '|' (cell '|')+ SPACE* (NEWLINE+) ;
cell : (~('|' | NEWLINE) .)* ;
tags : tag (SPACE tag)* NEWLINE+ ;
tag : '@' tag_name=ID ;
comment
: (comment_line NEWLINE)* ;
comment_line
: '#' line_to_eol;
line_to_eol
: (~NEWLINE)* ;
feature_keyword
: 'Feature' ':'? ;
scenario_keyword
: 'Scenario' ':'? ;
scenario_outline_keyword
: 'Scenario Outline' ':'? ;
step_keyword
: 'Given' | 'When' | 'Then' | 'And' | 'But' ;
examples_keyword
: 'Examples' ':'? ;
ID : ('a'..'z'|'A'..'Z'|'_')+ ;
NEWLINE : (('\r')? '\n' )+ ;
SPACE : (' '|'\t')+ {skip();};
@gaffo

This comment has been minimized.

Copy link

gaffo commented Apr 7, 2010

@josephwilk what version of antlr was this for? Did it ever work?

@josephwilk

This comment has been minimized.

Copy link
Owner Author

josephwilk commented Apr 7, 2010

I had trouble with the Ruby bindings so I was never quite sure it worked. It was a spike to test the ground for moving away from treetop.
We ended up going with Ragel instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.