1-----------------------------------------------------------------------------
3-- Module : PureScript.Parser.Types
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
15module PureScript.Parser.Types (
21import PureScript.Types
22import PureScript.Parser.Common
23import Control.Applicative
24import qualified Text.Parsec as P
25import Control.Arrow (Arrow(..))
27parseNumber :: P.Parsec String () Type
28parseNumber = const Number <$> P.string "Number"
30parseString :: P.Parsec String () Type
31parseString = const String <$> P.string "String"
33parseBoolean :: P.Parsec String () Type
34parseBoolean = const Boolean <$> P.string "Boolean"
36parseArray :: P.Parsec String () Type
37parseArray = squares $ Array <$> parseType
39parseObject :: P.Parsec String () Type
40parseObject = braces $ Object <$> parseRow
42parseFunction :: P.Parsec String () Type
44 args <- lexeme $ parens $ commaSep parseType
45 lexeme $ P.string "->"
46 resultType <- parseType
47 return $ Function args resultType
49parseTypeVariable :: P.Parsec String () Type
50parseTypeVariable = TypeVar <$> identifier
52parseTypeConstructor :: P.Parsec String () Type
53parseTypeConstructor = TypeConstructor <$> properName
55parseTypeAtom :: P.Parsec String () Type
56parseTypeAtom = P.choice $ map P.try
64 , parseTypeConstructor
67parsePolyType :: P.Parsec String () PolyType
68parsePolyType = PolyType <$> (P.option [] (reserved "forall" *> many identifier <* dot))
71parseType :: P.Parsec String () Type
72parseType = fold (lexeme parseTypeAtom) (lexeme parseTypeAtom) TypeApp
74parseNameAndType :: P.Parsec String () (String, Type)
75parseNameAndType = (,) <$> (identifier <* lexeme (P.string "::")) <*> parseType
77parseRowEnding :: P.Parsec String () Row
78parseRowEnding = P.option REmpty (RowVar <$> (lexeme (P.char '|') *> identifier))
80parseRow :: P.Parsec String () Row
81parseRow = fromList <$> semiSep parseNameAndType <*> parseRowEnding
83 fromList :: [(String, Type)] -> Row -> Row
85 fromList ((name, t):ts) r = RCons name t (fromList ts r)
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