@@ -41,6 +41,24 @@ instance Show Associativity where
4141 show Infixr = "infixr"
4242 show Infix = "infix"
4343
44+-- |
45+-- Source position information
46+--
47+data SourcePos = SourcePos
48+ {
49+ -- |
50+ -- Line number
51+ --
52+ sourcePosLine :: Int
53+ -- |
54+ -- Column number
55+ --
56+ , sourcePosColumn :: Int
57+ } deriving (D.Data, D.Typeable)
58+
59+instance Show SourcePos where
60+ show sp = "line " ++ show (sourcePosLine sp) ++ ", column " ++ show (sourcePosColumn sp)
61+
4462-- |
4563-- Fixity data for infix operators
4664--
@@ -132,6 +150,10 @@ data Declaration
132150 -- declarations)
133151 --
134152 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
153+ -- |
154+ -- A declaration with source position information
155+ --
156+ | PositionedDeclaration SourcePos Declaration
135157 deriving (Show, D.Data, D.Typeable)
136158
137159-- |
@@ -139,6 +161,7 @@ data Declaration
139161--
140162isValueDecl :: Declaration -> Bool
141163isValueDecl ValueDeclaration{} = True
164+isValueDecl (PositionedDeclaration _ d) = isValueDecl d
142165isValueDecl _ = False
143166
144167-- |
@@ -147,6 +170,7 @@ isValueDecl _ = False
147170isDataDecl :: Declaration -> Bool
148171isDataDecl DataDeclaration{} = True
149172isDataDecl TypeSynonymDeclaration{} = True
173+isDataDecl (PositionedDeclaration _ d) = isDataDecl d
150174isDataDecl _ = False
151175
152176-- |
@@ -154,6 +178,7 @@ isDataDecl _ = False
154178--
155179isImportDecl :: Declaration -> Bool
156180isImportDecl ImportDeclaration{} = True
181+isImportDecl (PositionedDeclaration _ d) = isImportDecl d
157182isImportDecl _ = False
158183
159184-- |
@@ -161,6 +186,7 @@ isImportDecl _ = False
161186--
162187isExternDataDecl :: Declaration -> Bool
163188isExternDataDecl ExternDataDeclaration{} = True
189+isExternDataDecl (PositionedDeclaration _ d) = isExternDataDecl d
164190isExternDataDecl _ = False
165191
166192-- |
@@ -168,6 +194,7 @@ isExternDataDecl _ = False
168194--
169195isExternInstanceDecl :: Declaration -> Bool
170196isExternInstanceDecl ExternInstanceDeclaration{} = True
197+isExternInstanceDecl (PositionedDeclaration _ d) = isExternInstanceDecl d
171198isExternInstanceDecl _ = False
172199
173200-- |
@@ -175,6 +202,7 @@ isExternInstanceDecl _ = False
175202--
176203isFixityDecl :: Declaration -> Bool
177204isFixityDecl FixityDeclaration{} = True
205+isFixityDecl (PositionedDeclaration _ d) = isFixityDecl d
178206isFixityDecl _ = False
179207
180208-- |
@@ -182,6 +210,7 @@ isFixityDecl _ = False
182210--
183211isExternDecl :: Declaration -> Bool
184212isExternDecl ExternDeclaration{} = True
213+isExternDecl (PositionedDeclaration _ d) = isExternDecl d
185214isExternDecl _ = False
186215
187216-- |
@@ -190,6 +219,7 @@ isExternDecl _ = False
190219isTypeClassDeclaration :: Declaration -> Bool
191220isTypeClassDeclaration TypeClassDeclaration{} = True
192221isTypeClassDeclaration TypeInstanceDeclaration{} = True
222+isTypeClassDeclaration (PositionedDeclaration _ d) = isTypeClassDeclaration d
193223isTypeClassDeclaration _ = False
194224
195225-- |
@@ -286,7 +316,11 @@ data Value
286316 -- can be evaluated at runtime. The constructor arguments represent (in order): the type class name and
287317 -- instance type, and the type class dictionaries in scope.
288318 --
289− | TypeClassDictionary (Qualified ProperName, [Type]) [TypeClassDictionaryInScope] deriving (Show, D.Data, D.Typeable)
319+ | TypeClassDictionary (Qualified ProperName, [Type]) [TypeClassDictionaryInScope]
320+ -- |
321+ -- A value with source position information
322+ --
323+ | PositionedValue SourcePos Value deriving (Show, D.Data, D.Typeable)
290324
291325-- |
292326-- An alternative in a case statement
@@ -328,7 +362,11 @@ data DoNotationElement
328362 -- |
329363 -- A let statement, i.e. a pure value with a binder
330364 --
331− | DoNotationLet Binder Value deriving (Show, D.Data, D.Typeable)
365+ | DoNotationLet Binder Value
366+ -- |
367+ -- A do notation element with source position information
368+ --
369+ | PositionedDoNotationElement SourcePos DoNotationElement deriving (Show, D.Data, D.Typeable)
332370
333371-- |
334372-- Data type for binders
@@ -373,8 +411,11 @@ data Binder
373411 -- |
374412 -- A binder which binds its input to an identifier
375413 --
376− | NamedBinder Ident Binder deriving (Show, D.Data, D.Typeable)
377−
414+ | NamedBinder Ident Binder
415+ -- |
416+ -- A binder with source position information
417+ --
418+ | PositionedBinder SourcePos Binder deriving (Show, D.Data, D.Typeable)
378419
379420-- |
380421-- Collect all names introduced in binders in an expression