Sha256: f9025af6daea02251aca9449973c8fdf44076f8d4316e810a2491a0ba31ac466

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

#encoding: utf-8
require 'gherkin/i18n'
require 'gherkin/native'

module Gherkin
  module Lexer
    LexingError = Class.new(StandardError)

    # The main entry point to lexing Gherkin source.
    class I18nLexer
      native_impl('gherkin')

      COMMENT_OR_EMPTY_LINE_PATTERN = /^(\xEF\xBB\xBF)?\s*#|^\s*$/
      LANGUAGE_PATTERN = /^(\xEF\xBB\xBF)?\s*#\s*language\s*:\s*([a-zA-Z\-]+)/ #:nodoc:
      attr_reader :i18n_language

      def initialize(listener, force_ruby=false)
        @listener = listener
        @force_ruby = force_ruby
      end

      def scan(source)
        create_delegate(source).scan(source)
      end

    private

      def create_delegate(source)
        @i18n_language = lang(source)
        @i18n_language.lexer(@listener, @force_ruby)
      end

      def lang(source)
        key = 'en'
        source.each_line do |line|
          break unless COMMENT_OR_EMPTY_LINE_PATTERN =~ line
          if LANGUAGE_PATTERN =~ line
            key = $2
            break
          end
        end
        I18n.get(key)
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/gherkin-2.11.6/lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.7 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.7-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.7-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.7-java lib/gherkin/lexer/i18n_lexer.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/gherkin-2.11.6/lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.6 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.6-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.6-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.6-java lib/gherkin/lexer/i18n_lexer.rb