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 qualified Text.Parsec as P
26import Control.Arrow (Arrow(..))
28import PureScript.Values
29import PureScript.Types
30import PureScript.Parser.Common
31import PureScript.Declarations
32import PureScript.Parser.Values
33import PureScript.Parser.Types
35parseDataDeclaration :: P.Parsec String () Declaration
36parseDataDeclaration = do
39 tyArgs <- many identifier
41 ctors <- P.sepBy1 ((,) <$> properName <*> P.optionMaybe parseType) (lexeme $ P.char '|')
42 return $ DataDeclaration name tyArgs ctors
44parseTypeDeclaration :: P.Parsec String () Declaration
45parseTypeDeclaration = TypeDeclaration <$> parseIdent <*> (lexeme (P.string "::") *> parsePolyType)
47parseTypeSynonymDeclaration :: P.Parsec String () Declaration
48parseTypeSynonymDeclaration = TypeSynonymDeclaration <$> (reserved "type" *> properName) <*> many identifier <*> (lexeme (P.char '=') *> parseType)
50parseValueDeclaration :: P.Parsec String () Declaration
51parseValueDeclaration = ValueDeclaration <$> parseIdent <*> (lexeme (P.char '=') *> parseValue)
53parseExternDeclaration :: P.Parsec String () Declaration
54parseExternDeclaration = ExternDeclaration <$> (reserved "extern" *> parseIdent) <*> (lexeme (P.string "::") *> parsePolyType)
56parseDeclaration :: P.Parsec String () Declaration
57parseDeclaration = P.choice $ map P.try
58 [ parseDataDeclaration
59 , parseTypeDeclaration
60 , parseTypeSynonymDeclaration
61 , parseValueDeclaration
62 , parseExternDeclaration ]
64parseDeclarations :: String -> Either P.ParseError [Declaration]
65parseDeclarations = fmap catMaybes . mapM (P.parse (whiteSpace *> (P.optionMaybe parseDeclaration <* whiteSpace) <* P.eof) "Declaration") . splitFileIntoDeclarations
67isIndented :: String -> Bool
68isIndented = any isSpace . take 1
70splitFileIntoDeclarations :: String -> [String]
71splitFileIntoDeclarations = reverse . map (dropWhile isSpace . unlines . reverse) . go [] [] . lines
76 | all isSpace s = go ss sss rest
77 | isIndented s = go (s:ss) sss rest
78 | null ss = go [s] sss rest
79 | otherwise = go [s] (ss:sss) rest
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