@@ -41,6 +41,24 @@ instance Show Associativity where
41 show Infixr = "infixr"
41 show Infixr = "infixr"
42 show Infix = "infix"
42 show Infix = "infix"
45+-- Source position information
47+data SourcePos = SourcePos
56+ , sourcePosColumn :: Int
57+ } deriving (D.Data, D.Typeable)
59+instance Show SourcePos where
60+ show sp = "line " ++ show (sourcePosLine sp) ++ ", column " ++ show (sourcePosColumn sp)
45-- Fixity data for infix operators
63-- Fixity data for infix operators
@@ -132,6 +150,10 @@ data Declaration
132 -- declarations)
150 -- declarations)
134 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
152 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
154+ -- A declaration with source position information
156+ | PositionedDeclaration SourcePos Declaration
135 deriving (Show, D.Data, D.Typeable)
157 deriving (Show, D.Data, D.Typeable)
@@ -139,6 +161,7 @@ data Declaration
140isValueDecl :: Declaration -> Bool
162isValueDecl :: Declaration -> Bool
141isValueDecl ValueDeclaration{} = True
163isValueDecl ValueDeclaration{} = True
164+isValueDecl (PositionedDeclaration _ d) = isValueDecl d
142isValueDecl _ = False
165isValueDecl _ = False
@@ -147,6 +170,7 @@ isValueDecl _ = False
147isDataDecl :: Declaration -> Bool
170isDataDecl :: Declaration -> Bool
148isDataDecl DataDeclaration{} = True
171isDataDecl DataDeclaration{} = True
149isDataDecl TypeSynonymDeclaration{} = True
172isDataDecl TypeSynonymDeclaration{} = True
173+isDataDecl (PositionedDeclaration _ d) = isDataDecl d
150isDataDecl _ = False
174isDataDecl _ = False
@@ -154,6 +178,7 @@ isDataDecl _ = False
155isImportDecl :: Declaration -> Bool
179isImportDecl :: Declaration -> Bool
156isImportDecl ImportDeclaration{} = True
180isImportDecl ImportDeclaration{} = True
181+isImportDecl (PositionedDeclaration _ d) = isImportDecl d
157isImportDecl _ = False
182isImportDecl _ = False
@@ -161,6 +186,7 @@ isImportDecl _ = False
162isExternDataDecl :: Declaration -> Bool
187isExternDataDecl :: Declaration -> Bool
163isExternDataDecl ExternDataDeclaration{} = True
188isExternDataDecl ExternDataDeclaration{} = True
189+isExternDataDecl (PositionedDeclaration _ d) = isExternDataDecl d
164isExternDataDecl _ = False
190isExternDataDecl _ = False
@@ -168,6 +194,7 @@ isExternDataDecl _ = False
169isExternInstanceDecl :: Declaration -> Bool
195isExternInstanceDecl :: Declaration -> Bool
170isExternInstanceDecl ExternInstanceDeclaration{} = True
196isExternInstanceDecl ExternInstanceDeclaration{} = True
197+isExternInstanceDecl (PositionedDeclaration _ d) = isExternInstanceDecl d
171isExternInstanceDecl _ = False
198isExternInstanceDecl _ = False
@@ -175,6 +202,7 @@ isExternInstanceDecl _ = False
176isFixityDecl :: Declaration -> Bool
203isFixityDecl :: Declaration -> Bool
177isFixityDecl FixityDeclaration{} = True
204isFixityDecl FixityDeclaration{} = True
205+isFixityDecl (PositionedDeclaration _ d) = isFixityDecl d
178isFixityDecl _ = False
206isFixityDecl _ = False
@@ -182,6 +210,7 @@ isFixityDecl _ = False
183isExternDecl :: Declaration -> Bool
211isExternDecl :: Declaration -> Bool
184isExternDecl ExternDeclaration{} = True
212isExternDecl ExternDeclaration{} = True
213+isExternDecl (PositionedDeclaration _ d) = isExternDecl d
185isExternDecl _ = False
214isExternDecl _ = False
@@ -190,6 +219,7 @@ isExternDecl _ = False
190isTypeClassDeclaration :: Declaration -> Bool
219isTypeClassDeclaration :: Declaration -> Bool
191isTypeClassDeclaration TypeClassDeclaration{} = True
220isTypeClassDeclaration TypeClassDeclaration{} = True
192isTypeClassDeclaration TypeInstanceDeclaration{} = True
221isTypeClassDeclaration TypeInstanceDeclaration{} = True
222+isTypeClassDeclaration (PositionedDeclaration _ d) = isTypeClassDeclaration d
193isTypeClassDeclaration _ = False
223isTypeClassDeclaration _ = False
@@ -286,7 +316,11 @@ data Value
286 -- can be evaluated at runtime. The constructor arguments represent (in order): the type class name and
316 -- can be evaluated at runtime. The constructor arguments represent (in order): the type class name and
287 -- instance type, and the type class dictionaries in scope.
317 -- instance type, and the type class dictionaries in scope.
289− | TypeClassDictionary (Qualified ProperName, [Type]) [TypeClassDictionaryInScope] deriving (Show, D.Data, D.Typeable)
319+ | TypeClassDictionary (Qualified ProperName, [Type]) [TypeClassDictionaryInScope]
321+ -- A value with source position information
323+ | PositionedValue SourcePos Value deriving (Show, D.Data, D.Typeable)
292-- An alternative in a case statement
326-- An alternative in a case statement
@@ -328,7 +362,11 @@ data DoNotationElement
329 -- A let statement, i.e. a pure value with a binder
363 -- A let statement, i.e. a pure value with a binder
331− | DoNotationLet Binder Value deriving (Show, D.Data, D.Typeable)
365+ | DoNotationLet Binder Value
367+ -- A do notation element with source position information
369+ | PositionedDoNotationElement SourcePos DoNotationElement deriving (Show, D.Data, D.Typeable)
334-- Data type for binders
372-- Data type for binders
@@ -373,8 +411,11 @@ data Binder
374 -- A binder which binds its input to an identifier
412 -- A binder which binds its input to an identifier
376− | NamedBinder Ident Binder deriving (Show, D.Data, D.Typeable)
414+ | NamedBinder Ident Binder
416+ -- A binder with source position information
418+ | PositionedBinder SourcePos Binder deriving (Show, D.Data, D.Typeable)
380-- Collect all names introduced in binders in an expression
421-- Collect all names introduced in binders in an expression