Created
March 14, 2023 22:31
-
-
Save thomasjslone/857086bc51d0ce6d33e783c0757e90d9 to your computer and use it in GitHub Desktop.
wanted to build html/script parser, this is the vverymost basic form of the parse loop with no numeric stack value
This file contains hidden or 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 scan_splicer(s,b,e) # i.e.: "<tag>", "</tag>" | |
if s.to_s == "" or b.to_s == "" or e.to_s == ""; raise "Invalid arguements passed."; end | |
if s.length<=(b.to_s.length+e.to_s.length); raise "Input string is too small."; end | |
pos=0; stack = false; list=[] | |
if b.length > e.length ; buffer_length = b.length; else; buffer_length = e.length; end | |
buffer = []; buffer_length.times{ buffer << "" } | |
empty_buffer=[]; buffer_length.times{ empty_buffer << "" } | |
empty_buffer2=[]; buffer_length.times{ empty_buffer2 << "" } | |
tag1=empty_buffer; b.split('').each { |ch| empty_buffer << ch ; empty_buffer.delete_at(0) } | |
tag2=empty_buffer2; e.split('').each { |ch| empty_buffer2 << ch ; empty_buffer2.delete_at(0) } | |
loop do | |
if s[pos].to_s==""; break; end | |
buffer << s[pos]; buffer.delete_at(0) | |
if stack; list << s[pos]; end | |
str=buffer.join(''); tag = tag1.join('') | |
m=true; i=0 | |
tag.reverse.split('').each{ |ch| if ch.to_s!=str.reverse[i].to_s and ch.to_s != ""; m=false; break; end; i+=1 } | |
if m == true; stack = true; end | |
tag = tag2.join('') | |
m=true; i=0 | |
tag.reverse.split('').each{ |ch| if ch.to_s!=str.reverse[i].to_s and ch.to_s != ""; m=false; break; end; i+=1 } | |
if m == true; stack = false; end | |
pos+=1 | |
end | |
if list.length == 0; return "" | |
else; return list.join('')[0..("-"+(e.length+1).to_s).to_i] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment