Ignore:
Timestamp:
Aug 12, 2013, 5:53:10 PM (6 years ago)
Author:
cameron
Message:

removeNullablePrefix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/RE/doc/re_proto.hs

    r3420 r3427  
    4848minMatchLen (Bounded i j r) = i * (minMatchLen r)
    4949
     50--- removeNullablePrefix takes a regular expression and returns
     51--- the version of it that has been transformed to remove any nullable
     52--- prefixes.  A prefix p is nullable if it can possibly match the empty
     53--- string, i.e., minMatchLen(p) = 0.  For example, in the regexp
     54--- [a-z]*-[0-9]+ the prefix [a-z]* is nullable.
    5055
     56removeNullablePrefix :: RE -> RE
     57removeNullablePrefix (CC s) = (CC s)
     58removeNullablePrefix (CCnot s) = (CCnot s)
     59removeNullablePrefix (Lit s) = (Lit s)
     60removeNullablePrefix Start = Start
     61removeNullablePrefix End = End
     62removeNullablePrefix Any = Any
     63removeNullablePrefix (Join []) = Join []
     64removeNullablePrefix (Join (r:rs))
     65   | minMatchLen(r) == 0  = removeNullablePrefix(Join rs)
     66   | otherwise            = Join (r:rs)
     67removeNullablePrefix (Alt rs) = Alt (map removeNullablePrefix rs)
     68removeNullablePrefix (Opt r) = Join []
     69removeNullablePrefix (Kstar r) = Join []
     70removeNullablePrefix (Kplus r)
     71   | minMatchLen(r) == 0  = Join []
     72   | otherwise            = Join [removeNullablePrefix(r), Kstar r]
     73removeNullablePrefix (OrMore i r)
     74   | minMatchLen(r) == 0  = Join []
     75   | i == 0               = Join []
     76   | otherwise            = Join [removeNullablePrefix(r), OrMore (i-1) r]
     77removeNullablePrefix (Bounded i j r)
     78   | minMatchLen(r) == 0  = Join []
     79   | i == 0               = Join []
     80   | otherwise            = Join [removeNullablePrefix(r), Bounded (i-1) (j-1) r]
    5181
    52 
Note: See TracChangeset for help on using the changeset viewer.