/usr/lib/ruby/1.9.1/gettext/parser/ruby.rb is in libgettext-ruby1.9.1 2.1.0-2.1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | #!/usr/bin/ruby
=begin
parser/ruby.rb - parser for ruby script
Copyright (C) 2003-2005 Masao Mutoh
Copyright (C) 2005 speakillof
Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
You may redistribute it and/or modify it under the same
license terms as Ruby.
=end
require 'irb/ruby-lex.rb'
require 'stringio'
warn "DEPRECATED: Use 'gettext/tools/parser/ruby' instead."
class RubyLexX < RubyLex # :nodoc: all
# Parser#parse resemlbes RubyLex#lex
def parse
until ( (tk = token).kind_of?(RubyToken::TkEND_OF_SCRIPT) && !@continue or tk.nil? )
s = get_readed
if RubyToken::TkSTRING === 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
$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
end
module GetText
module RubyParser
extend self
unless defined? ID
ID = ['gettext', '_', 'N_', 'sgettext', 's_']
PLURAL_ID = ['ngettext', 'n_', 'Nn_', 'ns_', 'nsgettext']
MSGCTXT_ID = ['pgettext', 'p_']
MSGCTXT_PLURAL_ID = ['npgettext', 'np_']
end
def parse(file, targets = []) # :nodoc:
lines = IO.readlines(file)
parse_lines(file, lines, targets)
end
def parse_lines(file_name, lines, targets) # :nodoc:
file = StringIO.new(lines.join + "\n")
rl = RubyLexX.new
rl.set_input(file)
rl.skip_space = true
#rl.readed_auto_clean_up = true
target = nil
msgid = nil
line_no = nil
rl.parse do |tk|
begin
case tk
when RubyToken::TkIDENTIFIER, RubyToken::TkCONSTANT
if ID.include?(tk.name)
target = :normal
elsif PLURAL_ID.include?(tk.name)
target = :plural
elsif MSGCTXT_ID.include?(tk.name)
target = :msgctxt
elsif MSGCTXT_PLURAL_ID.include?(tk.name)
target = :msgctxt_plural
else
target = nil
end
line_no = tk.line_no.to_s
when RubyToken::TkSTRING
if target
if msgid
msgid += tk.value
else
msgid = tk.value
end
end
when RubyToken::TkPLUS, RubyToken::TkNL
#do nothing
when RubyToken::TkCOMMA
if msgid
case target
when :plural
msgid += "\000"
target = :normal
when :msgctxt
msgid += "\004"
target = :normal
when :msgctxt_plural
msgid += "\004"
target = :plural
else
target = :normal
end
end
else
if msgid
key_existed = targets.assoc(msgid.gsub(/\n/, '\n'))
if key_existed
targets[targets.index(key_existed)] = key_existed <<
file_name + ":" + line_no
else
targets << [msgid.gsub(/\n/, '\n'), file_name + ":" + line_no]
end
msgid = nil
target = nil
end
end
targets
rescue
$stderr.print "\n\nError: #{$!.inspect} "
$stderr.print " in #{file_name}:#{tk.line_no}\n\t #{lines[tk.line_no - 1]}" if tk
$stderr.print "\n"
exit 1
end
end
targets
end
def target?(file) # :nodoc:
true # always true, as default parser.
end
end
end
if __FILE__ == $0
require 'pp'
ARGV.each do |file|
pp GetText::RubyParser.parse(file)
end
#rl = RubyLexX.new; rl.set_input(ARGF)
#rl.parse do |tk|
#p tk
#end
end
|