1--parse type and data constructors
2module TutorialD.Interpreter.Types where
4import Text.Parsec.String
6import TutorialD.Interpreter.Base
7import ProjectM36.DataTypes.Primitive
8import Control.Monad (liftM)
9import qualified Data.Text as T
11-- | Upper case names are type names while lower case names are polymorphic typeconstructor arguments.
12-- data *Either a b* = Left a | Right b
13typeConstructorDefP :: Parser TypeConstructorDef
14typeConstructorDefP = ADTypeConstructorDef <$> liftM T.pack capitalizedIdentifier <*> typeVarNamesP
16typeVarNamesP :: Parser [TypeVarName]
18 vars <- many uncapitalizedIdentifier
19 pure (map T.pack vars)
21-- data Either a b = *Left a* | *Right b*
22dataConstructorDefP :: Parser DataConstructorDef
23dataConstructorDefP = DataConstructorDef <$> liftM T.pack identifier <*> many dataConstructorDefArgP
25-- data *Either a b* = Left *a* | Right *b*
26dataConstructorDefArgP :: Parser DataConstructorDefArg
27dataConstructorDefArgP = parens (DataConstructorDefTypeConstructorArg <$> typeConstructorP) <|>
28 DataConstructorDefTypeVarNameArg <$> liftM T.pack uncapitalizedIdentifier
30--built-in, nullary type constructors
32primitiveTypeConstructorP :: Parser TypeConstructor
33primitiveTypeConstructorP = choice (map (\(PrimitiveTypeConstructorDef name typ, _) -> do
34 tName <- liftM T.pack (symbol (T.unpack name))
35 pure $ PrimitiveTypeConstructor tName typ)
36 primitiveTypeConstructorMapping)
38-- *Either Int Text*, *Int*
39typeConstructorP :: Parser TypeConstructor
40typeConstructorP = primitiveTypeConstructorP <|>
41 ADTypeConstructor <$> liftM T.pack identifier <*> many typeConstructorArgP
43typeConstructorArgP :: Parser TypeConstructorArg
44typeConstructorArgP = TypeConstructorArg <$> typeConstructorP <|>
45 TypeConstructorTypeVarArg <$> liftM T.pack uncapitalizedIdentifier
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