Class: GetText::RubyLexX::StringExtractor

Inherits:
Ripper::Filter
  • Object
show all
Defined in:
lib/gettext/tools/parser/ruby.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ StringExtractor

Returns a new instance of StringExtractor.



24
25
26
27
# File 'lib/gettext/tools/parser/ruby.rb', line 24

def initialize(*args)
  super
  @string_mark_stack = []
end

Instance Method Details

#on_default(event, token, output) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gettext/tools/parser/ruby.rb', line 29

def on_default(event, token, output)
  case event
  when :on_tstring_content
    if @string_mark_stack.last == "\""
      output << token.gsub(/\\./) do |data|
        case data
        when "\\n"
          "\n"
        when "\\t"
          "\t"
        when "\\\\"
          "\\"
        when "\\\""
          "\""
        when "\\\#"
          "#"
        else
          data
        end
      end
    else
      output << token.gsub(/\\./) do |data|
        case data
        when "\\\\"
          "\\"
        when "\\'"
          "'"
        else
          data
        end
      end
    end
  when :on_tstring_beg
    unless @string_mark_stack.empty?
      output << token
    end
    @string_mark_stack << token
  when :on_tstring_end
    @string_mark_stack.pop
    unless @string_mark_stack.empty?
      output << token
    end
  else
    unless @string_mark_stack.empty?
      output << token.to_s
    end
  end
  output
end