Class: Kwartz::PerlTranslator
- Inherits:
-
BaseTranslator
- Object
- Translator
- BaseTranslator
- Kwartz::PerlTranslator
- Includes:
- PerlExpressionParser
- Defined in:
- lib/kwartz/binding/perl.rb
Overview
translator for Perl
Instance Attribute Summary
Attributes inherited from BaseTranslator
Instance Method Summary collapse
-
#initialize(properties = {}) ⇒ PerlTranslator
constructor
A new instance of PerlTranslator.
- #translate(stmt_list) ⇒ Object
- #translate_string(str) ⇒ Object
Methods included from PerlExpressionParser
#parse_expr_str, #parse_expr_str!
Methods inherited from BaseTranslator
#translate_native_expr, #translate_native_stmt, #translate_print_stmt
Methods inherited from Translator
get_class, register_class, #translate_native_expr, #translate_native_stmt, #translate_print_stmt
Constructor Details
#initialize(properties = {}) ⇒ PerlTranslator
Returns a new instance of PerlTranslator.
195 196 197 198 199 200 201 |
# File 'lib/kwartz/binding/perl.rb', line 195 def initialize(properties={}) escapefunc = properties[:escapefunc] || 'encode_entities' marks = ['', '', 'push(@_buf, ', '); ', "push(@_buf, #{escapefunc}(", ')); '] super(marks, properties) @header = 'my @_buf = (); ' unless @header == false @footer = "join('', @_buf);" + @nl unless @footer == false end |
Instance Method Details
#translate(stmt_list) ⇒ Object
219 220 221 222 |
# File 'lib/kwartz/binding/perl.rb', line 219 def translate(stmt_list) stmt_list2 = optimize_print_stmts(stmt_list) return super(stmt_list2) end |
#translate_string(str) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/kwartz/binding/perl.rb', line 204 def translate_string(str) return if str.nil? || str.empty? #str.gsub!(/['\\]/, '\\\\\&') #@sb << "_buf << '#{str}'; " str.gsub!(/[`\\]/, '\\\\\&') @sb << "push(@_buf, q`#{str}`); " #if str[-1] == ?\n # str.chomp! # @sb << "push(@_buf, q`#{str}`, #{@nl.inspect});" << @nl #else # @sb << "push(@_buf, q`#{str}`); " #end end |