def parse_source(source)
po = []
file = StringIO.new(source)
rl = RubyLexX.new
rl.set_input(file)
rl.skip_space = true
po_entry = nil
line_no = nil
last_comment = ""
reset_comment = false
ignore_next_comma = false
rl.parse do |tk|
begin
ignore_current_comma = ignore_next_comma
ignore_next_comma = false
case tk
when RubyToken::TkIDENTIFIER, RubyToken::TkCONSTANT
if store_po_entry(po, po_entry, line_no, last_comment)
last_comment = ""
end
if ID.include?(tk.name)
po_entry = POEntry.new(:normal)
elsif PLURAL_ID.include?(tk.name)
po_entry = POEntry.new(:plural)
elsif MSGCTXT_ID.include?(tk.name)
po_entry = POEntry.new(:msgctxt)
elsif MSGCTXT_PLURAL_ID.include?(tk.name)
po_entry = POEntry.new(:msgctxt_plural)
else
po_entry = nil
end
line_no = tk.line_no.to_s
when RubyToken::TkBITOR
po_entry = nil
when RubyToken::TkSTRING, RubyToken::TkDSTRING
po_entry.set_current_attribute tk.value if po_entry
when RubyToken::TkPLUS, RubyToken::TkNL
when RubyToken::TkINTEGER
ignore_next_comma = true
when RubyToken::TkCOMMA
unless ignore_current_comma
po_entry.advance_to_next_attribute if po_entry
end
else
if store_po_entry(po, po_entry, line_no, last_comment)
po_entry = nil
last_comment = ""
end
end
rescue
$stderr.print "\n\nError"
$stderr.print " parsing #{@path}:#{tk.line_no}\n\t #{source.lines.to_a[tk.line_no - 1]}" if tk
$stderr.print "\n #{$!.inspect} in\n"
$stderr.print $!.backtrace.join("\n")
$stderr.print "\n"
exit 1
end
case tk
when RubyToken::TkCOMMENT_WITH_CONTENT
last_comment = "" if reset_comment
if last_comment.empty?
comment1 = tk.value.lstrip
if comment_to_be_extracted?(comment1)
last_comment += comment1
end
else
last_comment += "\n"
last_comment += tk.value
end
reset_comment = false
when RubyToken::TkNL
else
reset_comment = true
end
end
po
end