Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
This module contains the definition of a source span data type that is used by the AST of the intermediate language to store for every node the corresponding portion of the source code.
Source spans can be pretty printed and are used by the error reporting engine of the compiler to point the user to the relevant piece of code when an error occurs.
Synopsis
- data SrcFile
- mkSrcFile :: FilePath -> String -> SrcFile
- hasSrcFileContents :: SrcFile -> Bool
- type SrcFileMap = [(FilePath, SrcFile)]
- mkSrcFileMap :: [SrcFile] -> SrcFileMap
- lookupSrcFile :: FilePath -> SrcFileMap -> SrcFile
- data SrcSpan
- srcSpanCodeLines :: SrcSpan -> [String]
- hasSrcSpanFile :: SrcSpan -> Bool
- hasSourceCode :: SrcSpan -> Bool
- spansMultipleLines :: SrcSpan -> Bool
- class ConvertibleSrcSpan ss where
- convertSrcSpan :: SrcFileMap -> ss -> SrcSpan
Source Files
Data type that contains the name and contents of source files.
The contents of the source file are stored as a string for parsing and as a list of lines for error messages.
SrcFile | |
| |
NoSrcFile | A source file whose contents are unknown. |
|
mkSrcFile :: FilePath -> String -> SrcFile Source #
Smart constructor for SrcFile
that automatically splits the file
contents into lines.
hasSrcFileContents :: SrcFile -> Bool Source #
Tests whether the contents of the given source file are known.
Source File Maps
type SrcFileMap = [(FilePath, SrcFile)] Source #
Type for a map that associates source files with their filename.
mkSrcFileMap :: [SrcFile] -> SrcFileMap Source #
Smart constructor for SrcFileMap
for the given SrcFile
s.
lookupSrcFile :: FilePath -> SrcFileMap -> SrcFile Source #
Looks up a SrcFile
in a SrcFileMap
.
Returns NoSrcFile
if the map does not contain such a source file.
Source Spans
Describes the portion of the source code that caused a message to be reported.
In contrast to the source spans provided by the haskell-src-exts
package
this source span provides access to the lines of code that contain the
source span.
SrcSpan | |
| |
NoSrcSpan | Indicates that no location information is available. |
FileSpan | Points to an unknown location in the given file. |
|
Instances
Eq SrcSpan Source # | |
Show SrcSpan Source # | |
Pretty SrcSpan Source # | Pretty instance for a source span that displays the filename and the start and end position of the source span. If the source span spans only a single line, the end position is omitted. |
Defined in FreeC.IR.SrcSpan | |
TransformSrcSpan SrcSpan | Converts a source span to an HST source span. |
Defined in FreeC.Frontend.Haskell.PatternMatching transformSrcSpan :: SrcSpan -> SrcSpan0 (HSE SrcSpan) | |
TransformSrcSpan SrcSpan | Extracts the actual source span from an HST source span. |
Defined in FreeC.Frontend.Haskell.PatternMatching transformSrcSpan :: SrcSpan0 (HSE SrcSpan) -> SrcSpan |
Selectors
srcSpanCodeLines :: SrcSpan -> [String] Source #
Gets the lines of source code spanned by the given source span.
Returns an empty list if the given source span does not satisfy the
hasSourceCode
predicate.
Predicates
hasSrcSpanFile :: SrcSpan -> Bool Source #
Tests whether the given SrcSpan
contains information about the file
that is spanned (i.e., there is a field srcSpanFile
).
hasSourceCode :: SrcSpan -> Bool Source #
Tests whether the given source span has attached source code.
spansMultipleLines :: SrcSpan -> Bool Source #
Tests whether the given source span spans multiple lines.
Conversion
class ConvertibleSrcSpan ss where Source #
Type class for source spans from other packages that can be converted
to SrcSpan
s for pretty printing of messages.
convertSrcSpan :: SrcFileMap -> ss -> SrcSpan Source #
Converts the given third party source span to a SrcSpan
by attaching
the corresponding line of source code.
Instances
ConvertibleSrcSpan SourcePos Source # | |
Defined in FreeC.Util.Parsec convertSrcSpan :: SrcFileMap -> SourcePos -> SrcSpan Source # | |
ConvertibleSrcSpan SrcLoc Source # | Converts a |
Defined in FreeC.Frontend.Haskell.SrcSpanConverter convertSrcSpan :: SrcFileMap -> SrcLoc -> SrcSpan Source # | |
ConvertibleSrcSpan SrcSpan Source # | Directly converts a |
Defined in FreeC.Frontend.Haskell.SrcSpanConverter convertSrcSpan :: SrcFileMap -> SrcSpan -> SrcSpan0 Source # | |
ConvertibleSrcSpan SrcSpanInfo Source # | Converts a |
Defined in FreeC.Frontend.Haskell.SrcSpanConverter convertSrcSpan :: SrcFileMap -> SrcSpanInfo -> SrcSpan Source # |