Sha256: e24422b9758af67887611316d1903df5edd95bd84b0b53b6dd375bca1e9995e7

Contents?: true

Size: 1.83 KB

Versions: 11

Compression:

Stored size: 1.83 KB

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Formatters
    module Rbnf

      class RuleParser < TwitterCldr::Parsers::Parser

        private

        def do_parse(options)
          switch([])
        end

        def switch(list)
          send(current_token.type, list)
        end

        def equals(list)
          contents = descriptor(current_token)
          list << Substitution.new(:equals, contents, 2)
          next_token(:equals)
          switch(list)
        end

        def left_arrow(list)
          contents = descriptor(current_token)
          list << Substitution.new(:left_arrow, contents, 2)
          next_token(:left_arrow)
          switch(list)
        end

        def right_arrow(list)
          contents = descriptor(current_token)
          sub = Substitution.new(:right_arrow, contents, 2)
          next_token(:right_arrow)

          # handle >>> case
          if current_token.type == :right_arrow
            sub.length += 1
            next_token(:right_arrow)
          end

          list << sub
          switch(list)
        end

        def plaintext(list)
          add_and_advance(list)
        end

        def open_bracket(list)
          add_and_advance(list)
        end

        def close_bracket(list)
          add_and_advance(list)
        end

        def semicolon(list)
          list
        end

        def add_and_advance(list)
          list << current_token
          next_token(current_token.type)
          switch(list)
        end

        def descriptor(token)
          next_token(token.type)
          contents = []
          until current_token.type == token.type
            contents << current_token
            next_token(current_token.type)
          end
          contents
        end

      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
twitter_cldr-3.0.10 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.9 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.8 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.7 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.6 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.5 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.4 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.3 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.2 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.1 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb
twitter_cldr-3.0.0 lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb