Sha256: 966b99b91c64f04c88891294edd6c544ea23023e9a9d662362dcd11191a2650b

Contents?: true

Size: 1.6 KB

Versions: 19

Compression:

Stored size: 1.6 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Tokenizers
    class UnicodeRegexTokenizer

      extend Forwardable
      def_delegator :tokenizer, :insert_before

      def tokenize(pattern)
        tokenizer.tokenize(pattern)
      end

      private

      def tokenizer
        @tokenizer ||= begin
          recognizers = [
            # The variable name can contain letters and digits, but must start with a letter.
            TokenRecognizer.new(:variable, /\$\w[\w\d]*/),
            TokenRecognizer.new(:character_set, /\[:\w+:\]|\\p\{[\w=]+\}/),  # [:Lu:] or \p{Lu} or \p{Sentence_Break=CF}
            TokenRecognizer.new(:negated_character_set, /\[:\^\w+:\]|\\P\{[\w=]+\}/),  #[:^Lu:] or \P{Lu}
            TokenRecognizer.new(:unicode_char, /\\u\{?[a-fA-F0-9]{1,6}\}?/),
            TokenRecognizer.new(:multichar_string, /\{\w+\}/u),

            TokenRecognizer.new(:escaped_character, /\\./),
            TokenRecognizer.new(:negate, /\^/),
            TokenRecognizer.new(:ampersand, /&/),
            TokenRecognizer.new(:pipe, /\|/),
            TokenRecognizer.new(:dash, /-/),

            # stuff that shouldn't be converted to codepoints
            TokenRecognizer.new(:special_char, /\{\d,?\d?\}|[$?:{}()*+\.,\/\\]/),

            TokenRecognizer.new(:open_bracket, /\[/),
            TokenRecognizer.new(:close_bracket, /\]/),

            TokenRecognizer.new(:string, //) do |val|
              val == " " ? val : val.strip
            end
          ]

          Tokenizer.new(recognizers)
        end
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.2.1 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.2.0 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.1.2 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.1.1 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.1.0 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.10 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.9 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.8 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.7 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.6 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.5 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.4 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.3 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.2 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.1 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb
twitter_cldr-3.0.0 lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb