class TwitterCldr::Transforms::Transforms::Parser

Private Instance Methods

backward_form() click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 27
def backward_form
  if open_paren?(current_token)
    next_token(:special_char)
    spaces

    frm = if close_paren?(current_token)
      BlankTransform.instance
    else
      form
    end

    spaces
    next_token(:special_char)
    frm
  end
end
close_paren?(token) click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 114
def close_paren?(token)
  token && token.type == :special_char && token.value == ')'
end
consume_until_balanced() click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 93
def consume_until_balanced
  open_brackets = 0
  consumed_tokens = []

  if is_opening?(current_token) || is_closing?(current_token)
    loop do
      open_brackets += 1 if is_opening?(current_token)
      open_brackets -= 1 if is_closing?(current_token)
      consumed_tokens << current_token
      next_token(current_token.type)
      break if open_brackets == 0 || eof?
    end
  end

  consumed_tokens
end
consume_while() click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 82
def consume_while
  consumed_tokens = []

  while !eof? && yield(current_token)
    consumed_tokens << current_token
    next_token(current_token.type)
  end

  consumed_tokens
end
do_parse(options) click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 13
def do_parse(options)
  forward = forward_form
  backward = backward_form
  [forward, backward]
end
filter() click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 54
def filter
  if current_token.type == :character_set
    [current_token].tap do
      next_token(:character_set)
    end
  else
    consume_until_balanced
  end
end
form() click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 44
def form
  filter_tokens = filter
  transform_tokens = transform

  TransformPair.new(
    join_tokens(filter_tokens).strip,
    join_tokens(transform_tokens).strip
  )
end
forward_form() click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 19
def forward_form
  spaces

  unless open_paren?(current_token)
    form
  end
end
is_closing?(token) click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 122
def is_closing?(token)
  token && token.type == :close_bracket || close_paren?(token)
end
is_opening?(token) click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 118
def is_opening?(token)
  token && token.type == :open_bracket || open_paren?(token)
end
join_tokens(tokens) click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 76
def join_tokens(tokens)
  tokens.inject('') do |ret, token|
    ret << token.value
  end
end
open_paren?(token) click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 110
def open_paren?(token)
  token && token.type == :special_char && token.value == '('
end
spaces() click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 70
def spaces
  consume_while do |token|
    token.value =~ /[\s]+/
  end
end
transform() click to toggle source
# File lib/twitter_cldr/transforms/transforms/parser.rb, line 64
def transform
  consume_while do |token|
    token.value =~ /[\w\s\-]/
  end
end