Strscan ruby 1.8 why this doesn't work ?

  • Thread starter Domingo Alvarez Duarte
  • Start date
D

Domingo Alvarez Duarte

I have been using strscan till version 0.65 and it was working with a
code like this but now trying to upgrade to ruby 1.8 it doesn't, is
there a bug in strscan or I misunderstood it ?

I expect to find a match for the regular expression but it doesn't.


#---- code start here
require 'strscan'

SSI_search_re = /<!--#(.+?)#-->|\[\)(.+?)\(\]/m

def parse(html)
ret_var = ''
ssc = StringScanner.new(html)
ret_var << "\n0print(' xxx start scanner zzz ')\n"
while ssc.scan(SSI_search_re) do
ret_var << "\n1print([}#{ssc.pre_match}{])\n"
if ssc[1]
ret_var << ' :: ' + ssc[1]
else
ret_var << "\n2print(#{ssc[2]})\n"
end
end
ret_var << "\n3print([}#{ssc.rest}{])\n"
ret_var << "\n4print(' vvv end scanner kkk ')\n"
end

res = parse('<html><!--# . vvvvcartasvvvv . #--><body>Hello
[)Domingo(] !</body></html>')
puts res
#---- code end here
 
D

Domingo Alvarez Duarte

Hi,

At Tue, 19 Aug 2003 20:03:28 +0900,
Domingo said:
I have been using strscan till version 0.65 and it was working with a
code like this but now trying to upgrade to ruby 1.8 it doesn't, is
there a bug in strscan or I misunderstood it ?

StringScanner has the "cursor" internally, and always tries
matching at the position. In other words, it never skip
unmatched portion.
SSI_search_re = /<!--#(.+?)#-->|\[\)(.+?)\(\]/m
res = parse('<html><!--# . vvvvcartasvvvv . #--><body>Hello
[)Domingo(] !</body></html>')

This string doesn't start with the part matches to the RE.

SSI_search_re = /.*?(?:<!--#(.+?)#-->|\[\)(.+?)\(\])/m

may works but I'm not sure if it is what you really want.


No it's not that, I think it should try match the whole string and not
only if it starts with the regular expression and as I told and you
can try it works with strscan version 6.5 but not with 6.7 as well, I
couldn't find any documentation that try explain how it should work in
ruby 1.8.
 
M

Minero Aoki

Hi,

In mail "Strscan ruby 1.8 why this doesn't work ?"
I have been using strscan till version 0.65 and it was working with a
code like this but now trying to upgrade to ruby 1.8 it doesn't, is
there a bug in strscan or I misunderstood it ?

Did you use Ruby version of StringScanner? Try

$ ruby -rstrscan -e 'p StringScanner'

with 0.6.5. If it prints "StringScanner_R", it is Ruby version.
otherwise ("StringScanner_C") it is C version.

Ruby version and C version is completely *different*,
and C version is bundled with ruby 1.8.

I expect to find a match for the regular expression but it doesn't.


#---- code start here
require 'strscan'

SSI_search_re = /<!--#(.+?)#-->|\[\)(.+?)\(\]/m

def parse(html)
ret_var = ''
ssc = StringScanner.new(html)
ret_var << "\n0print(' xxx start scanner zzz ')\n"
while ssc.scan(SSI_search_re) do

while ssc.scan_until(SSI_search_re) do

might help.


Regards,
Minero Aoki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top