Clean up comments and add function types

This commit is contained in:
Joscha 2017-12-17 09:09:10 +00:00
parent 76378b0add
commit 3af17331f4

View file

@ -133,7 +133,7 @@ yearday day = let (y,m,d) = toGregorian day
in toInteger dayofyear in toInteger dayofyear
{- {-
- Parsing DateExpr - Parsing Expressions
-} -}
-- error ↓ ↓ input -- error ↓ ↓ input
@ -142,7 +142,8 @@ type Parser = Parsec Void String
parseDateExpr :: Parser DateExpr parseDateExpr :: Parser DateExpr
parseDateExpr = boolExpr parseDateExpr = boolExpr
sc :: Parser () -- oddly necessary -- Lexeme parser functions
sc :: Parser ()
sc = L.space space1 empty empty sc = L.space space1 empty empty
symbol :: String -> Parser String symbol :: String -> Parser String
@ -160,11 +161,11 @@ integer = lexeme L.decimal
bool :: Parser Bool bool :: Parser Bool
bool = (True <$ symbol "true") <|> (False <$ symbol "false") bool = (True <$ symbol "true") <|> (False <$ symbol "false")
-- helper functions for creating tables -- Helper functions for creating tables
prefix name f = Prefix (f <$ symbol name) prefix name f = Prefix (f <$ symbol name)
infixL name f = InfixL (f <$ symbol name) infixL name f = InfixL (f <$ symbol name)
-- parse IntExpr -- Parse IntExpr
intExpr :: Parser IntExpr intExpr :: Parser IntExpr
intExpr = makeExprParser intTerm intTable intExpr = makeExprParser intTerm intTable
@ -180,7 +181,7 @@ intTerm = parens intExpr
<|> IDate <$> pSpecialDate <|> IDate <$> pSpecialDate
<?> "integer expression" <?> "integer expression"
-- parse BoolExpr -- Parse BoolExpr
boolExpr :: Parser BoolExpr boolExpr :: Parser BoolExpr
boolExpr = makeExprParser boolTerm boolTable boolExpr = makeExprParser boolTerm boolTable
@ -195,32 +196,37 @@ boolTerm = parens boolExpr
<|> BStatement <$> pDateStatement <|> BStatement <$> pDateStatement
<|> relExpr <|> relExpr
<?> "boolean expression" <?> "boolean expression"
-- comparison (==, <, >, <=, >=)
relExpr :: Parser BoolExpr
relExpr = do relExpr = do
a <- intExpr a <- intExpr
b <- relation b <- relation
c <- intExpr c <- intExpr
return $ b a c return $ b a c
relation :: Parser (IntExpr -> IntExpr -> BoolExpr)
relation = (BEq <$ symbol "==") relation = (BEq <$ symbol "==")
<|> ((\a b -> BNot (BEq a b)) <$ symbol "!=") <|> ((\a b -> BNot (BEq a b)) <$ symbol "!=")
<|> ((\a b -> BNot (BLt a b)) <$ symbol ">=") <|> ((\a b -> BNot (BLt a b)) <$ symbol ">=")
<|> ((\a b -> BNot (BGt a b)) <$ symbol "<=") <|> ((\a b -> BNot (BGt a b)) <$ symbol "<=")
<|> (BGt <$ symbol ">") <|> (BGt <$ symbol ">")
<|> (BLt <$ symbol "<") <|> (BLt <$ symbol "<")
<?> "comparison"
-- Parse SpecialDates and DateStatements
pSpecialDate :: Parser SpecialDate
pSpecialDate = (SJulianDay <$ symbol "julian") pSpecialDate = (SJulianDay <$ symbol "julian")
<|> (SDayOfYear <$ symbol "yearday")
<|> (SYearCount <$ symbol "yearcount") <|> (SYearCount <$ symbol "yearcount")
<|> (SDayOfYear <$ symbol "yearday")
<|> (SYear <$ symbol "year") <|> (SYear <$ symbol "year")
<|> (SMonthCount <$ symbol "monthcount") <|> (SMonthCount <$ symbol "monthcount")
<|> (SMonth <$ symbol "month") <|> (SMonth <$ symbol "month")
<|> (SDay <$ symbol "day") <|> (SDay <$ symbol "day")
<|> (SDayOfWeek <$ symbol "weekday") <|> (SDayOfWeek <$ symbol "weekday")
<|> (SEaster <$ symbol "easter") <|> (SEaster <$ symbol "easter")
<?> "special date" -- necessary? <?> "special date"
pDateStatement :: Parser DateStatement
pDateStatement = (IsWeekend <$ symbol "isweekend") pDateStatement = (IsWeekend <$ symbol "isweekend")
<|> (IsLeapYear <$ symbol "isleapyear") <|> (IsLeapYear <$ symbol "isleapyear")
<?> "date statement" -- necessary? <?> "date statement"