Skip to content

Instantly share code, notes, and snippets.

@zaach
Created January 7, 2010 22:54
Show Gist options
  • Save zaach/271692 to your computer and use it in GitHub Desktop.
Save zaach/271692 to your computer and use it in GitHub Desktop.
%%
spec
: prefix top_description_list EOF
;
prefix
: PREFIX
{print('prefix',yytext);}
|
;
top_description_list
: top_description_list description
| description
;
description
: DESCRIBE string before_block description_list END
;
description_list
: description_list list_item
| list_item
;
before_block
: BEFORE_BLOCK
{print('before',yytext);}
|
;
list_item
: description
| it_block
;
it_block
: it code
;
it
: IT
{print('it',yytext);}
;
string
: STRING
{print('string',yytext.substr(1, yytext.length-2));}
;
code
: CODE
{print('code',yytext);}
;
{
"rules": [
["[^\\v]+?describe\\b", "this.unput('describe');return 'PREFIX';"],
["\\s+", ""],
["describe\\b", "return 'DESCRIBE';"],
["before_each\\b[^\\v]*?end", "return 'BEFORE_BLOCK';"],
["it\\s*'[^']*'", "this.unput('then'); return 'IT';"],
["'[^']*'", "return 'STRING';"],
["then\\b[^\\v]*?end", "return 'CODE';"],
["end\\b", "return 'END';"],
["$", "return 'EOF';"]
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment