Changeset 3594


Ignore:
Timestamp:
Dec 23, 2013, 3:36:03 PM (6 years ago)
Author:
cameron
Message:

Fix syntax errors

File:
1 edited

Legend:

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

    r3593 r3594  
    1212import Data.Char
    1313
    14 data RE = CC String | Seq [RE] | Alt [RE] | Rep RE Int Int |
     14data RepLimit = UpperBound Int | Unbounded deriving Show
     15upper_bound_dec (UpperBound j) = UpperBound (j - 1)
     16upper_bound_dec Unbounded = Unbounded
     17
     18data RE = CC String | Seq [RE] | Alt [RE] | Rep RE Int RepLimit |
    1519          Start | End  -- lookbehind/lookahead assertions for newline
    1620-- Rep r i j represents bounded repetition, with lower bound i and
     
    2731canonicalize (Proto.Join rs) = Seq (map canonicalize rs)
    2832canonicalize (Proto.Alt rs) = Alt (map canonicalize rs)
    29 canonicalize (Proto.Opt r) = Rep (canonicalize r) 0 1
    30 canonicalize (Proto.Kstar r) = Rep (canonicalize r) 0 (-1)
    31 canonicalize (Proto.Kplus r) = Rep (canonicalize r) 1 (-1)
    32 canonicalize (Proto.OrMore i r) = Rep (canonicalize r) i (-1)
    33 canonicalize (Proto.Bounded i j r) = Rep (canonicalize r) i j
     33canonicalize (Proto.Opt r) = Rep (canonicalize r) 0 (UpperBound 1)
     34canonicalize (Proto.Kstar r) = Rep (canonicalize r) 0 Unbounded
     35canonicalize (Proto.Kplus r) = Rep (canonicalize r) 1 Unbounded
     36canonicalize (Proto.OrMore i r) = Rep (canonicalize r) i Unbounded
     37canonicalize (Proto.Bounded i j r) = Rep (canonicalize r) i (UpperBound j)
    3438
    3539
     
    6367   | otherwise            = Seq ((removeNullablePrefix r):rs)
    6468removeNullablePrefix (Alt rs) = Alt (map removeNullablePrefix rs)
    65 removeNullablePrefix (Rep r i j)
     69removeNullablePrefix (Rep r 0 ub) = Seq []
     70removeNullablePrefix (Rep r lb ub)
    6671   | minMatchLen(r) == 0  = Seq []
    67    | i == 0               = Seq []
    68    | otherwise            = Seq [removeNullablePrefix(r), Rep r (i-1) (j-1)]
     72   | otherwise            = Seq [removeNullablePrefix(r), Rep r (lb-1) (upper_bound_dec ub)]
    6973
    7074
     
    100104--
    101105re2pablo_helper(Start, m) =
    102   (m+1, [SetMarker(m+1, And(m, Not(Advance(Not(CharClass('\n'))))))])
     106  (m+1, [SetMarker(m+1, And(Marker m, Not(Advance(Not(CharClass("\n"))))))])
    103107
    104108-- To match "$" we must have reached end of line.
    105109--
    106110re2pablo_helper(End, m) =
    107   (m+1, [SetMarker(m+1, And(m, CharClass('\n')))])
     111  (m+1, [SetMarker(m+1, And(Marker m, CharClass("\n")))])
    108112
    109113-- Seq [] is the empty regexp which matches the empty string. 
     
    128132-- does.
    129133
    130 re2pablo_helper(Alt (r1:rs), m) = (Or(m1, m2), s1 ++ s2)
     134re2pablo_helper(Alt (r1:rs), m) = (m2 + 1, s1 ++ s2 ++ [SetMarker (m2 + 1, Or(Marker m1, Marker m2))])
    131135  where
    132136   (m1, s1) = mre2pablo_helper(r1, m)
    133137   (m2, s2) = mre2pablo_helper(Alt rs, m1)
    134138
    135 re2pablo_helper(Rep (CC c) 0 -1, m) =
     139re2pablo_helper(Rep (CC c) 0 Unbounded, m) =
    136140   (m + 1, [SetMarker(m + 1, MatchStar(Marker(m), CharClass(c)))])
    137141
    138 re2pablo_helper(Rep r 0 j, m) =
    139   j < 0 == (m1, [SetMarker(m + 1, Marker m), While (Marker (m+1), s1 ++ [SetMarker(m + 1, And(Marker m1 ,Not(Marker (m+1))))] )])
    140   otherwise == (Or(m1, m2), s1 ++ s2)
     142re2pablo_helper(Rep r 0 ub, m)
     143  | ub < 0 = (m1, [SetMarker(m + 1, Marker m), While (Marker (m+1), s1 ++ [SetMarker(m + 1, And(Marker m1 ,Not(Marker (m+1))))] )])
     144  | otherwise = (m + 1, s1 ++ s2 ++ [SetMarker (m + 1, Or(Marker m1, Marker m2))])
    141145  where
    142146   (m1, s1) = mre2pablo_helper(r, m+1)
    143    (m2, s2) = mre2pablo_helper(Rep r 0 (j-1), m1)
     147   (m2, s2) = mre2pablo_helper(Rep r 0 (upper_bound_dec ub), m1)
    144148
    145 re2pablo_helper(Rep r i j, m) =  (m2, s1 ++ s2)
     149re2pablo_helper(Rep r lb ub, m) =  (m2, s1 ++ s2)
    146150  where
    147151   (m1, s1) = mre2pablo_helper(r, m)
    148    (m2, s2) = mre2pablo_helper(Rep r (i-1) (j-1), m1)
     152   (m2, s2) = mre2pablo_helper(Rep r (lb - 1) (upper_bound_dec ub), m1)
    149153
Note: See TracChangeset for help on using the changeset viewer.