Skip to content

Instantly share code, notes, and snippets.

@davidakachaos
Created July 16, 2010 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidakachaos/478422 to your computer and use it in GitHub Desktop.
Save davidakachaos/478422 to your computer and use it in GitHub Desktop.
def prepare_literal_token
str = ""
count = 1
#puts "prepare_literal_token..."
while count > 0 && !@io.eof
#puts "\t count: #{count} str: #{str.inspect}"
#raise "\t\t!!!!!!EOF!!!!!!" if str == '%%EOF'
chr = @io.read(1)
#break if @io.pos == eof_index
#raise "Chr found: #{chr.inspect} && str[-1,1] != \x5C #{str[-1,1] != "\x5C"}" if count > 4
if chr.nil?
count = 0 # unbalanced params
elsif chr == "(" && str[-1,1] != "\x5C"
str << "("
count += 1
elsif chr == ")" && str[-1,1] != "\x5C" #|| str[-2,1] != "\x5C")
count -= 1
str << ")" unless count == 0
elsif chr == ")" && str[-2,2] == "\x5C\x5C"
#DW: If escaped \ then, still do the above...
count -= 1
str << ")" unless count == 0
else
str << chr unless count == 0
end
end
@tokens << str if str.size > 0
@tokens << ")"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment