Class: GetText::RubyLexX

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

Overview

:nodoc: all

Instance Method Summary collapse

Instance Method Details

#identify_commentObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gettext/tools/parser/ruby.rb', line 67

def identify_comment
  @ltype = "#"
  get_readed # skip the hash sign itself

  while ch = getc
    if ch == "\n"
      @ltype = nil
      ungetc
      break
    end
  end
  return Token(TkCOMMENT_WITH_CONTENT, get_readed)
end

#parseObject

Parser#parse resemlbes RubyLex#lex



22
23
24
25
26
27
28
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
# File 'lib/gettext/tools/parser/ruby.rb', line 22

def parse
  until (  (tk = token).kind_of?(RubyToken::TkEND_OF_SCRIPT) && !@continue or tk.nil?  )
    s = get_readed
    if RubyToken::TkSTRING === tk or RubyToken::TkDSTRING === tk
      def tk.value
        @value
      end

      def tk.value=(s)
        @value = s
      end

      if @here_header
        s = s.sub(/\A.*?\n/, "").sub(/^.*\n\Z/, "")
      else
        begin
          s = eval(s)
        rescue Exception
          # Do nothing.
        end
      end

      tk.value = s
    end

    if $DEBUG
      if tk.is_a? TkSTRING or tk.is_a? TkDSTRING
        $stderr.puts("#{tk}: #{tk.value}")
      elsif tk.is_a? TkIDENTIFIER
        $stderr.puts("#{tk}: #{tk.name}")
      else
        $stderr.puts(tk)
      end
    end

    yield tk
  end
  return nil
end