1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
3module CoreParser(parseTerm, parseFile, parseDef, pTerm, iName) where
7import Text.ParserCombinators.Parsec
8import Text.ParserCombinators.Parsec.Expr
9import Text.ParserCombinators.Parsec.Language
10import qualified Text.ParserCombinators.Parsec.Token as PTok
14type TokenParser a = PTok.TokenParser a
16lexer :: TokenParser ()
17lexer = PTok.makeTokenParser haskellDef
19whiteSpace= PTok.whiteSpace lexer
20lexeme = PTok.lexeme lexer
21symbol = PTok.symbol lexer
22natural = PTok.natural lexer
23parens = PTok.parens lexer
25comma = PTok.comma lexer
26identifier= PTok.identifier lexer
27reserved = PTok.reserved lexer
28operator = PTok.operator lexer
29reservedOp= PTok.reservedOp lexer
32parseFile = parse pTestFile "(input)"
33parseDef = parse pDef "(input)"
34parseTerm = parse pTerm "(input)"
36pTestFile :: Parser RProgram
40iName = identifier >>= (\n -> return (UN [n]))
42pDef :: Parser (Name, RDef)
43pDef = try (do x <- iName; lchar ':'; ty <- pTerm
47 return (x, RFunction (RawFun ty tm)))
48 <|> do x <- iName; lchar ':'; ty <- pTerm; lchar ';'
51app :: Parser (Raw -> Raw -> Raw)
52app = do whiteSpace ; return RApp
54arrow :: Parser (Raw -> Raw -> Raw)
55arrow = do symbol "->" ; return $ \s t -> RBind (MN 0 "X") (Pi s) t
58pTerm = try (do chainl1 pNoApp app)
62pNoApp = try (chainr1 pExp arrow)
66pExp = do lchar '\\'; x <- iName; lchar ':'; ty <- pTerm
69 return (RBind x (Lam ty) sc)
70 <|> try (do lchar '?'; x <- iName; lchar ':'; ty <- pTerm
73 return (RBind x (Lam ty) sc))
74 <|> try (do lchar '(';
75 x <- iName; lchar ':'; ty <- pTerm
79 return (RBind x (Pi ty) sc))
80 <|> try (do lchar '(';
84 <|> try (do lchar '?';
85 x <- iName; lchar ':'; ty <- pTerm
88 return (RBind x (Hole ty) sc))
89 <|> try (do symbol "??";
90 x <- iName; lchar ':'; ty <- pTerm
94 return (RBind x (Guess ty val) sc))
95 <|> try (do reserved "let";
96 x <- iName; lchar ':'; ty <- pTerm
100 return (RBind x (Let ty val) sc))
101 <|> try (do lchar '_';
102 x <- iName; lchar ':'; ty <- pTerm
105 return (RBind x (PVar ty) sc))
106 <|> try (do reserved "Set"; i <- natural
107 return (RSet (fromInteger i)))
108 <|> try (do x <- iName
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list