Module: Metal::Generator

Defined in:
lib/metal/generator.rb

Defined Under Namespace

Classes: Action, AndSet, Expression, Grammar, LiteralAny, LiteralApply, LiteralCharclass, LiteralEnd, LiteralQuotedToken, LiteralSuper, LiteralToken, Meta, OrSet, Precode, PredLookahead, PredNot, Rule, Token, Where

Class Method Summary collapse

Class Method Details

.escape_quoated_string(str) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/metal/generator.rb', line 22

def self.escape_quoated_string(str)
	str = str.gsub("\\", "\\\\\\\\")
	str.gsub!("\"", "\\\\\"")
	str_len = string_length(str)
	str.gsub!("\n", "\\\\n\"\n\"")
	return str, str_len
end

.string_length(str) ⇒ Object



30
31
32
33
# File 'lib/metal/generator.rb', line 30

def self.string_length(str)
	#@str.bytesize  # FIXME Ruby 1.9
	str.size - str.scan(/\\/).length + str.scan(/\\\\/).length;
end