Browse files

Let's start with the rex/rexical duo

  • Loading branch information...
1 parent 2d5a853 commit 5a5aee4d5674130a72d2dd8605e40ad18d890ee0 @txus txus committed Nov 29, 2011
View
20 Rakefile
@@ -8,4 +8,22 @@ Rake::TestTask.new do |t|
t.test_files = FileList['./test/**/*_test.rb']
end
-task :default => [:test]
+desc "Regenerate Gherkin-ruby lexer and parser."
+task :regenerate do
+ has_rex = `which rex`
+ has_racc = `which racc`
+
+ if has_rex && has_racc
+ `rex lib/gherkin/parser/gherkin.rex -o lib/gherkin/parser/lexer.rb`
+ `racc lib/gherkin/parser/gherkin.y -o lib/gherkin/parser/parser.rb`
+ else
+ puts "You need both Rexical and Racc to do that. Install them by doing:"
+ puts
+ puts "\t\tgem install rexical"
+ puts "\t\tgem install racc"
+ puts
+ puts "Or just type `bundle install`."
+ end
+end
+
+task :default => [:regenerate, :test]
View
3 gherkin-ruby.gemspec
@@ -13,7 +13,8 @@ Gem::Specification.new do |s|
s.rubyforge_project = "gherkin-ruby"
- s.add_runtime_dependency 'parslet'
+ s.add_development_dependency 'rexical'
+ s.add_development_dependency 'racc'
s.add_development_dependency 'minitest'
s.files = `git ls-files`.split("\n")
View
88 lib/gherkin/parser.rb
@@ -1,43 +1,45 @@
-require 'parslet'
-
-module Gherkin
- class Parser < Parslet::Parser
- def indent(num=2)
- str(' ' * num)
- end
-
- rule(:space) { match('\s').repeat }
- rule(:space?) { space.maybe }
- rule(:newline) { match('\n').repeat }
- rule(:text) { match('[^\n]').repeat }
- rule(:identifier) { match('\w').repeat }
-
- rule(:feature_line) { str('Feature:') >> space? >> text.as(:name) }
- rule(:scenario_line) { indent(2) >> str('Scenario:') >> space? >> text.as(:name) }
-
- rule(:step_keyword) { str('Given') | str('When') | str('Then') | str('And') | str('But') }
-
- rule(:comment) { str('#') >> text.as(:comment) }
-
- rule(:description_text) { (str('Background:') | str('Scenario:') | str('@')).absent? >> text }
- rule(:description) { (indent(2) >> description_text >> newline).repeat }
-
- rule(:background_line) { indent(2) >> str('Background:') }
-
- rule(:step) { indent(4) >> step_keyword.as(:keyword) >> space? >> text.as(:name) }
- rule(:steps) { (step.as(:step) >> newline.maybe).repeat }
-
- rule(:tags) { indent(2) >> (str('@') >> identifier.as(:tag) >> str(' ').maybe).repeat(1) }
-
- rule(:scenario) { (tags.as(:tags) >> newline).maybe >> scenario_line >> newline >> steps.as(:steps) }
- rule(:scenarios) { (scenario.as(:scenario) >> newline.maybe).repeat }
-
- rule(:background) { background_line >> newline >> steps.as(:steps) }
-
- rule(:feature) { feature_line >> newline >> description >> background.as(:background).maybe >> scenarios.as(:scenarios) }
-
- rule(:main) { feature.as(:feature) }
-
- root :main
- end
-end
+# require 'parslet'
+require_relative 'parser/lexer'
+require_relative 'parser/parser'
+
+# module Gherkin
+# class Parser < Parslet::Parser
+# def indent(num=2)
+# str(' ' * num)
+# end
+#
+# rule(:space) { match('\\s').repeat }
+# rule(:space?) { space.maybe }
+# rule(:newline) { match('\\n').repeat }
+# rule(:text) { match('[^\\n]').repeat }
+# rule(:identifier) { match('\\w').repeat }
+#
+# rule(:feature_line) { str('Feature:') >> space? >> text.as(:name) }
+# rule(:scenario_line) { indent(2) >> str('Scenario:') >> space? >> text.as(:name) }
+#
+# rule(:step_keyword) { str('Given') | str('When') | str('Then') | str('And') | str('But') }
+#
+# rule(:comment) { str('#') >> text.as(:comment) }
+#
+# rule(:description_text) { (str('Background:') | str('Scenario:') | str('@')).absent? >> text }
+# rule(:description) { (indent(2) >> description_text >> newline).repeat }
+#
+# rule(:background_line) { indent(2) >> str('Background:') }
+#
+# rule(:step) { indent(4) >> step_keyword.as(:keyword) >> space? >> text.as(:name) }
+# rule(:steps) { (step.as(:step) >> newline.maybe).repeat }
+#
+# rule(:tags) { indent(2) >> (str('@') >> identifier.as(:tag) >> str(' ').maybe).repeat(1) }
+#
+# rule(:scenario) { (tags.as(:tags) >> newline).maybe >> scenario_line >> newline >> steps.as(:steps) }
+# rule(:scenarios) { (scenario.as(:scenario) >> newline.maybe).repeat }
+#
+# rule(:background) { background_line >> newline >> steps.as(:steps) }
+#
+# rule(:feature) { feature_line >> newline >> description >> background.as(:background).maybe >> scenarios.as(:scenarios) }
+#
+# rule(:main) { feature.as(:feature) }
+#
+# root :main
+# end
+# end
View
0 lib/gherkin/parser/gherkin.rex
No changes.
View
0 lib/gherkin/parser/gherkin.y
No changes.

0 comments on commit 5a5aee4

Please sign in to comment.