Skip to content

Commit

Permalink
Parse locale
Browse files Browse the repository at this point in the history
  • Loading branch information
josepjaume committed May 18, 2012
1 parent 7ba6d4b commit 820a724
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 129 deletions.
4 changes: 4 additions & 0 deletions lib/gherkin/ast.rb
Expand Up @@ -83,5 +83,9 @@ def initialize(name)
@name = name
end
end

class Locale < Node
attr_reader :name, :keyword
end
end
end
1 change: 1 addition & 0 deletions lib/gherkin/parser/gherkin.rex
Expand Up @@ -6,6 +6,7 @@ macro
BLANK [\ \t]+

rule
\#\s?locale: { [:LOCALE, text[0..-2]] }
# Whitespace
{BLANK} # no action
\#.*$
Expand Down
10 changes: 10 additions & 0 deletions lib/gherkin/parser/gherkin.y
Expand Up @@ -4,6 +4,7 @@ class Gherkin::Parser

# Declare tokens produced by the lexer
token NEWLINE
token LOCALE
token FEATURE BACKGROUND SCENARIO
token TAG
token GIVEN WHEN THEN AND BUT
Expand All @@ -12,12 +13,21 @@ token TEXT
rule

Root:
Locale { result = val[0]; }
|
Feature { result = val[0] }
|
Feature { result = val[0]; }
|
Feature
Scenarios { result = val[0]; result.scenarios = val[1] }
;

Locale:
LOCALE TEXT { result = val[1] }
| LOCALE TEXT Newline { result = val[1] }


Newline:
NEWLINE
| Newline NEWLINE
Expand Down
3 changes: 3 additions & 0 deletions lib/gherkin/parser/lexer.rb
Expand Up @@ -59,6 +59,9 @@ def _next_token
token = case @state
when nil
case
when (text = @ss.scan(/\#\s?locale:/))
action { [:LOCALE, text[0..-2]] }

when (text = @ss.scan(/[ \t]+/))
;

Expand Down

0 comments on commit 820a724

Please sign in to comment.