Sha256: e0d43e668b25f354995be56dc4b0927efc61bde79e003d35e9ef115b9a7daff1

Contents?: true

Size: 912 Bytes

Versions: 24

Compression:

Stored size: 912 Bytes

Contents

require 'gherkin/i18n'
require 'gherkin/native'

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

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

      LANGUAGE_PATTERN = /^\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)
        line_one = source.split(/\n/)[0]
        match = LANGUAGE_PATTERN.match(line_one)
        I18n.get(match ? match[1] : 'en')
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
gherkin-2.2.4 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.4-i386-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.4-i386-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.4-universal-dotnet lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.4-java lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.3 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.3-i386-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.3-i386-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.3-universal-dotnet lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.3-java lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.2-i386-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.2-i386-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.2-universal-dotnet lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.2-java lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.1 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.1-i386-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.1-i386-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.1-universal-dotnet lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.1-java lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.2.0 lib/gherkin/lexer/i18n_lexer.rb