Created
January 10, 2012 14:40
-
-
Save arnar/1589395 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Syntax.hs b/src/Syntax.hs | |
index 1905488..475a02a 100644 | |
--- a/src/Syntax.hs | |
+++ b/src/Syntax.hs | |
@@ -2,6 +2,7 @@ | |
module Syntax where | |
import Labels | |
+import Control.Monad.State | |
import Data.Generics | |
import Text.PrettyPrint | |
@@ -55,40 +56,9 @@ data LCmd = CSkip | |
deriving (Eq,Show,Data,Typeable) | |
-relabel c = snd $ aux 1 c | |
- where aux n CSkip = (n, CSkip) | |
- aux n (CAsn _ lhs e) = (n+1, CAsn (Posn n) lhs e) | |
- aux n (CNew _ lhs) = (n+1, CNew (Posn n) lhs) | |
- | |
- aux n (CBlock cs) = let (n', cs') = f n cs in (n', CBlock cs') | |
- where f n [] = (n, []) | |
- f n (c:cs) = let (n' ,c') = aux n c | |
- (n'',cs') = f n' cs in | |
- (n'', c' : cs') | |
- | |
- aux n (CIf _ e c1 c2) = | |
- let (n' ,c1') = aux (n+1) c1 | |
- (n'',c2') = aux n' c2 in | |
- (n'', CIf (Posn n) e c1' c2') | |
- | |
- aux n (CWhile _ e c) = | |
- let (n' ,c') = aux (n+1) c in | |
- (n', CWhile (Posn n) e c') | |
- | |
- aux n (CThrow _) = (n+1, CThrow (Posn n)) | |
- | |
- aux n (CTry _ c1 c2) = | |
- let (n' ,c1') = aux (n+1) c1 | |
- (n'',c2') = aux n' c2 in | |
- (n'', CTry (Posn n) c1' c2') | |
- | |
- aux n (CUp _ lhs l) = (n+1, CUp (Posn n) lhs l) | |
- aux n (CUpError _ l) = (n+1, CUpError (Posn n) l) | |
- aux n (CUpStruct _ lhs l) = (n+1, CUpStruct (Posn n) lhs l) | |
- aux n (CUpExist _ lhs l) = (n+1, CUpExist (Posn n) lhs l) | |
- | |
- aux _ _ = error "relabel: CEnd, CTryEnd, COr only for internal use" | |
- | |
+reposition :: Posn -> State Int Posn | |
+reposition x = modify (+1) >> get >>= return . Posn | |
+relabel c = evalState (everywhereM (mkM reposition) c) 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment