@@ -243,14 +243,17 @@ match :: (Show a) => a -> Case.Match () () -> State Int [Statement ()]
243match span mtch =
243match span mtch =
244 case mtch of
244 case mtch of
245 Case.Match name clauses mtch' ->
245 Case.Match name clauses mtch' ->
246− do clauses' <- mapM (clause span name) clauses
246+ do (isChars, clauses') <- unzip <$> mapM (clause span name) clauses
247 mtch'' <- match span mtch'
247 mtch'' <- match span mtch'
248− return (SwitchStmt () (access name) clauses' : mtch'')
248+ return (SwitchStmt () (format isChars (access name)) clauses' : mtch'')
250 isLiteral p = case p of
250 isLiteral p = case p of
251 Case.Clause (Right _) _ _ -> True
251 Case.Clause (Right _) _ _ -> True
252 _ -> False
252 _ -> False
253 access name = if any isLiteral clauses then ref name else dotSep [name,"ctor"]
253 access name = if any isLiteral clauses then ref name else dotSep [name,"ctor"]
255+ | or isChars = InfixExpr () OpAdd e (string "")
255 Case.Fail ->
258 Case.Fail ->
256 return [ ExprStmt () (obj "_E.Case" `call` [ref "$moduleName", string (show span)]) ]
259 return [ ExprStmt () (obj "_E.Case" `call` [ref "$moduleName", string (show span)]) ]
@@ -268,15 +271,18 @@ match span mtch =
268 _ -> dropEnd (acc ++ [m]) ms
271 _ -> dropEnd (acc ++ [m]) ms
270clause span variable (Case.Clause value vars mtch) =
273clause span variable (Case.Clause value vars mtch) =
271− CaseClause () pattern <$> match span (Case.matchSubst (zip vars vars') mtch)
274+ (,) isChar . CaseClause () pattern <$> match span (Case.matchSubst (zip vars vars') mtch)
273 vars' = map (\n -> variable ++ "._" ++ show n) [0..]
276 vars' = map (\n -> variable ++ "._" ++ show n) [0..]
279+ Right (Chr c) -> (True, string [c])
274− pattern = case value of
280+ _ -> (,) False $ case value of
275− Right (Boolean b) -> BoolLit () b
281+ Right (Boolean b) -> BoolLit () b
276− Right lit -> literal lit
282+ Right lit -> literal lit
277− Left name -> string $ case List.elemIndices '.' name of
283+ Left name -> string $ case List.elemIndices '.' name of
278− [] -> name
284+ [] -> name
279− is -> drop (last is + 1) name
285+ is -> drop (last is + 1) name
282jsModule :: MetadataModule () () -> String
288jsModule :: MetadataModule () () -> String