diff --git a/src/App/Fontifier.hs b/src/App/Fontifier.hs index c2440c2..d76d75c 100644 --- a/src/App/Fontifier.hs +++ b/src/App/Fontifier.hs @@ -187,8 +187,9 @@ invalidAccesses = invAcc [] 0 invAcc :: [(String,Slice,Bool)] -> Int -> CheckString -> Slices invAcc a i ('{':t) = invAcc (enterBlock a) (i+1) t invAcc a i ('}':t) = getUnread a ++ invAcc (leaveBlock a) (i+1) t -invAcc a i ('[':t) = invAcc a (i+1 + g) (drop g t) -- TODO check reads in first part +invAcc a i ('[':t) = map snd (filter (\x -> isUnassigned x a) r) ++ invAcc (markReads r a) (i+1 + g) (drop g t) -- TODO check reads in first part where g = fromJust (elemIndex ':' t) + r = getReads (i+1) (take g t) -- when reading an assignment :word: = -- put :word:, slice, false in the list -- when reading a read access scan the list for the variable @@ -210,6 +211,16 @@ invAcc a i s@(c:t) = let writeAcc = getWrite i s else invAcc (a ++ [fromJust writeAcc]) (i+matchLen) (drop matchLen s) -- assignment in accumStr, advance offset to end invAcc _ _ _ = [] +getReads :: Int -> String -> [(String,Slice)] +getReads _ "" = [] +getReads i ('.':t) = getReads (i+1 + g) (drop g t) + where g = length $ fst $ fromJust $ getRead 0 t +getReads i s@(c:ss) + | isNothing v = getReads (i+1) ss + | otherwise = let l = length $ fst $ fromJust v + in fromJust v : getReads (i+l) (drop l s) + where v = getRead i s + getWrite :: Int -> String -> Maybe (String, Slice, Bool) getWrite offset s = ((Tdfa.matchOnceText ยง~ "^(\\**[[:word:]]+)[[:blank:]]*=") s) >>= matchToA where matchToA (before, match, after) = @@ -228,6 +239,10 @@ isUnassigned (s,_) = null . filter (\(t,_,_) -> t == s) markRead :: (String,Slice) -> [(String,Slice,Bool)] -> [(String,Slice,Bool)] markRead (s,_) = map (\(v,p,b) -> (v,p,b || v == s)) +markReads :: [(String,Slice)] -> [(String,Slice,Bool)] -> [(String,Slice,Bool)] +markReads [] a = a +markReads (r:rs) a = markReads rs $ markRead r a + enterBlock :: [(String,Slice,Bool)] -> [(String,Slice,Bool)] enterBlock = map (\(v,s,b) -> ('*':v,s,b))