@@ -16,14 +16,11 @@
17module Language.PureScript.Parser.Common where
17module Language.PureScript.Parser.Common where
19−import Data.Char (isSpace)
19+import Data.Functor.Identity
20import Control.Applicative
20import Control.Applicative
21import Control.Monad
21import Control.Monad
22−import Control.Monad.State
23import Language.PureScript.Parser.State
22import Language.PureScript.Parser.State
24−import qualified Data.Map as M
25import qualified Text.Parsec as P
23import qualified Text.Parsec as P
26−import qualified Text.Parsec.Pos as P
27import qualified Text.Parsec.Token as PT
24import qualified Text.Parsec.Token as PT
29import Language.PureScript.Names
26import Language.PureScript.Names
@@ -77,7 +74,7 @@ reservedNames = [ "case"
78builtInOperators :: [String]
75builtInOperators :: [String]
79builtInOperators = [ "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "<<", ">>>", ">>"
76builtInOperators = [ "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "<<", ">>>", ">>"
80− , "==", "!=", "&&", "||", "&", "^", "|", "!!", "!" ]
77+ , "==", "!=", "&&", "||", "&", "^", "|", "!!", "!", ":" ]
82reservedOpNames :: [String]
79reservedOpNames :: [String]
83reservedOpNames = builtInOperators ++ [ "->" ]
80reservedOpNames = builtInOperators ++ [ "->" ]
@@ -92,11 +89,12 @@ identLetter :: P.Parsec String u Char
92identLetter = P.alphaNum <|> P.oneOf "_'"
89identLetter = P.alphaNum <|> P.oneOf "_'"
94opStart :: P.Parsec String u Char
91opStart :: P.Parsec String u Char
95−opStart = P.oneOf "!#$%&*+/<=>?@^|~"
92+opStart = P.oneOf "!#$%&*+/<=>?@^|~:"
97opLetter :: P.Parsec String u Char
94opLetter :: P.Parsec String u Char
98opLetter = P.oneOf ":#$%&*+./<=>?@^|"
95opLetter = P.oneOf ":#$%&*+./<=>?@^|"
97+langDef :: PT.GenLanguageDef String u Identity
100langDef = PT.LanguageDef
98langDef = PT.LanguageDef
101 { PT.reservedNames = reservedNames
99 { PT.reservedNames = reservedNames
102 , PT.reservedOpNames = reservedOpNames
100 , PT.reservedOpNames = reservedOpNames
@@ -111,36 +109,80 @@ langDef = PT.LanguageDef
111 , PT.caseSensitive = True
109 , PT.caseSensitive = True
112+tokenParser :: PT.GenTokenParser String u Identity
114tokenParser = PT.makeTokenParser langDef
113tokenParser = PT.makeTokenParser langDef
116−lexeme = PT.lexeme tokenParser
115+lexeme :: P.Parsec String u a -> P.Parsec String u a
117−identifier = PT.identifier tokenParser
118−reserved = PT.reserved tokenParser
119−reservedOp = PT.reservedOp tokenParser
120−operator = PT.operator tokenParser
121−stringLiteral = PT.stringLiteral tokenParser
122−whiteSpace = PT.whiteSpace tokenParser
123−squares = PT.squares tokenParser
124−semi = PT.semi tokenParser
125−comma = PT.comma tokenParser
126−colon = PT.colon tokenParser
127−dot = PT.dot tokenParser
128−natural = PT.natural tokenParser
116+lexeme = PT.lexeme tokenParser
118+identifier :: P.Parsec String u String
119+identifier = PT.identifier tokenParser
121+reserved :: String -> P.Parsec String u ()
122+reserved = PT.reserved tokenParser
124+reservedOp :: String -> P.Parsec String u ()
125+reservedOp = PT.reservedOp tokenParser
127+operator :: P.Parsec String u String
128+operator = PT.operator tokenParser
130+stringLiteral :: P.Parsec String u String
131+stringLiteral = PT.stringLiteral tokenParser
133+whiteSpace :: P.Parsec String u ()
134+whiteSpace = PT.whiteSpace tokenParser
136+semi :: P.Parsec String u String
137+semi = PT.semi tokenParser
139+colon :: P.Parsec String u String
140+colon = PT.colon tokenParser
142+dot :: P.Parsec String u String
143+dot = PT.dot tokenParser
145+comma :: P.Parsec String u String
146+comma = PT.comma tokenParser
148+tick :: P.Parsec String u Char
149+tick = lexeme $ P.char '`'
151+pipe :: P.Parsec String u Char
152+pipe = lexeme $ P.char '|'
154+natural :: P.Parsec String u Integer
155+natural = PT.natural tokenParser
157+squares :: P.Parsec String ParseState a -> P.Parsec String ParseState a
158+squares = P.between (lexeme $ P.char '[') (lexeme $ indented *> P.char ']') . (indented *>)
160+parens :: P.Parsec String ParseState a -> P.Parsec String ParseState a
130parens = P.between (lexeme $ P.char '(') (lexeme $ indented *> P.char ')') . (indented *>)
161parens = P.between (lexeme $ P.char '(') (lexeme $ indented *> P.char ')') . (indented *>)
163+braces :: P.Parsec String ParseState a -> P.Parsec String ParseState a
131braces = P.between (lexeme $ P.char '{') (lexeme $ indented *> P.char '}') . (indented *>)
164braces = P.between (lexeme $ P.char '{') (lexeme $ indented *> P.char '}') . (indented *>)
166+angles :: P.Parsec String ParseState a -> P.Parsec String ParseState a
132angles = P.between (lexeme $ P.char '<') (lexeme $ indented *> P.char '>') . (indented *>)
167angles = P.between (lexeme $ P.char '<') (lexeme $ indented *> P.char '>') . (indented *>)
169+sepBy :: P.Parsec String ParseState a -> P.Parsec String ParseState sep -> P.Parsec String ParseState [a]
134sepBy p s = P.sepBy (indented *> p) (indented *> s)
170sepBy p s = P.sepBy (indented *> p) (indented *> s)
172+sepBy1 :: P.Parsec String ParseState a -> P.Parsec String ParseState sep -> P.Parsec String ParseState [a]
135sepBy1 p s = P.sepBy1 (indented *> p) (indented *> s)
173sepBy1 p s = P.sepBy1 (indented *> p) (indented *> s)
137−semiSep = flip sepBy semi
175+semiSep :: P.Parsec String ParseState a -> P.Parsec String ParseState [a]
138−semiSep1 = flip sepBy1 semi
176+semiSep = flip sepBy semi
139−commaSep = flip sepBy comma
140−commaSep1 = flip sepBy1 comma
142−tick = lexeme $ P.char '`'
178+semiSep1 :: P.Parsec String ParseState a -> P.Parsec String ParseState [a]
143−pipe = lexeme $ P.char '|'
179+semiSep1 = flip sepBy1 semi
181+commaSep :: P.Parsec String ParseState a -> P.Parsec String ParseState [a]
182+commaSep = flip sepBy comma
184+commaSep1 :: P.Parsec String ParseState a -> P.Parsec String ParseState [a]
185+commaSep1 = flip sepBy1 comma
145properName :: P.Parsec String u ProperName
187properName :: P.Parsec String u ProperName
146properName = lexeme $ ProperName <$> P.try ((:) <$> P.upper <*> many (PT.identLetter langDef) P.<?> "name")
188properName = lexeme $ ProperName <$> P.try ((:) <$> P.upper <*> many (PT.identLetter langDef) P.<?> "name")