20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/kwartz/binding/php.rb', line 20
def parse_expr_str(expr_str, linenum)
case expr_str
when /\A(\w+)\z/ expr = '$' + $1
when /\A(\w+)\.(\w+)\z/ expr = "$#{$1}->#{$2}"
when /\A(\w+)\[('.*?'|".*?"|:\w+)\]\z/ key = $2[0] == ?: ? "'#{$2[1..-1]}'" : $2
expr = "$#{$1}[#{key}]"
when /\A(\w+)\[(\w+)\]\z/ begin
expr = "$#{$1}[#{Integer($2)}]"
rescue
expr = "$#{$1}[$#{$2}]"
end
else
raise convert_error("'#{expr_str}': invalid expression.", linenum)
end
return expr
end
|