1. re:find_replace_callback() -- example fails

Example 1 in the documentation for find_replace_callback() is not working.

A cut and paste copy of the example produces an error...


include std/regex.e as re 
include std/console.e 
 
function my_convert(sequence params) 
    switch params[1] do 
        case "1" then 
             return "one " 
        case "2" then 
             return "two " 
        case else 
             return "unknown " 
    end switch 
end function 
regex r = re:new(`\d`) 
sequence result = re:find_replace_callback(r, "125", routine_id("my_convert")) 
-- result = "one two unknown " 
 
display( result ) 
 
/* 

bash-3.1# eui demo 
 
demo.ex:5 in function my_convert() 
A machine-level exception occurred during execution of this statement 
 
... called from /root/euphoria/include/std/regex.e:1218 in function find_replace_callback() 
 
... called from demo.ex:15 
 
--> See ex.err 
*/ 
 
new topic     » topic index » view message » categorize

2. Re: re:find_replace_callback() -- example fails

_tom said...

Example 1 in the documentation for find_replace_callback() is not working.

A cut and paste copy of the example produces an error...

it does work translated. it also crashes using previous interpreters back to 3155 and probably beyond.

new topic     » goto parent     » topic index » view message » categorize

3. Re: re:find_replace_callback() -- example fails

ne1uno said...
_tom said...

Example 1 in the documentation for find_replace_callback() is not working.

A cut and paste copy of the example produces an error...

it does work translated. it also crashes using previous interpreters back to 3155 and probably beyond.

I tested with 3023 and still got a crash.

I just tried it with 3414 and eu.ex, and got the error "Unknown opcode" in line 9.

I suspect we have a fencepost error somewhere in the math that deals with switches for sequences. Changing the following function in execute.e fixes eu.ex and allows the demo to run correctly:

procedure opSWITCH() 
-- pc+1: switch value 
-- pc+2: case values 
-- pc+3: jump_table 
-- pc+4: else jump 
        a = find( val[Code[pc+1]], val[Code[pc+2]] ) 
        if a then 
                pc += val[Code[pc+3]][a] 
                if Code[pc] > MAX_OPCODE then 
                        pc -= 1 
                end if 
        else 
                pc = Code[pc + 4] 
        end if 
end procedure 
new topic     » goto parent     » topic index » view message » categorize

4. Re: re:find_replace_callback() -- example fails

jimcbrown said...

I tested with 3023 and still got a crash.

I just tried it with 3414 and eu.ex, and got the error "Unknown opcode" in line 9.

The eu.ex issue sounds like a problem with some opcode not advancing the instruction pointer correctly. I've added ticket:204 for this issue.

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: re:find_replace_callback() -- example fails

mattlewis said...
jimcbrown said...

I tested with 3023 and still got a crash.

I just tried it with 3414 and eu.ex, and got the error "Unknown opcode" in line 9.

The eu.ex issue sounds like a problem with some opcode not advancing the instruction pointer correctly. I've added ticket:204 for this issue.

ticket:204 is now fixed in svn:3425.

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu