Sha256: 7a6454ada9456578e7ee5fa5ca4684c826b74f03fce4f7acdc4cf588c0adbc36

Contents?: true

Size: 1.1 KB

Versions: 19

Compression:

Stored size: 1.1 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, iso_code='en')
        @listener = listener
        @force_ruby = force_ruby
        @iso_code = iso_code
      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 = @iso_code
        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

19 entries across 17 versions & 2 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/gherkin-2.12.2/lib/gherkin/lexer/i18n_lexer.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/gherkin-2.12.2/lib/gherkin/lexer/i18n_lexer.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/gherkin-2.12.2/lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.2 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.2-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.2-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.2-java lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.1 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.1-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.1-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.1-java lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.0 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.0-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.0-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.12.0-java lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.8 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.8-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.8-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.8-java lib/gherkin/lexer/i18n_lexer.rb