home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / LIB / REGEXP.LF < prev    next >
Text File  |  1996-06-04  |  893b  |  32 lines

  1. % Copyright by Denys Duchier, Dec 1994
  2. % Simon Fraser University
  3. % --------------------------------------------------------------------
  4. %    $Id: regexp.lf,v 1.3 1995/01/24 23:07:21 duchier Exp $
  5. % --------------------------------------------------------------------
  6.  
  7. module("regexp")?
  8. public(re_compile,re_match,re_substr,re_split,re_matching)?
  9.  
  10. re_compile(S:string) -> sys#regexp_compile(S).
  11. re_compile(R:regexp) -> R.
  12.  
  13. X:re_match(R,S) ->
  14.     cond(has_feature(3,X,M),
  15.          sys#regexp_execute(RE:re_compile(R),S,M),
  16.          sys#regexp_execute(RE,S)).
  17.  
  18. re_substr((B,E),S) -> substr(S,B,E-B).
  19.  
  20. maybe_substr(N,M,B,S) -> true |
  21.     cond(has_feature(N,M,SN),
  22.          cond(has_feature(N,B,BN),
  23.           SN=re_substr(BN,S),fail),
  24.          succeed).
  25.  
  26. re_split(R,S,M) :-
  27.     B=re_match(R,S),
  28.     F=maybe_substr(2=>M,3=>B,4=>S),
  29.     F(0),F(1),F(2),F(3),F(4),F(5),F(6),F(7),F(8),F(9).
  30.  
  31. re_matching(R) -> S:string | re_match(R,S,@).
  32.