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 P.Column Type
28parseNumber = const Number <$> P.string "Number"
30parseString :: P.Parsec String P.Column Type
31parseString = const String <$> P.string "String"
33parseBoolean :: P.Parsec String P.Column Type
34parseBoolean = const Boolean <$> P.string "Boolean"
36parseArray :: P.Parsec String P.Column Type
37parseArray = squares $ Array <$> parseType
39parseObject :: P.Parsec String P.Column Type
40parseObject = braces $ Object <$> parseRow
42parseFunction :: P.Parsec String P.Column Type
44 args <- lexeme $ parens $ commaSep parseType
45 lexeme $ P.string "->"
46 resultType <- parseType
47 return $ Function args resultType
49parseTypeVariable :: P.Parsec String P.Column Type
50parseTypeVariable = TypeVar <$> identifier
52parseTypeConstructor :: P.Parsec String P.Column Type
53parseTypeConstructor = TypeConstructor <$> properName
55parseTypeAtom :: P.Parsec String P.Column Type
56parseTypeAtom = indented *> P.choice (map P.try
64 , parseTypeConstructor
67parsePolyType :: P.Parsec String P.Column PolyType
68parsePolyType = PolyType <$> (P.option [] (indented *> reserved "forall" *> many (indented *> identifier) <* indented <* dot))
71parseType :: P.Parsec String P.Column Type
72parseType = fold (lexeme parseTypeAtom) (lexeme parseTypeAtom) TypeApp
74parseNameAndType :: P.Parsec String P.Column (String, Type)
75parseNameAndType = (,) <$> (indented *> identifier <* indented <* lexeme (P.string "::")) <*> parseType
77parseRowEnding :: P.Parsec String P.Column Row
78parseRowEnding = P.option REmpty (RowVar <$> (lexeme (indented *> P.char '|') *> indented *> identifier))
80parseRow :: P.Parsec String P.Column Row
81parseRow = fromList <$> (parseNameAndType `P.sepBy` (indented *> semi)) <*> 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