Sha256: 2ac1105a16f8a7cf8479251200fbb7046e74e78398e85410397784183c5239d0

Contents?: true

Size: 884 Bytes

Versions: 4

Compression:

Stored size: 884 Bytes

Contents

# frozen_string_literal: true

require 'gherkin/token_scanner'
require 'gherkin/token_matcher'
require 'gherkin/parser'
require 'gherkin/dialect'

module Cucumber
  module Gherkin
    class StepsParser
      def initialize(builder, language)
        @builder = builder
        @language = language
      end

      def parse(text)
        dialect = ::Gherkin::Dialect.for(@language)
        token_matcher = ::Gherkin::TokenMatcher.new(@language)
        token_scanner = ::Gherkin::TokenScanner.new(feature_header(dialect) + text)
        parser = ::Gherkin::Parser.new
        gherkin_document = parser.parse(token_scanner, token_matcher)

        @builder.steps(gherkin_document[:feature][:children][0][:steps])
      end

      def feature_header(dialect)
        %(#{dialect.feature_keywords[0]}:
            #{dialect.scenario_keywords[0]}:
         )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
cucumber-3.2.0 lib/cucumber/gherkin/steps_parser.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/cucumber-3.1.2/lib/cucumber/gherkin/steps_parser.rb
cucumber-3.1.2 lib/cucumber/gherkin/steps_parser.rb
cucumber-3.1.1 lib/cucumber/gherkin/steps_parser.rb