require'cucumber/ast'require'gherkin/rubify'require'cucumber/ast/multiline_argument'moduleCucumbermoduleParser# This class conforms to the Gherkin event API and builds the# "legacy" AST. It will be replaced later when we have a new "clean"# AST.classGherkinBuilderincludeGherkin::Rubifydefast@feature||@multiline_argenddeffeature(feature)@feature=Ast::Feature.new(nil,Ast::Comment.new(feature.comments.map{|comment|comment.value}.join("\n")),Ast::Tags.new(nil,feature.tags.map{|tag|tag.name}),feature.keyword,feature.name.lstrip,feature.description.rstrip,[])@feature.gherkin_statement(feature)@featureenddefbackground(background)@background=Ast::Background.new(Ast::Comment.new(background.comments.map{|comment|comment.value}.join("\n")),background.line,background.keyword,background.name,background.description,steps=[])@feature.background=@background@background.feature=@feature@step_container=@background@background.gherkin_statement(background)enddefscenario(statement)scenario=Ast::Scenario.new(@background,Ast::Comment.new(statement.comments.map{|comment|comment.value}.join("\n")),Ast::Tags.new(nil,statement.tags.map{|tag|tag.name}),statement.line,statement.keyword,statement.name,statement.description,steps=[])@feature.add_feature_element(scenario)@background.feature_elements<<scenarioif@background@step_container=scenarioscenario.gherkin_statement(statement)enddefscenario_outline(statement)scenario_outline=Ast::ScenarioOutline.new(@background,Ast::Comment.new(statement.comments.map{|comment|comment.value}.join("\n")),Ast::Tags.new(nil,statement.tags.map{|tag|tag.name}),statement.line,statement.keyword,statement.name,statement.description,steps=[],example_sections=[])@feature.add_feature_element(scenario_outline)if@background@background=@background.dup@background.feature_elements<<scenario_outlineend@step_container=scenario_outlinescenario_outline.gherkin_statement(statement)enddefexamples(examples)examples_fields=[Ast::Comment.new(examples.comments.map{|comment|comment.value}.join("\n")),examples.line,examples.keyword,examples.name,examples.description,matrix(examples.rows)]@step_container.add_examples(examples_fields,examples)enddefstep(gherkin_step)step=Ast::Step.new(gherkin_step.line,gherkin_step.keyword,gherkin_step.name,Ast::MultilineArgument.from(gherkin_step.doc_string||gherkin_step.rows))step.gherkin_statement(gherkin_step)@step_container.add_step(step)enddefeofenddefsyntax_error(state,event,legal_events,line)# raise "SYNTAX ERROR"endprivatedefmatrix(gherkin_table)gherkin_table.mapdo|gherkin_row|row=gherkin_row.cellsclass<<rowattr_accessor:lineendrow.line=gherkin_row.linerowendendendendend