Sha256: ae6c751a274c804518cbcbebcc26faf332838e9dc46e517b88ea0b585b7c8419

Contents?: true

Size: 1 KB

Versions: 69

Compression:

Stored size: 1 KB

Contents

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 = /^\s*#|^\s*$/
      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)
        key = 'en'
        source.each_line do |line|
          break unless COMMENT_OR_EMPTY_LINE_PATTERN =~ line
          if LANGUAGE_PATTERN =~ line
            key = $1
            break
          end
        end
        I18n.get(key)
      end

    end
  end
end

Version data entries

69 entries across 66 versions & 8 rubygems

Version Path
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/gherkin-2.11.1/lib/gherkin/lexer/i18n_lexer.rb
candlepin-api-0.4.0 bundle/ruby/gems/gherkin-2.11.1/lib/gherkin/lexer/i18n_lexer.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/gherkin-2.11.1/lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.5 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.5-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.5-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.5-java lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.4 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.4-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.4-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.4-java lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.3 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.3-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.3-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.3-java lib/gherkin/lexer/i18n_lexer.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/gherkin-2.11.1/lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.2 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.2-x86-mswin32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.2-x86-mingw32 lib/gherkin/lexer/i18n_lexer.rb
gherkin-2.11.2-java lib/gherkin/lexer/i18n_lexer.rb