-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathgherkin.rex
More file actions
45 lines (35 loc) · 1.09 KB
/
gherkin.rex
File metadata and controls
45 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Compile with: rex gherkin.rex -o lexer.rb
class GherkinRuby::Parser
macro
BLANK [\ \t]+
rule
# Whitespace
{BLANK} # no action
\#.*$
# Literals
\n { [:NEWLINE, text] }
# Keywords
Feature: { [:FEATURE, text[0..-2]] }
Background: { [:BACKGROUND, text[0..-2]] }
Scenario: { [:SCENARIO, text[0..-2]] }
# Tags
@(\w|-|:)+ { [:TAG, text[1..-1]] }
# Step keywords
Given { [:GIVEN, text] }
When { [:WHEN, text] }
Then { [:THEN, text] }
And { [:AND, text] }
But { [:BUT, text] }
\* { [:STAR, text] }
# Text
[^#\n]* { [:TEXT, text.strip] }
inner
def tokenize(code)
scan_setup(code)
tokens = []
while token = next_token
tokens << token
end
tokens
end
end