Changeset 9054
- Timestamp:
- 02/18/06 21:47:47 (3 years ago)
- Location:
- src
- Files:
-
- 8 modified
-
DrIFT/RuleYAML.hs (modified) (2 diffs)
-
DrIFT/YAML.hs (modified) (9 diffs)
-
Emit/PIR.hs (modified) (9 diffs)
-
Pugs/AST/Internals.hs (modified) (15 diffs)
-
Pugs/CodeGen.hs (modified) (3 diffs)
-
Pugs/CodeGen/YAML.hs (modified) (2 diffs)
-
Pugs/PIL1.hs (modified) (10 diffs)
-
Pugs/PIL2.hs (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/DrIFT/RuleYAML.hs
r9051 r9054 12 12 13 13 caseHead, caseTail :: Doc 14 caseHead = text "fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of" 15 caseTail = nest 8 $ text "_ -> fail $ \"unhandled tag: \" ++ (show t)" 14 caseHead = text "fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of" 15 caseTail = nest 4 (text "_ -> fail $ \"unhandled tag: \" ++ show t") 16 $+$ text "fromYAML _ = fail \"no tag found\"" 16 17 17 18 makeFromYAML, makeAsYAML :: IFunction 18 19 19 20 makeFromYAML Body{constructor=constructor,labels=labels,types=types} = 20 nest 8 $ dqt constructor <+> match <+> makeFromYAML' $+$ extraLifts21 nest 4 $ eqv <+> match <+> dot $+$ extraLifts $+$ makeFromYAML' 21 22 where 22 23 dqt = doubleQuotes . text 23 24 match = text "->" 24 25 dot = text "do" 26 -- eqv = text "| t == packFS" <+> dqt ("tag:hs:" ++ constructor) 27 eqv = dqt constructor 25 28 makeFromYAML' 26 | null types = text "return" <+> text constructor29 | null types = nest 4 $ text "return" <+> text constructor 27 30 | null labels = vcat 28 [ dot 29 , nest 4 $ text "let YamlSeq" <+> (list $ varNames types) <+> equals <+> text "e" 31 [ nest 4 $ text "let YamlSeq" <+> (list $ varNames types) <+> equals <+> text "e" 30 32 , nest 4 $ liftNfy 31 33 ] 32 34 | otherwise = vcat 33 [ dot 34 , nest 4 $ text "let YamlMap assocs = e" 35 [ nest 4 $ text "let YamlMap assocs = e" 35 36 , nest 4 $ text "let" <+> (list $ varNames types) <+> equals <+> text "map snd assocs" 36 37 , nest 4 $ liftNfy … … 42 43 extraLifts 43 44 | length types < 6 = empty 44 | otherwise = nest 16 $ (text "where") $+$(hsep $ -- XXX: pull me to the level of the case?45 | otherwise = nest 4 $ (text "let") <+> (hsep $ -- XXX: pull me to the level of the case? 45 46 [ (text $ "liftM" ++ (show arity)) 46 47 , text "f" -
src/DrIFT/YAML.hs
r9051 r9054 26 26 type SeenCache = IntSet.IntSet 27 27 28 packFS :: String -> Str.FastString 29 packFS = Str.pack 30 31 unpackFS :: Str.FastString -> String 32 unpackFS = Str.unpack 33 34 toYamlNode :: YAML a => a -> IO YamlNode 35 toYamlNode x = runReaderT (asYAML x) IntSet.empty 36 28 37 showYaml :: YAML a => a -> IO String 29 38 showYaml x = do 30 node <- (`runReaderT` IntSet.empty) (asYAML x)39 node <- toYamlNode x 31 40 rv <- emitYaml node 32 case rv of 33 Left e -> error e 34 Right s -> return s 41 either fail return rv 35 42 36 43 type EmitAs = ReaderT SeenCache IO … … 67 74 mapM fromYAMLpair m 68 75 where 69 fromYAMLpair ~(MkYamlNode{el=YamlStr k}, v) = do76 fromYAMLpair (MkYamlNode{el=YamlStr k}, v) = do 70 77 v' <- fromYAML v 71 78 return (Str.unpack k, v') 79 fromYAMLpair _ = fail "no parse" 72 80 73 81 … … 92 100 instance YAML Int where 93 101 asYAML x = return $ mkTagNode "int" (YamlStr $ Str.pack $ show x) 94 fromYAMLElem ~(YamlStr x) = return $ read $ Str.unpack x 102 fromYAMLElem (YamlStr x) = return $ read $ Str.unpack x 103 fromYAMLElem _ = fail "no parse" 95 104 96 105 instance YAML String where 97 106 asYAML str = return $ mkTagNode "str" (YamlStr $ Str.pack str) 98 fromYAMLElem ~(YamlStr str) = return $ Str.unpack str 107 fromYAMLElem (YamlStr str) = return $ Str.unpack str 108 fromYAMLElem _ = fail "no parse" 99 109 100 110 instance YAML Bool where … … 104 114 fromYAML MkYamlNode{tag=Just s} | s == Str.pack "bool#no" = return False 105 115 fromYAML MkYamlNode{el=x} = fromYAMLElem x 106 fromYAMLElem ~(YamlStr x) = return (x == Str.pack "0") 116 fromYAMLElem (YamlStr x) = return (x == Str.pack "0") 117 fromYAMLElem _ = fail "no parse" 107 118 108 119 instance YAML Integer where 109 120 asYAML x = return $ mkTagNode "int" (YamlStr $ Str.pack $ show x) 110 fromYAMLElem ~(YamlStr x) = return $ read $ Str.unpack x 121 fromYAMLElem (YamlStr x) = return $ read $ Str.unpack x 122 fromYAMLElem _ = fail "no parse" 111 123 112 124 instance YAML Rational where … … 115 127 x = numerator r 116 128 y = denominator r 117 fromYAMLElem ~(YamlStr str) = return $ (read x) / (read y) 118 where 119 (x,y) = break (== '/') (Str.unpack str) 129 fromYAMLElem (YamlStr str) = do 130 let (x,y) = break (== '/') (Str.unpack str) 131 return $ (read x) / (read y) 132 fromYAMLElem _ = fail "no parse" 120 133 121 134 instance YAML Double where … … 128 141 fromYAML MkYamlNode{tag=Just s} | s == Str.pack "float#nan" = return $ 0/0 -- "NaN" 129 142 fromYAML MkYamlNode{el=x} = fromYAMLElem x 130 fromYAMLElem ~(YamlStr x) = return $ read $ Str.unpack x 143 fromYAMLElem (YamlStr x) = return $ read $ Str.unpack x 144 fromYAMLElem _ = fail "no parse" 131 145 132 146 instance (YAML a) => YAML (Maybe a) where … … 142 156 xs' <- mapM asYAML xs 143 157 (return . mkNode . YamlSeq) xs' 144 fromYAMLElem ~(YamlSeq s) = mapM fromYAML s 158 fromYAMLElem (YamlSeq s) = mapM fromYAML s 159 fromYAMLElem _ = fail "no parse" 145 160 146 161 instance (YAML a, YAML b) => YAML (a, b) where … … 149 164 y' <- asYAML y 150 165 return $ mkNode (YamlSeq [x', y']) 151 fromYAMLElem ~(YamlSeq [x, y]) = do166 fromYAMLElem (YamlSeq [x, y]) = do 152 167 x' <- fromYAML x 153 168 y' <- fromYAML y 154 169 return (x', y') 170 fromYAMLElem _ = fail "no parse" 155 171 156 172 instance (YAML a, YAML b, YAML c) => YAML (a, b, c) where … … 160 176 z' <- asYAML z 161 177 return $ mkNode (YamlSeq [x', y', z']) 162 fromYAMLElem ~(YamlSeq [x, y, z]) = do178 fromYAMLElem (YamlSeq [x, y, z]) = do 163 179 x' <- fromYAML x 164 180 y' <- fromYAML y 165 181 z' <- fromYAML z 166 182 return (x', y', z') 183 fromYAMLElem _ = fail "no parse" 167 184 168 185 instance (Typeable a, YAML a) => YAML (TVar a) where -
src/Emit/PIR.hs
r9051 r9054 1000 1000 {-* Generated by DrIFT : Look, but Don't Touch. *-} 1001 1001 instance YAML Decl where 1002 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1003 "DeclSub" -> do let YamlMap assocs = e 1004 let [aa , ab , ac] = map snd assocs 1005 liftM3 DeclSub (fromYAML aa) (fromYAML ab) (fromYAML ac) 1006 "DeclNS" -> do let YamlMap assocs = e 1007 let [aa , ab] = map snd assocs 1008 liftM2 DeclNS (fromYAML aa) (fromYAML ab) 1009 "DeclInc" -> do let YamlMap assocs = e 1010 let [aa] = map snd assocs 1011 liftM DeclInc (fromYAML aa) 1012 _ -> fail $ "unhandled tag: " ++ (show t) 1002 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1003 "DeclSub" -> do 1004 let YamlMap assocs = e 1005 let [aa , ab , ac] = map snd assocs 1006 liftM3 DeclSub (fromYAML aa) (fromYAML ab) (fromYAML ac) 1007 "DeclNS" -> do 1008 let YamlMap assocs = e 1009 let [aa , ab] = map snd assocs 1010 liftM2 DeclNS (fromYAML aa) (fromYAML ab) 1011 "DeclInc" -> do 1012 let YamlMap assocs = e 1013 let [aa] = map snd assocs 1014 liftM DeclInc (fromYAML aa) 1015 _ -> fail $ "unhandled tag: " ++ show t 1016 fromYAML _ = fail "no tag found" 1013 1017 asYAML (DeclSub aa ab ac) = asYAMLmap "DeclSub" 1014 1018 [("dsName", asYAML aa) , ("dsFlags", asYAML ab) , … … 1019 1023 1020 1024 instance YAML Stmt where 1021 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1022 "StmtComment" -> do let YamlSeq [aa] = e 1023 liftM StmtComment (fromYAML aa) 1024 "StmtLine" -> do let YamlSeq [aa , ab] = e 1025 liftM2 StmtLine (fromYAML aa) (fromYAML ab) 1026 "StmtPad" -> do let YamlSeq [aa , ab] = e 1027 liftM2 StmtPad (fromYAML aa) (fromYAML ab) 1028 "StmtRaw" -> do let YamlSeq [aa] = e 1029 liftM StmtRaw (fromYAML aa) 1030 "StmtIns" -> do let YamlSeq [aa] = e 1031 liftM StmtIns (fromYAML aa) 1032 "StmtSub" -> do let YamlSeq [aa , ab] = e 1033 liftM2 StmtSub (fromYAML aa) (fromYAML ab) 1034 _ -> fail $ "unhandled tag: " ++ (show t) 1025 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1026 "StmtComment" -> do 1027 let YamlSeq [aa] = e 1028 liftM StmtComment (fromYAML aa) 1029 "StmtLine" -> do 1030 let YamlSeq [aa , ab] = e 1031 liftM2 StmtLine (fromYAML aa) (fromYAML ab) 1032 "StmtPad" -> do 1033 let YamlSeq [aa , ab] = e 1034 liftM2 StmtPad (fromYAML aa) (fromYAML ab) 1035 "StmtRaw" -> do 1036 let YamlSeq [aa] = e 1037 liftM StmtRaw (fromYAML aa) 1038 "StmtIns" -> do 1039 let YamlSeq [aa] = e 1040 liftM StmtIns (fromYAML aa) 1041 "StmtSub" -> do 1042 let YamlSeq [aa , ab] = e 1043 liftM2 StmtSub (fromYAML aa) (fromYAML ab) 1044 _ -> fail $ "unhandled tag: " ++ show t 1045 fromYAML _ = fail "no tag found" 1035 1046 asYAML (StmtComment aa) = asYAMLseq "StmtComment" [asYAML aa] 1036 1047 asYAML (StmtLine aa ab) = asYAMLseq "StmtLine" … … 1044 1055 1045 1056 instance YAML Ins where 1046 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1047 "InsLocal" -> do let YamlSeq [aa , ab] = e 1048 liftM2 InsLocal (fromYAML aa) (fromYAML ab) 1049 "InsNew" -> do let YamlSeq [aa , ab] = e 1050 liftM2 InsNew (fromYAML aa) (fromYAML ab) 1051 "InsBind" -> do let YamlSeq [aa , ab] = e 1052 liftM2 InsBind (fromYAML aa) (fromYAML ab) 1053 "InsAssign" -> do let YamlSeq [aa , ab] = e 1054 liftM2 InsAssign (fromYAML aa) (fromYAML ab) 1055 "InsPrim" -> do let YamlSeq [aa , ab , ac] = e 1056 liftM3 InsPrim (fromYAML aa) (fromYAML ab) (fromYAML ac) 1057 "InsFun" -> do let YamlSeq [aa , ab , ac] = e 1058 liftM3 InsFun (fromYAML aa) (fromYAML ab) (fromYAML ac) 1059 "InsTailFun" -> do let YamlSeq [aa , ab] = e 1060 liftM2 InsTailFun (fromYAML aa) (fromYAML ab) 1061 "InsLabel" -> do let YamlSeq [aa] = e 1062 liftM InsLabel (fromYAML aa) 1063 "InsComment" -> do let YamlSeq [aa , ab] = e 1064 liftM2 InsComment (fromYAML aa) (fromYAML ab) 1065 "InsExp" -> do let YamlSeq [aa] = e 1066 liftM InsExp (fromYAML aa) 1067 "InsConst" -> do let YamlSeq [aa , ab , ac] = e 1068 liftM3 InsConst (fromYAML aa) (fromYAML ab) (fromYAML ac) 1069 _ -> fail $ "unhandled tag: " ++ (show t) 1057 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1058 "InsLocal" -> do 1059 let YamlSeq [aa , ab] = e 1060 liftM2 InsLocal (fromYAML aa) (fromYAML ab) 1061 "InsNew" -> do 1062 let YamlSeq [aa , ab] = e 1063 liftM2 InsNew (fromYAML aa) (fromYAML ab) 1064 "InsBind" -> do 1065 let YamlSeq [aa , ab] = e 1066 liftM2 InsBind (fromYAML aa) (fromYAML ab) 1067 "InsAssign" -> do 1068 let YamlSeq [aa , ab] = e 1069 liftM2 InsAssign (fromYAML aa) (fromYAML ab) 1070 "InsPrim" -> do 1071 let YamlSeq [aa , ab , ac] = e 1072 liftM3 InsPrim (fromYAML aa) (fromYAML ab) (fromYAML ac) 1073 "InsFun" -> do 1074 let YamlSeq [aa , ab , ac] = e 1075 liftM3 InsFun (fromYAML aa) (fromYAML ab) (fromYAML ac) 1076 "InsTailFun" -> do 1077 let YamlSeq [aa , ab] = e 1078 liftM2 InsTailFun (fromYAML aa) (fromYAML ab) 1079 "InsLabel" -> do 1080 let YamlSeq [aa] = e 1081 liftM InsLabel (fromYAML aa) 1082 "InsComment" -> do 1083 let YamlSeq [aa , ab] = e 1084 liftM2 InsComment (fromYAML aa) (fromYAML ab) 1085 "InsExp" -> do 1086 let YamlSeq [aa] = e 1087 liftM InsExp (fromYAML aa) 1088 "InsConst" -> do 1089 let YamlSeq [aa , ab , ac] = e 1090 liftM3 InsConst (fromYAML aa) (fromYAML ab) (fromYAML ac) 1091 _ -> fail $ "unhandled tag: " ++ show t 1092 fromYAML _ = fail "no tag found" 1070 1093 asYAML (InsLocal aa ab) = asYAMLseq "InsLocal" 1071 1094 [asYAML aa , asYAML ab] … … 1089 1112 1090 1113 instance YAML Expression where 1091 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1092 "ExpLV" -> do let YamlSeq [aa] = e 1093 liftM ExpLV (fromYAML aa) 1094 "ExpLit" -> do let YamlSeq [aa] = e 1095 liftM ExpLit (fromYAML aa) 1096 _ -> fail $ "unhandled tag: " ++ (show t) 1114 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1115 "ExpLV" -> do 1116 let YamlSeq [aa] = e 1117 liftM ExpLV (fromYAML aa) 1118 "ExpLit" -> do 1119 let YamlSeq [aa] = e 1120 liftM ExpLit (fromYAML aa) 1121 _ -> fail $ "unhandled tag: " ++ show t 1122 fromYAML _ = fail "no tag found" 1097 1123 asYAML (ExpLV aa) = asYAMLseq "ExpLV" [asYAML aa] 1098 1124 asYAML (ExpLit aa) = asYAMLseq "ExpLit" [asYAML aa] 1099 1125 1100 1126 instance YAML LValue where 1101 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1102 "VAR" -> do let YamlSeq [aa] = e 1103 liftM VAR (fromYAML aa) 1104 "PMC" -> do let YamlSeq [aa] = e 1105 liftM PMC (fromYAML aa) 1106 "STR" -> do let YamlSeq [aa] = e 1107 liftM STR (fromYAML aa) 1108 "INT" -> do let YamlSeq [aa] = e 1109 liftM INT (fromYAML aa) 1110 "NUM" -> do let YamlSeq [aa] = e 1111 liftM NUM (fromYAML aa) 1112 "KEYED" -> do let YamlSeq [aa , ab] = e 1113 liftM2 KEYED (fromYAML aa) (fromYAML ab) 1114 _ -> fail $ "unhandled tag: " ++ (show t) 1127 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1128 "VAR" -> do 1129 let YamlSeq [aa] = e 1130 liftM VAR (fromYAML aa) 1131 "PMC" -> do 1132 let YamlSeq [aa] = e 1133 liftM PMC (fromYAML aa) 1134 "STR" -> do 1135 let YamlSeq [aa] = e 1136 liftM STR (fromYAML aa) 1137 "INT" -> do 1138 let YamlSeq [aa] = e 1139 liftM INT (fromYAML aa) 1140 "NUM" -> do 1141 let YamlSeq [aa] = e 1142 liftM NUM (fromYAML aa) 1143 "KEYED" -> do 1144 let YamlSeq [aa , ab] = e 1145 liftM2 KEYED (fromYAML aa) (fromYAML ab) 1146 _ -> fail $ "unhandled tag: " ++ show t 1147 fromYAML _ = fail "no tag found" 1115 1148 asYAML (VAR aa) = asYAMLseq "VAR" [asYAML aa] 1116 1149 asYAML (PMC aa) = asYAMLseq "PMC" [asYAML aa] … … 1121 1154 1122 1155 instance YAML Literal where 1123 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1124 "LitStr" -> do let YamlSeq [aa] = e 1125 liftM LitStr (fromYAML aa) 1126 "LitInt" -> do let YamlSeq [aa] = e 1127 liftM LitInt (fromYAML aa) 1128 "LitNum" -> do let YamlSeq [aa] = e 1129 liftM LitNum (fromYAML aa) 1130 _ -> fail $ "unhandled tag: " ++ (show t) 1156 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1157 "LitStr" -> do 1158 let YamlSeq [aa] = e 1159 liftM LitStr (fromYAML aa) 1160 "LitInt" -> do 1161 let YamlSeq [aa] = e 1162 liftM LitInt (fromYAML aa) 1163 "LitNum" -> do 1164 let YamlSeq [aa] = e 1165 liftM LitNum (fromYAML aa) 1166 _ -> fail $ "unhandled tag: " ++ show t 1167 fromYAML _ = fail "no tag found" 1131 1168 asYAML (LitStr aa) = asYAMLseq "LitStr" [asYAML aa] 1132 1169 asYAML (LitInt aa) = asYAMLseq "LitInt" [asYAML aa] … … 1134 1171 1135 1172 instance YAML SubFlag where 1136 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1137 "SubMAIN" -> return SubMAIN 1138 "SubLOAD" -> return SubLOAD 1139 "SubANON" -> return SubANON 1140 "SubMETHOD" -> return SubMETHOD 1141 "SubMULTI" -> do let YamlSeq [aa] = e 1142 liftM SubMULTI (fromYAML aa) 1143 "SubOUTER" -> do let YamlSeq [aa] = e 1144 liftM SubOUTER (fromYAML aa) 1145 _ -> fail $ "unhandled tag: " ++ (show t) 1173 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1174 "SubMAIN" -> do 1175 return SubMAIN 1176 "SubLOAD" -> do 1177 return SubLOAD 1178 "SubANON" -> do 1179 return SubANON 1180 "SubMETHOD" -> do 1181 return SubMETHOD 1182 "SubMULTI" -> do 1183 let YamlSeq [aa] = e 1184 liftM SubMULTI (fromYAML aa) 1185 "SubOUTER" -> do 1186 let YamlSeq [aa] = e 1187 liftM SubOUTER (fromYAML aa) 1188 _ -> fail $ "unhandled tag: " ++ show t 1189 fromYAML _ = fail "no tag found" 1146 1190 asYAML (SubMAIN) = asYAMLcls "SubMAIN" 1147 1191 asYAML (SubLOAD) = asYAMLcls "SubLOAD" … … 1152 1196 1153 1197 instance YAML RegType where 1154 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1155 "RegInt" -> return RegInt 1156 "RegNum" -> return RegNum 1157 "RegStr" -> return RegStr 1158 "RegPMC" -> return RegPMC 1159 _ -> fail $ "unhandled tag: " ++ (show t) 1198 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1199 "RegInt" -> do 1200 return RegInt 1201 "RegNum" -> do 1202 return RegNum 1203 "RegStr" -> do 1204 return RegStr 1205 "RegPMC" -> do 1206 return RegPMC 1207 _ -> fail $ "unhandled tag: " ++ show t 1208 fromYAML _ = fail "no tag found" 1160 1209 asYAML (RegInt) = asYAMLcls "RegInt" 1161 1210 asYAML (RegNum) = asYAMLcls "RegNum" … … 1164 1213 1165 1214 instance YAML ObjType where 1166 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1167 "PerlScalar" -> return PerlScalar 1168 "PerlArray" -> return PerlArray 1169 "PerlHash" -> return PerlHash 1170 "PerlInt" -> return PerlInt 1171 "PerlPair" -> return PerlPair 1172 "PerlRef" -> return PerlRef 1173 "PerlEnv" -> return PerlEnv 1174 "Sub" -> return Sub 1175 "Closure" -> return Closure 1176 "Continuation" -> return Continuation 1177 "BareType" -> do let YamlSeq [aa] = e 1178 liftM BareType (fromYAML aa) 1179 _ -> fail $ "unhandled tag: " ++ (show t) 1215 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1216 "PerlScalar" -> do 1217 return PerlScalar 1218 "PerlArray" -> do 1219 return PerlArray 1220 "PerlHash" -> do 1221 return PerlHash 1222 "PerlInt" -> do 1223 return PerlInt 1224 "PerlPair" -> do 1225 return PerlPair 1226 "PerlRef" -> do 1227 return PerlRef 1228 "PerlEnv" -> do 1229 return PerlEnv 1230 "Sub" -> do 1231 return Sub 1232 "Closure" -> do 1233 return Closure 1234 "Continuation" -> do 1235 return Continuation 1236 "BareType" -> do 1237 let YamlSeq [aa] = e 1238 liftM BareType (fromYAML aa) 1239 _ -> fail $ "unhandled tag: " ++ show t 1240 fromYAML _ = fail "no tag found" 1180 1241 asYAML (PerlScalar) = asYAMLcls "PerlScalar" 1181 1242 asYAML (PerlArray) = asYAMLcls "PerlArray" … … 1191 1252 1192 1253 instance YAML Sig where 1193 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1194 "MkSig" -> do let YamlMap assocs = e 1195 let [aa , ab] = map snd assocs 1196 liftM2 MkSig (fromYAML aa) (fromYAML ab) 1197 _ -> fail $ "unhandled tag: " ++ (show t) 1254 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1255 "MkSig" -> do 1256 let YamlMap assocs = e 1257 let [aa , ab] = map snd assocs 1258 liftM2 MkSig (fromYAML aa) (fromYAML ab) 1259 _ -> fail $ "unhandled tag: " ++ show t 1260 fromYAML _ = fail "no tag found" 1198 1261 asYAML (MkSig aa ab) = asYAMLmap "MkSig" 1199 1262 [("sigFlags", asYAML aa) , ("sigIdent", asYAML ab)] 1200 1263 1201 1264 instance YAML ArgFlag where 1202 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1203 "MkArgFlatten" -> return MkArgFlatten 1204 "MkArgSlurpyArray" -> return MkArgSlurpyArray 1205 "MkArgMaybeFlatten" -> return MkArgMaybeFlatten 1206 "MkArgOptional" -> return MkArgOptional 1207 _ -> fail $ "unhandled tag: " ++ (show t) 1265 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1266 "MkArgFlatten" -> do 1267 return MkArgFlatten 1268 "MkArgSlurpyArray" -> do 1269 return MkArgSlurpyArray 1270 "MkArgMaybeFlatten" -> do 1271 return MkArgMaybeFlatten 1272 "MkArgOptional" -> do 1273 return MkArgOptional 1274 _ -> fail $ "unhandled tag: " ++ show t 1275 fromYAML _ = fail "no tag found" 1208 1276 asYAML (MkArgFlatten) = asYAMLcls "MkArgFlatten" 1209 1277 asYAML (MkArgSlurpyArray) = asYAMLcls "MkArgSlurpyArray" -
src/Pugs/AST/Internals.hs
r9051 r9054 1951 1951 {-* Generated by DrIFT : Look, but Don't Touch. *-} 1952 1952 instance YAML VThunk where 1953 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1954 "MkThunk" -> do let YamlMap assocs = e 1955 let [aa , ab] = map snd assocs 1956 liftM2 MkThunk (fromYAML aa) (fromYAML ab) 1957 _ -> fail $ "unhandled tag: " ++ (show t) 1953 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1954 "MkThunk" -> do 1955 let YamlMap assocs = e 1956 let [aa , ab] = map snd assocs 1957 liftM2 MkThunk (fromYAML aa) (fromYAML ab) 1958 _ -> fail $ "unhandled tag: " ++ show t 1959 fromYAML _ = fail "no tag found" 1958 1960 asYAML (MkThunk aa ab) = asYAMLmap "MkThunk" 1959 1961 [("thunkExp", asYAML aa) , ("thunkType", asYAML ab)] 1960 1962 1961 1963 instance YAML VProcess where 1962 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1963 "MkProcess" -> do let YamlSeq [aa] = e 1964 liftM MkProcess (fromYAML aa) 1965 _ -> fail $ "unhandled tag: " ++ (show t) 1964 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1965 "MkProcess" -> do 1966 let YamlSeq [aa] = e 1967 liftM MkProcess (fromYAML aa) 1968 _ -> fail $ "unhandled tag: " ++ show t 1969 fromYAML _ = fail "no tag found" 1966 1970 asYAML (MkProcess aa) = asYAMLseq "MkProcess" [asYAML aa] 1967 1971 1968 1972 instance YAML VRule where 1969 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1970 "MkRulePCRE" -> do let YamlMap assocs = e 1971 let [aa , ab , ac , ad , ae , af] = map snd assocs 1972 liftM6 MkRulePCRE (fromYAML aa) (fromYAML ab) (fromYAML ac) (fromYAML ad) (fromYAML ae) (fromYAML af) 1973 where 1974 liftM6 f m1 m2 m3 m4 m5 m6 = do { x1 <- m1; x2 <- m2; x3 <- m3; x4 <- m4; x5 <- m5; x6 <- m6; return (f x1 x2 x3 x4 x5 x6) } 1975 "MkRulePGE" -> do let YamlMap assocs = e 1976 let [aa , ab , ac , ad] = map snd assocs 1977 liftM4 MkRulePGE (fromYAML aa) (fromYAML ab) (fromYAML ac) (fromYAML ad) 1978 _ -> fail $ "unhandled tag: " ++ (show t) 1973 fromYAML MkYamlNode{tag=Just t, el=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackFS t = case tag of 1974 "MkRulePCRE" -> do 1975 let liftM6 f m1 m2 m3 m4 m5 m6 = do { x1 <- m1; x2 <- m2; x3 <- m3; x4 <- m4; x5 <- m5; x6 <- m6; return (f x1 x2 x3 x4 x5 x6) } 1976 let YamlMap assocs = e 1977 let [aa , ab , ac , ad , ae , af] = map snd assocs 1978 liftM6 MkRulePCRE (fromYAML aa) (fromYAML ab) (fromYAML ac) (fromYAML ad) (fromYAML ae) (fromYAML af) 1979 "MkRulePGE" -> do 1980 let YamlMap assocs = e 1981 let [aa , ab , ac , ad] = map snd assocs 1982 liftM4 MkRulePGE (fromYAML aa) (fromYAML ab) (fromYAML ac) (fromYAML ad) 1983 _ -> fail $ "unhandled tag: " ++ show t 1984 fromYAML _ = fail "no tag found" 1979 1985 asYAML (MkRulePCRE aa ab ac ad ae af) = asYAMLmap "MkRulePCRE" 1980 1986 [("rxRegex", asYAML aa) , ("rxGlobal", asYAML ab) , … … 1986 1992 1987 1993 instance YAML Val where 1988 fromYAML n@MkYamlNode{tag=t, el=e} = case deTag n of 1989 "VUndef" -> return VUndef 1990 "VBool" -> do let YamlSeq [aa] = e 1991 liftM VBool (fromYAML aa) 1992 "VInt" -> do let YamlSeq [aa] = e 1993 liftM VInt (fromYAML aa) 1994 "VRat" -> do let YamlSeq [aa] = e 1995 liftM VRat (fromYAML aa) 1996 "VNum" -> do let YamlSeq [aa] = e 1997 liftM VNum (fromYAML aa) 1998 "VComplex" -> do let YamlSeq [aa] = e 1999 liftM VComplex (fromYAML aa) 2000 "VStr" -> do let YamlSeq [aa] = e 2001 liftM VStr (fromYAML aa) 2002 "VList" -> do let YamlSeq [aa] = e 2003 liftM VList (fromYAML aa) 2004 "VType" -> do let YamlSeq [aa] = e 2005 liftM VType (fromYAML aa) 2006 "VJunc" -> do let YamlSeq [aa] = e 2007 liftM VJunc (fromYAML aa) 2008 "VError" -> do let YamlSeq [aa , ab] = e 2009 liftM2 VError (fromYAML aa) (fromYAML ab) 2010 "VControl"
