jump over strings/comments

This commit is contained in:
Armin Friedl 2016-08-29 13:37:10 +02:00
parent 380ed86ccf
commit 54c04ad7c6
2 changed files with 10 additions and 2 deletions

View file

@ -1,7 +1,9 @@
{ {
error = "0"; error = "0";
fact = { % number num -> number; set error if something is wrong fact = { % number num -> number; set error if something is wrong
continue = {} + ("test 1 -ge " + num).syscall; "continue = a"
% continue = "b"
continue = {} + ("test 1 -ge " + num).syscall;
[ continue = "0" : [ continue = "0" :
[ {} + ("test 0 = " + num).syscall # "0" : [ {} + ("test 0 = " + num).syscall # "0" :
*error = "1"; *error = "1";

View file

@ -197,6 +197,12 @@ invAcc a i ('[':t) = invAcc a (i+1 + g) (drop g t) -- TODO check reads in f
-- all variables with false at the end of a block are unused -- all variables with false at the end of a block are unused
invAcc a i ('.':t) = invAcc a (i+1 + g) (drop g t) invAcc a i ('.':t) = invAcc a (i+1 + g) (drop g t)
where g = length $ fst $ fromJust $ getRead 0 t where g = length $ fst $ fromJust $ getRead 0 t
invAcc a i ('"':t) = invAcc a (i+1 + g) (drop g t)
where g = if isJust next then 1 + (fromJust next) else length t
next = elemIndex '"' t
invAcc a i ('%':t) = invAcc a (i+1 + g) (drop g t)
where g = if isJust next then 1 + (fromJust next) else length t
next = elemIndex '\n' t
invAcc a i s@(c:t) = let writeAcc = getWrite i s invAcc a i s@(c:t) = let writeAcc = getWrite i s
matchLen = (length $ (\(v,_,_) -> v) (fromJust writeAcc)) matchLen = (length $ (\(v,_,_) -> v) (fromJust writeAcc))
readAcc = getRead i s readAcc = getRead i s
@ -207,7 +213,7 @@ invAcc a i s@(c:t) = let writeAcc = getWrite i s
else if isUnassigned (fromJust readAcc) a -- no assignment in rest str else if isUnassigned (fromJust readAcc) a -- no assignment in rest str
then (snd (fromJust readAcc)) : (invAcc a (i+readLen) (drop readLen s)) then (snd (fromJust readAcc)) : (invAcc a (i+readLen) (drop readLen s))
else invAcc (markRead (fromJust readAcc) a) (i+readLen) (drop readLen s) else invAcc (markRead (fromJust readAcc) a) (i+readLen) (drop readLen s)
else invAcc (a ++ [fromJust writeAcc]) (i+matchLen) (drop matchLen s) -- assignment in accumStr, advance offset to end else invAcc (fromJust writeAcc: a) (i+matchLen) (drop matchLen s) -- assignment in accumStr, advance offset to end
invAcc _ _ _ = [] invAcc _ _ _ = []
getWrite :: Int -> String -> Maybe (String, Slice, Bool) getWrite :: Int -> String -> Maybe (String, Slice, Bool)