Skip to content

Instantly share code, notes, and snippets.

@josephwilk
Created December 28, 2008 20:53
Show Gist options
  • Save josephwilk/41042 to your computer and use it in GitHub Desktop.
Save josephwilk/41042 to your computer and use it in GitHub Desktop.
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
Copy link

gaffo commented Apr 7, 2010

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

@josephwilk
Copy link
Author

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