Created
July 16, 2010 14:19
-
-
Save davidakachaos/478422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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