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
29import qualified Text.Parsec.Indent as I
31import PureScript.Values
32import PureScript.Types
33import PureScript.Parser.Common
34import PureScript.Declarations
35import PureScript.Parser.Values
36import PureScript.Parser.Types
38parseDataDeclaration :: I.IndentParser String () Declaration
39parseDataDeclaration = do
42 tyArgs <- many identifier
44 ctors <- P.sepBy1 ((,) <$> properName <*> P.optionMaybe parseType) (lexeme $ P.char '|')
45 return $ DataDeclaration name tyArgs ctors
47parseTypeDeclaration :: I.IndentParser String () Declaration
48parseTypeDeclaration = TypeDeclaration <$> parseIdent <*> (lexeme (P.string "::") *> parsePolyType)
50parseTypeSynonymDeclaration :: I.IndentParser String () Declaration
51parseTypeSynonymDeclaration = TypeSynonymDeclaration <$> (reserved "type" *> properName) <*> many identifier <*> (lexeme (P.char '=') *> parseType)
53parseValueDeclaration :: I.IndentParser String () Declaration
54parseValueDeclaration = ValueDeclaration <$> parseIdent <*> (lexeme (P.char '=') *> parseValue)
56parseExternDeclaration :: I.IndentParser String () Declaration
57parseExternDeclaration = ExternDeclaration <$> (reserved "extern" *> parseIdent) <*> (lexeme (P.string "::") *> parsePolyType)
59parseDeclaration :: I.IndentParser String () Declaration
60parseDeclaration = P.choice $ map P.try
61 [ parseDataDeclaration
62 , parseTypeDeclaration
63 , parseTypeSynonymDeclaration
64 , parseValueDeclaration
65 , parseExternDeclaration ]
67parseManyDeclarations :: I.IndentParser String () [Declaration]
68parseManyDeclarations = I.block $ I.withPos parseDeclaration
70parseDeclarations :: String -> Either P.ParseError [Declaration]
71parseDeclarations = flip evalState (P.initialPos "Declarations") . P.runPT parseManyDeclarations () "Declarations"
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