1-----------------------------------------------------------------------------
3-- Module : PureScript.Parser.Declarations
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
15module PureScript.Parser.Declarations (
24import Control.Applicative
25import Control.Arrow (Arrow(..))
26import Control.Monad.State
27import qualified Text.Parsec as P
28import qualified Text.Parsec.Pos as P
30import PureScript.Values
31import PureScript.Types
32import PureScript.Parser.Common
33import PureScript.Declarations
34import PureScript.Parser.Values
35import PureScript.Parser.Types
37parseDataDeclaration :: P.Parsec String P.Column Declaration
38parseDataDeclaration = do
40 name <- indented *> properName
41 tyArgs <- many (indented *> identifier)
42 lexeme $ indented *> P.char '='
43 ctors <- P.sepBy1 ((,) <$> (indented *> properName) <*> P.optionMaybe parseType) (lexeme $ indented *> P.char '|')
44 return $ DataDeclaration name tyArgs ctors
46parseTypeDeclaration :: P.Parsec String P.Column Declaration
48 TypeDeclaration <$> parseIdent
49 <*> (lexeme (indented *> P.string "::") *> parsePolyType)
51parseTypeSynonymDeclaration :: P.Parsec String P.Column Declaration
52parseTypeSynonymDeclaration =
53 TypeSynonymDeclaration <$> (reserved "type" *> indented *> properName)
54 <*> many (indented *> identifier)
55 <*> (lexeme (indented *> P.char '=') *> parseType)
57parseValueDeclaration :: P.Parsec String P.Column Declaration
58parseValueDeclaration =
59 ValueDeclaration <$> parseIdent
60 <*> (lexeme (indented *> P.char '=') *> parseValue)
62parseExternDeclaration :: P.Parsec String P.Column Declaration
63parseExternDeclaration =
64 ExternDeclaration <$> (reserved "extern" *> indented *> parseIdent)
65 <*> (lexeme (indented *> P.string "::") *> parsePolyType)
67parseDeclaration :: P.Parsec String P.Column Declaration
68parseDeclaration = P.choice $ map P.try
69 [ parseDataDeclaration
70 , parseTypeDeclaration
71 , parseTypeSynonymDeclaration
72 , parseValueDeclaration
73 , parseExternDeclaration ]
75parseDeclarations :: P.Parsec String P.Column [Declaration]
76parseDeclarations = whiteSpace *> mark (same *> P.many parseDeclaration) <* P.eof
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