Skip to content

Commit fa89354

Browse files
committed
Initial work on purescript#518
1 parent 2881a5b commit fa89354

25 files changed

Lines changed: 247 additions & 226 deletions

hierarchy/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ superClasses :: P.Declaration -> [SuperMap]
8484
superClasses (P.TypeClassDeclaration sub _ supers@(_:_) _) =
8585
fmap (\(P.Qualified _ super, _) -> SuperMap (Right (super, sub))) supers
8686
superClasses (P.TypeClassDeclaration sub _ _ _) = [SuperMap (Left sub)]
87-
superClasses (P.PositionedDeclaration _ decl) = superClasses decl
87+
superClasses (P.PositionedDeclaration _ _ decl) = superClasses decl
8888
superClasses _ = []
8989

9090
inputFile :: Parser FilePath

psc-docs/Main.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ renderDeclaration n _ (P.TypeInstanceDeclaration name constraints className tys
152152
[] -> ""
153153
cs -> "(" ++ intercalate ", " (map (\(pn, tys') -> show pn ++ " " ++ unwords (map P.prettyPrintTypeAtom tys')) cs) ++ ") => "
154154
atIndent n $ "instance " ++ show name ++ " :: " ++ constraintsText ++ show className ++ " " ++ unwords (map P.prettyPrintTypeAtom tys)
155-
renderDeclaration n exps (P.PositionedDeclaration _ d) =
155+
renderDeclaration n exps (P.PositionedDeclaration _ _ d) =
156156
renderDeclaration n exps d
157157
renderDeclaration _ _ _ = return ()
158158

@@ -176,30 +176,30 @@ getName (P.ExternDataDeclaration name _) = P.runProperName name
176176
getName (P.TypeSynonymDeclaration name _ _) = P.runProperName name
177177
getName (P.TypeClassDeclaration name _ _ _) = P.runProperName name
178178
getName (P.TypeInstanceDeclaration name _ _ _ _) = show name
179-
getName (P.PositionedDeclaration _ d) = getName d
179+
getName (P.PositionedDeclaration _ _ d) = getName d
180180
getName _ = error "Invalid argument to getName"
181181

182182
isValueDeclaration :: P.Declaration -> Bool
183183
isValueDeclaration P.TypeDeclaration{} = True
184184
isValueDeclaration P.ExternDeclaration{} = True
185-
isValueDeclaration (P.PositionedDeclaration _ d) = isValueDeclaration d
185+
isValueDeclaration (P.PositionedDeclaration _ _ d) = isValueDeclaration d
186186
isValueDeclaration _ = False
187187

188188
isTypeDeclaration :: P.Declaration -> Bool
189189
isTypeDeclaration P.DataDeclaration{} = True
190190
isTypeDeclaration P.ExternDataDeclaration{} = True
191191
isTypeDeclaration P.TypeSynonymDeclaration{} = True
192-
isTypeDeclaration (P.PositionedDeclaration _ d) = isTypeDeclaration d
192+
isTypeDeclaration (P.PositionedDeclaration _ _ d) = isTypeDeclaration d
193193
isTypeDeclaration _ = False
194194

195195
isTypeClassDeclaration :: P.Declaration -> Bool
196196
isTypeClassDeclaration P.TypeClassDeclaration{} = True
197-
isTypeClassDeclaration (P.PositionedDeclaration _ d) = isTypeClassDeclaration d
197+
isTypeClassDeclaration (P.PositionedDeclaration _ _ d) = isTypeClassDeclaration d
198198
isTypeClassDeclaration _ = False
199199

200200
isTypeInstanceDeclaration :: P.Declaration -> Bool
201201
isTypeInstanceDeclaration P.TypeInstanceDeclaration{} = True
202-
isTypeInstanceDeclaration (P.PositionedDeclaration _ d) = isTypeInstanceDeclaration d
202+
isTypeInstanceDeclaration (P.PositionedDeclaration _ _ d) = isTypeInstanceDeclaration d
203203
isTypeInstanceDeclaration _ = False
204204

205205
inputFile :: Parser FilePath

psci/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ completion = completeWordWithPrev Nothing " \t\n\r" findCompletions
244244
getDeclName :: Maybe [P.DeclarationRef] -> P.Declaration -> Maybe P.Ident
245245
getDeclName exts (P.ValueDeclaration ident _ _ _) | isExported ident exts = Just ident
246246
getDeclName exts (P.ExternDeclaration _ ident _ _) | isExported ident exts = Just ident
247-
getDeclName exts (P.PositionedDeclaration _ d) = getDeclName exts d
247+
getDeclName exts (P.PositionedDeclaration _ _ d) = getDeclName exts d
248248
getDeclName _ _ = Nothing
249249

250250
isExported :: N.Ident -> Maybe [P.DeclarationRef] -> Bool
251251
isExported ident = maybe True (any exports)
252252
where
253253
exports :: P.DeclarationRef -> Bool
254254
exports (P.ValueRef ident') = ident == ident'
255-
exports (P.PositionedDeclarationRef _ r) = exports r
255+
exports (P.PositionedDeclarationRef _ _ r) = exports r
256256
exports _ = False
257257

258258
identNames :: [P.Module] -> [String]

src/Language/PureScript.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ addDefaultImport toImport m@(Module mn decls exps) =
239239
else Module mn (ImportDeclaration toImport Unqualified Nothing : decls) exps
240240
where
241241
isExistingImport (ImportDeclaration mn' _ _) | mn' == toImport = True
242-
isExistingImport (PositionedDeclaration _ d) = isExistingImport d
242+
isExistingImport (PositionedDeclaration _ _ d) = isExistingImport d
243243
isExistingImport _ = False
244244

245245
importPrim :: Module -> Module

src/Language/PureScript/AST/Binders.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import qualified Data.Data as D
2020

2121
import Language.PureScript.AST.SourcePos
2222
import Language.PureScript.Names
23+
import Language.PureScript.Parser.Lexer
2324

2425
-- |
2526
-- Data type for binders
@@ -68,7 +69,7 @@ data Binder
6869
-- |
6970
-- A binder with source position information
7071
--
71-
| PositionedBinder SourceSpan Binder deriving (Show, D.Data, D.Typeable)
72+
| PositionedBinder SourceSpan [Comment] Binder deriving (Show, D.Data, D.Typeable)
7273

7374
-- |
7475
-- Collect all names introduced in binders in an expression
@@ -82,5 +83,5 @@ binderNames = go []
8283
go ns (ArrayBinder bs) = foldl go ns bs
8384
go ns (ConsBinder b1 b2) = go (go ns b1) b2
8485
go ns (NamedBinder name b) = go (name : ns) b
85-
go ns (PositionedBinder _ b) = go ns b
86+
go ns (PositionedBinder _ _ b) = go ns b
8687
go ns _ = ns

src/Language/PureScript/AST/Declarations.hs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Language.PureScript.Types
2525
import Language.PureScript.Names
2626
import Language.PureScript.Kinds
2727
import Language.PureScript.TypeClassDictionaries
28+
import Language.PureScript.Parser.Lexer
2829
import Language.PureScript.CodeGen.JS.AST
2930
import Language.PureScript.Environment
3031

@@ -40,7 +41,7 @@ data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving
4041
isExported :: Maybe [DeclarationRef] -> Declaration -> Bool
4142
isExported Nothing _ = True
4243
isExported _ TypeInstanceDeclaration{} = True
43-
isExported exps (PositionedDeclaration _ d) = isExported exps d
44+
isExported exps (PositionedDeclaration _ _ d) = isExported exps d
4445
isExported (Just exps) decl = any (matches decl) exps
4546
where
4647
matches (TypeDeclaration ident _) (ValueRef ident') = ident == ident'
@@ -49,8 +50,8 @@ isExported (Just exps) decl = any (matches decl) exps
4950
matches (ExternDataDeclaration ident _) (TypeRef ident' _) = ident == ident'
5051
matches (TypeSynonymDeclaration ident _ _) (TypeRef ident' _) = ident == ident'
5152
matches (TypeClassDeclaration ident _ _ _) (TypeClassRef ident') = ident == ident'
52-
matches (PositionedDeclaration _ d) r = d `matches` r
53-
matches d (PositionedDeclarationRef _ r) = d `matches` r
53+
matches (PositionedDeclaration _ _ d) r = d `matches` r
54+
matches d (PositionedDeclarationRef _ _ r) = d `matches` r
5455
matches _ _ = False
5556

5657
exportedDeclarations :: Module -> [Declaration]
@@ -63,7 +64,7 @@ isDctorExported :: ProperName -> Maybe [DeclarationRef] -> ProperName -> Bool
6364
isDctorExported _ Nothing _ = True
6465
isDctorExported ident (Just exps) ctor = test `any` exps
6566
where
66-
test (PositionedDeclarationRef _ d) = test d
67+
test (PositionedDeclarationRef _ _ d) = test d
6768
test (TypeRef ident' Nothing) = ident == ident'
6869
test (TypeRef ident' (Just ctors)) = ident == ident' && ctor `elem` ctors
6970
test _ = False
@@ -102,16 +103,16 @@ data DeclarationRef
102103
-- |
103104
-- A declaration reference with source position information
104105
--
105-
| PositionedDeclarationRef SourceSpan DeclarationRef
106+
| PositionedDeclarationRef SourceSpan [Comment] DeclarationRef
106107
deriving (Show, D.Data, D.Typeable)
107108

108109
instance Eq DeclarationRef where
109110
(TypeRef name dctors) == (TypeRef name' dctors') = name == name' && dctors == dctors'
110111
(ValueRef name) == (ValueRef name') = name == name'
111112
(TypeClassRef name) == (TypeClassRef name') = name == name'
112113
(TypeInstanceRef name) == (TypeInstanceRef name') = name == name'
113-
(PositionedDeclarationRef _ r) == r' = r == r'
114-
r == (PositionedDeclarationRef _ r') = r == r'
114+
(PositionedDeclarationRef _ _ r) == r' = r == r'
115+
r == (PositionedDeclarationRef _ _ r') = r == r'
115116
_ == _ = False
116117

117118
-- |
@@ -192,15 +193,15 @@ data Declaration
192193
-- |
193194
-- A declaration with source position information
194195
--
195-
| PositionedDeclaration SourceSpan Declaration
196+
| PositionedDeclaration SourceSpan [Comment] Declaration
196197
deriving (Show, D.Data, D.Typeable)
197198

198199
-- |
199200
-- Test if a declaration is a value declaration
200201
--
201202
isValueDecl :: Declaration -> Bool
202203
isValueDecl ValueDeclaration{} = True
203-
isValueDecl (PositionedDeclaration _ d) = isValueDecl d
204+
isValueDecl (PositionedDeclaration _ _ d) = isValueDecl d
204205
isValueDecl _ = False
205206

206207
-- |
@@ -209,47 +210,47 @@ isValueDecl _ = False
209210
isDataDecl :: Declaration -> Bool
210211
isDataDecl DataDeclaration{} = True
211212
isDataDecl TypeSynonymDeclaration{} = True
212-
isDataDecl (PositionedDeclaration _ d) = isDataDecl d
213+
isDataDecl (PositionedDeclaration _ _ d) = isDataDecl d
213214
isDataDecl _ = False
214215

215216
-- |
216217
-- Test if a declaration is a module import
217218
--
218219
isImportDecl :: Declaration -> Bool
219220
isImportDecl ImportDeclaration{} = True
220-
isImportDecl (PositionedDeclaration _ d) = isImportDecl d
221+
isImportDecl (PositionedDeclaration _ _ d) = isImportDecl d
221222
isImportDecl _ = False
222223

223224
-- |
224225
-- Test if a declaration is a data type foreign import
225226
--
226227
isExternDataDecl :: Declaration -> Bool
227228
isExternDataDecl ExternDataDeclaration{} = True
228-
isExternDataDecl (PositionedDeclaration _ d) = isExternDataDecl d
229+
isExternDataDecl (PositionedDeclaration _ _ d) = isExternDataDecl d
229230
isExternDataDecl _ = False
230231

231232
-- |
232233
-- Test if a declaration is a type class instance foreign import
233234
--
234235
isExternInstanceDecl :: Declaration -> Bool
235236
isExternInstanceDecl ExternInstanceDeclaration{} = True
236-
isExternInstanceDecl (PositionedDeclaration _ d) = isExternInstanceDecl d
237+
isExternInstanceDecl (PositionedDeclaration _ _ d) = isExternInstanceDecl d
237238
isExternInstanceDecl _ = False
238239

239240
-- |
240241
-- Test if a declaration is a fixity declaration
241242
--
242243
isFixityDecl :: Declaration -> Bool
243244
isFixityDecl FixityDeclaration{} = True
244-
isFixityDecl (PositionedDeclaration _ d) = isFixityDecl d
245+
isFixityDecl (PositionedDeclaration _ _ d) = isFixityDecl d
245246
isFixityDecl _ = False
246247

247248
-- |
248249
-- Test if a declaration is a foreign import
249250
--
250251
isExternDecl :: Declaration -> Bool
251252
isExternDecl ExternDeclaration{} = True
252-
isExternDecl (PositionedDeclaration _ d) = isExternDecl d
253+
isExternDecl (PositionedDeclaration _ _ d) = isExternDecl d
253254
isExternDecl _ = False
254255

255256
-- |
@@ -258,7 +259,7 @@ isExternDecl _ = False
258259
isTypeClassDeclaration :: Declaration -> Bool
259260
isTypeClassDeclaration TypeClassDeclaration{} = True
260261
isTypeClassDeclaration TypeInstanceDeclaration{} = True
261-
isTypeClassDeclaration (PositionedDeclaration _ d) = isTypeClassDeclaration d
262+
isTypeClassDeclaration (PositionedDeclaration _ _ d) = isTypeClassDeclaration d
262263
isTypeClassDeclaration _ = False
263264

264265
-- |
@@ -369,7 +370,7 @@ data Expr
369370
-- |
370371
-- A value with source position information
371372
--
372-
| PositionedValue SourceSpan Expr deriving (Show, D.Data, D.Typeable)
373+
| PositionedValue SourceSpan [Comment] Expr deriving (Show, D.Data, D.Typeable)
373374

374375
-- |
375376
-- An alternative in a case statement
@@ -404,4 +405,4 @@ data DoNotationElement
404405
-- |
405406
-- A do notation element with source position information
406407
--
407-
| PositionedDoNotationElement SourceSpan DoNotationElement deriving (Show, D.Data, D.Typeable)
408+
| PositionedDoNotationElement SourceSpan [Comment] DoNotationElement deriving (Show, D.Data, D.Typeable)

0 commit comments

Comments
 (0)