Skip to content

Commit

Permalink
Fixed some -Wall warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoerdvisscher committed Oct 24, 2009
1 parent c1832b6 commit 9ce0846
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
10 changes: 5 additions & 5 deletions Moiell/Globals.hs
Expand Up @@ -56,21 +56,21 @@ eachS :: Moiell c => c
eachS = eachC (\body -> eachC (\arg -> body `apply` arg))

filterS :: Moiell c => c
filterS = eachC (\arg -> eachC (\test -> split empty (\h t -> arg) (test `apply` arg)))
filterS = eachC (\arg -> eachC (\test -> split empty (\_ _ -> arg) (test `apply` arg)))

notS, andS, orS :: Moiell c => c
notS = liftC $ split unit (\h t -> empty) getArg
andS = liftC $ liftC $ split empty (\h t -> getArg) $ inParent getArg
notS = liftC $ split unit (\_ _ -> empty) getArg
andS = liftC $ liftC $ split empty (\_ _ -> getArg) $ inParent getArg
orS = liftC $ liftC $ split getArg (\h t -> csum [h, t]) $ inParent getArg

filterN2 :: Moiell c => (Double -> Double -> Bool) -> c
filterN2 op = eachCN (\a -> eachCN (\b -> if op a b then number a else empty))

headS :: Moiell c => c
headS = liftC $ split empty (\h t -> h) getArg
headS = liftC $ split empty (\h _ -> h) getArg

tailS :: Moiell c => c
tailS = liftC $ split empty (\h t -> t) getArg
tailS = liftC $ split empty (\_ t -> t) getArg

charsS :: Moiell c => c
charsS = eachCS $ csum . map (string . (:[]))
Expand Down
25 changes: 10 additions & 15 deletions Moiell/Parser.hs
Expand Up @@ -42,14 +42,13 @@ infixSeq' f prec = do
infixOperator :: ParserForAST
infixOperator = try (inOptWS commaToken) <|> try (inWS dotInfixExpr) <?> "infix operator"

compactExpr, dotInfixExpr, postfixExpr, prefixExpr, bracketPostfixExpr :: ParserForAST
compactExpr = commaToken <|> dotInfixExpr <?> "compact expression"
dotInfixExpr, postfixExpr, prefixExpr, bracketPostfixExpr :: ParserForAST
dotInfixExpr = postfixExpr `chainl1` (flip mkApp <$ simpleToken Dot) <?> "dot expression"
postfixExpr = mkPostfixApp <$> prefixExpr <*> optional identToken <?> "postfix expression"
prefixExpr = try (mkPrefixApp <$> identToken <*> bracketPostfixExpr) <|> bracketPostfixExpr <?> "prefix expression"
bracketPostfixExpr = foldl bracketPostfix <$> atomExpr <*> many bracketExpr <?> "bracket postfix expression"

atomExpr, bracketExpr, indentBlock, seqSeparator :: ParserForAST
atomExpr, bracketExpr, indentBlock, seqSeparator, commaToken :: ParserForAST
atomExpr = choice [bracketExpr, atomToken, identToken, indentBlock]
bracketExpr = choice [brackets '(' ')', brackets '{' '}', brackets '[' ']'] <?> "bracket expression"
indentBlock = between (simpleToken Indent) (simpleToken Unindent) exprs <?> "indentation block"
Expand All @@ -74,26 +73,22 @@ mmaybe :: (Alternative m, Monad m) => m a -> m b -> (a -> m b) ->
mmaybe p a f = optional p >>= maybe a f

mkTokenParser :: ((SourcePos, Token) -> Maybe AST) -> ParserForAST
mkTokenParser testTok
= token showTok posFromTok testTok
where
showTok (pos,t) = show t
posFromTok (pos,t) = pos
mkTokenParser testTok = token (show . snd) fst testTok

simpleToken :: Token -> ParserForAST
simpleToken x = mkTokenParser (\(pos,t) -> if x == t then Just [] else Nothing)
simpleToken x = mkTokenParser (\(_, t) -> if x == t then Just [] else Nothing)

atomToken :: ParserForAST
atomToken = mkTokenParser testTok where
testTok (pos, CharTok c) = Just [StringLit [c]]
testTok (pos, StringTok c) = Just [StringLit c]
testTok (pos, NumberTok c) = Just [NumberLit c]
testTok (pos, _) = Nothing
testTok (_, CharTok c) = Just [StringLit [c]]
testTok (_, StringTok c) = Just [StringLit c]
testTok (_, NumberTok c) = Just [NumberLit c]
testTok (_, _) = Nothing

identToken :: ParserForAST
identToken = mkTokenParser testTok where
testTok (pos, IdentTok c) = Just [Ident c]
testTok (pos, _) = Nothing
testTok (_, IdentTok c) = Just [Ident c]
testTok (_, _) = Nothing

precedence :: AST -> Integer
precedence [Ident "*"] = 120
Expand Down
9 changes: 4 additions & 5 deletions Moiell/Serialize.hs
@@ -1,7 +1,6 @@
module Moiell.Serialize where

import Moiell.Class
import Moiell.Expr

import Data.Monoid
import qualified Data.Map as Map
Expand All @@ -27,9 +26,9 @@ instance Moiell Src where
apply f x = A f x

-- Create call-by-value functions.
eachC f = one $ "eachC(c -> c)"
eachCS f = one $ "eachCS(String -> c)"
eachCN f = one $ "eachCN(Double -> c)"
eachC _ = one $ "eachC(c -> c)"
eachCS _ = one $ "eachCS(String -> c)"
eachCN _ = one $ "eachCN(Double -> c)"

-- The empty sequence.
empty = mempty
Expand All @@ -39,7 +38,7 @@ instance Moiell Src where
-- an empty value
-- a function taking head and tail computations
-- the computation to eliminate
split e ht c = one $ "split" ++ showInBrackets c
split _ _ c = one $ "split" ++ showInBrackets c

-- Throw catchable errors.
throw e = one $ "throw" ++ showInBrackets e
Expand Down

0 comments on commit 9ce0846

Please sign in to comment.