1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
3module CoreParser(parseTerm, parseFile, parseDef, pTerm) 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
39pDef :: Parser (Name, RDef)
40pDef = try (do x <- identifier; lchar ':'; ty <- pTerm
44 return (UN [x], RFunction (RawFun ty tm)))
45 <|> do x <- identifier; lchar ':'; ty <- pTerm; lchar ';'
46 return (UN [x], RConst ty)
48app :: Parser (Raw -> Raw -> Raw)
49app = do whiteSpace ; return RApp
51arrow :: Parser (Raw -> Raw -> Raw)
52arrow = do symbol "->" ; return $ \s t -> RBind (MN 0 "X") (Pi s) t
55pTerm = try (do chainl1 pNoApp app)
59pNoApp = try (chainr1 pExp arrow)
63pExp = do lchar '\\'; x <- identifier; lchar ':'; ty <- pTerm
66 return (RBind (UN [x]) (Lam ty) sc)
67 <|> try (do lchar '?'; x <- identifier; lchar ':'; ty <- pTerm
70 return (RBind (UN [x]) (Lam ty) sc))
71 <|> try (do lchar '(';
72 x <- identifier; lchar ':'; ty <- pTerm
76 return (RBind (UN [x]) (Pi ty) sc))
77 <|> try (do lchar '(';
81 <|> try (do lchar '?';
82 x <- identifier; lchar ':'; ty <- pTerm
85 return (RBind (UN [x]) (Hole ty) sc))
86 <|> try (do symbol "??";
87 x <- identifier; lchar ':'; ty <- pTerm
91 return (RBind (UN [x]) (Guess ty val) sc))
92 <|> try (do reserved "let";
93 x <- identifier; lchar ':'; ty <- pTerm
97 return (RBind (UN [x]) (Let ty val) sc))
98 <|> try (do lchar '_';
99 x <- identifier; lchar ':'; ty <- pTerm
102 return (RBind (UN [x]) (PVar ty) sc))
103 <|> try (do reserved "Set"; i <- natural
104 return (RSet (fromInteger i)))
105 <|> try (do x <- identifier
106 return (Var (UN [x])))
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