wrote concept for invAcc

This commit is contained in:
Johannes Winklehner 2016-08-28 21:37:23 +02:00
parent 7350e8a4cd
commit 14a7fe984f

View file

@ -17,6 +17,8 @@ import Lens.Micro ((%~), (&), (.~), (^.))
import Lens.Micro.TH (makeLenses)
import qualified Data.Map as Map
import Data.List
import Data.Maybe
{---- Type Definitions ----}
-- defines an attribute for a text slice
@ -168,16 +170,42 @@ mismatchedQuotes s = slicesToFT §: "err_quotes" $ firstChar untermed
| otherwise = negPrune checkFts slices
-- ::CheckString -> Slices == ::String -> [(Int,Int)]
invalidReads :: CheckString -> Slices
--invalidReads :: CheckString -> Slices
invalidReads s = [] -- do magic here
invalidWrites :: CheckString -> Slices
--invalidWrites :: CheckString -> Slices
invalidWrites s = [] -- do magic here
-- (alternative if easier than invalid read/invalid write separated)
-- invAcc :: CheckString -> Slices
-- invAcc s = [] -- do magic here
{-invAcc :: [(String,Slice,Bool)] -> CheckString -> Slices
invAcc _ "" = [] -- do magic here
invAcc a ('{':t) = invAcc (enterBlock a) t
invAcc a ('}':t) = invAcc (leaveBlock a) t
invAcc a ('[':t) = invAcc a (drop g t) -- TODO check reads
where g = fromJust (elemIndex ':' t)
-}
invAcc :: [(String,Slice,Bool)] -> CheckString -> Slices
invAcc a ('{':t) = invAcc (enterBlock a) t
invAcc a ('}':t) = invAcc (leaveBlock a) t
invAcc a ('[':t) = invAcc a (drop g t) -- TODO check reads in first part
where g = fromJust (elemIndex ':' t)
-- when reading a assignment :word: =
-- put :word:, slice, false in the list
-- when reading a read access scan the list for the variable
-- if it is found set its boolean value to true
-- if it is not found add its slice to the result
-- all variables with false at the end of a block are unused
invAcc _ _ = []
enterBlock :: [(String,Slice,Bool)] -> [(String,Slice,Bool)]
enterBlock = map (\(v,s,b) -> ('*':v,s,b))
-- remove 1 * from each variable name
-- if it cannot be removed, remove the variable
leaveBlock :: [(String,Slice,Bool)] -> [(String,Slice,Bool)]
leaveBlock _ = []
{- General Fontification Utilities -}