1-----------------------------------------------------------------------------
3-- Module : PureScript.Parser.Common
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
15module PureScript.Parser.Common where
17import Control.Applicative
18import qualified Text.Parsec as P
19import qualified Text.Parsec.Token as PT
20import qualified Text.Parsec.Language as PL
22import PureScript.Names
24langDef = PL.haskellStyle
25 { PT.identStart = P.lower <|> P.char '_'
26 , PT.reservedNames = [ "case"
40 , PT.reservedOpNames = [ "!", "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "<<", ">>>", ">>"
41 , "==", "!=", "&", "^", "|", "&&", "||" ]
44tokenParser = PT.makeTokenParser langDef
45lexeme = PT.lexeme tokenParser
46identifier = PT.identifier tokenParser
47reserved = PT.reserved tokenParser
48operator = PT.operator tokenParser
49stringLiteral = PT.stringLiteral tokenParser
50natural = PT.natural tokenParser
51naturalOrFloat = PT.naturalOrFloat tokenParser
52whiteSpace = PT.whiteSpace tokenParser
53parens = PT.parens tokenParser
54braces = PT.braces tokenParser
55angles = PT.angles tokenParser
56brackets = PT.brackets tokenParser
57squares = PT.squares tokenParser
58semi = PT.semi tokenParser
59comma = PT.comma tokenParser
60colon = PT.colon tokenParser
61dot = PT.dot tokenParser
62semiSep = PT.semiSep tokenParser
63semiSep1 = PT.semiSep1 tokenParser
64commaSep = PT.commaSep tokenParser
65commaSep1 = PT.commaSep1 tokenParser
67tick = lexeme (P.char '`')
69properName :: P.Parsec String u String
70properName = lexeme $ P.try properName'
72 properName' = (:) <$> P.upper <*> many (PT.identLetter langDef) P.<?> "name"
74augment :: P.Stream s m t => P.ParsecT s u m a -> P.ParsecT s u m b -> (a -> b -> a) -> P.ParsecT s u m a
75augment p q f = (flip $ maybe id $ flip f) <$> p <*> P.optionMaybe q
77fold :: P.Stream s m t => P.ParsecT s u m a -> P.ParsecT s u m b -> (a -> b -> a) -> P.ParsecT s u m a
78fold first more combine = do
81 return $ foldl combine a bs
83parseIdent :: P.Parsec String () Ident
84parseIdent = (Ident <$> identifier) <|> (Op <$> parens operator)
86parseIdentInfix :: P.Parsec String () Ident
87parseIdentInfix = (Ident <$> P.between tick tick identifier) <|> (Op <$> operator)
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