-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Josep M. Bach
committed
Nov 30, 2011
1 parent
e48635c
commit 3d10322
Showing
8 changed files
with
236 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Compile with: racc gherkin.y -o parser.rb | ||
|
||
class Gherkin::Parser | ||
|
||
# Declare tokens produced by the lexer | ||
token NEWLINE | ||
token FEATURE BACKGROUND SCENARIO | ||
token TAG | ||
token GIVEN WHEN THEN AND BUT | ||
token TEXT | ||
|
||
rule | ||
|
||
Root: | ||
Feature { result = val[0] } | ||
; | ||
|
||
Feature: | ||
FEATURE TEXT { result = AST::Feature.new(val[1]) } | ||
| FEATURE TEXT NEWLINE | ||
Description { result = AST::Feature.new(val[1]) } | ||
; | ||
|
||
Description: | ||
TEXT NEWLINE | ||
| Description TEXT NEWLINE | ||
; | ||
|
||
end | ||
|
||
---- header | ||
require_relative "lexer" | ||
require_relative "../ast" | ||
|
||
---- inner | ||
def parse(code, show_tokens=false) | ||
@tokens = Lexer.new.run(code) | ||
p @tokens if show_tokens | ||
do_parse | ||
end | ||
|
||
def next_token | ||
@tokens.shift | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'test_helper' | ||
|
||
module Gherkin | ||
describe Parser do | ||
def parse(input) | ||
parser = Parser.new | ||
parser.parse(input) | ||
end | ||
|
||
it 'parses feature header without description' do | ||
feature = parse( | ||
"Feature: my feature" | ||
) | ||
feature.must_be_kind_of AST::Feature | ||
feature.name.must_equal "my feature" | ||
end | ||
|
||
it 'parses feature header with description' do | ||
feature = parse( | ||
"Feature: my feature\n In order to do something\n As a user\n" | ||
) | ||
feature.must_be_kind_of AST::Feature | ||
feature.name.must_equal "my feature" | ||
end | ||
end | ||
end |