Re: Phix 0.8.1 uploaded

new topic     » goto parent     » topic index » view thread      » older message » newer message

regex

  • off-by-one indexing does not make any sense
  • a start argument makes the regex() much more useful

The hacked regex.e file is too big for the pastey.

My hacks look like

-- builtins\regex.e 
-- ================ 
-- 
-- Routines for handling regular expressions. 
-- 
 
--//tom 
--// around line 160 
-- // provide a start argument 
--// allows easy multiple regex matches 
 
--//original    integer sp = 1 
    integer sp = strtndx 
 
 
--// add a start parameter 
 
global function regex(sequence re, string s, integer strtndx = 1) 
-- 
-- returns {} if no match could be found, otherwise an even-length sequence 
-- of capture indexes, eg regex(`(a)(b)`,"ab") yields {1,3,1,2,2,3}. 
 
--\\tom 
--\\ this must not be.. 
 
-- Note 
-- that the goup start is the correct index for the first character but the 
-- end is always <idx of last character>+1. res[1..2] is the capture for the 
-- entire expression, and subsequent pairs for any () as read left-to-right. 
-- 
 
--// the fix is near roughly line 900 
 
--//tom 
--// patch return value so there is no off-by-one 
for i=2 to length(m) by 2 do 
    m[i] := m[i] - 1 
end for 
--//tom 
     
    return m 
end function 

struct

  • only a niggle

regex.e --> is not regexes.e
struct.e --> should not be structs.e

(just some subliminal issue after reading the struct docs...)

  • := not recognized

in a struct you use `=` (as expected) but can't use `:=` (as works in the rest of phix)


thanks for your work

_tom

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu