fortran-src-0.15.1: Parsers and analyses for Fortran standards 66, 77, 90, 95 and 2003 (partial).
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.Fortran.Rewriter.Internal

Synopsis

Documentation

data SourceLocation Source #

Represents location in source code.

Note that, SourceLocation indicates space between characters, i.e the following example:

 SourceLocation 0 1

indicates position between first and second characters in a file.

Constructors

SourceLocation Int Int 

data SourceRange Source #

Represents range in source code.

Instances

Instances details
Show SourceRange Source # 
Instance details

Defined in Language.Fortran.Rewriter.Internal

Eq SourceRange Source # 
Instance details

Defined in Language.Fortran.Rewriter.Internal

data RChar Source #

Represents a character in the original source text along with any replacement operations applied to the character in place.

It expects a character (in case it's empty, Nothing should be used), whether it should be removed, its SourceLocation and a string that should be put in place of it.

Instances

Instances details
Show RChar Source # 
Instance details

Defined in Language.Fortran.Rewriter.Internal

Methods

showsPrec :: Int -> RChar -> ShowS #

show :: RChar -> String #

showList :: [RChar] -> ShowS #

Eq RChar Source # 
Instance details

Defined in Language.Fortran.Rewriter.Internal

Methods

(==) :: RChar -> RChar -> Bool #

(/=) :: RChar -> RChar -> Bool #

data Replacement Source #

Represents the intent to replace content in the file.

The content in Replacement will be used in place of what is in the range described. Note that the replacement text can be shorter or larger than the original span, and it can also be multi-line.

type Chunk = [RChar] Source #

As we advance through the [RChar] list, we consider "chunks" as the unit of text written out. A chunk is either:

  1. original source text up to a newline character, end of file or RChar described in 2.
  2. a single RChar that has non-empty replacement string or is deleted.

type ReplacementMap = Map String [Replacement] Source #

Represents map of files and replacements that will be done.

toRCharList :: ByteString -> [RChar] Source #

Parses input string into a list of annotated characters.

markRChars :: [RChar] -> SourceRange -> [RChar] Source #

Marks RChars in a given range to be removed later.

setReplacementStringSL :: [RChar] -> SourceLocation -> ByteString -> Bool -> [RChar] Source #

Sets replacement string to be prepended to the given location.

setReplacementStringSR :: [RChar] -> SourceRange -> ByteString -> Bool -> [RChar] Source #

Sets replacement string to be prepended to the begining of the given range.

evaluateRChars :: [RChar] -> ByteString Source #

Applies all deletions and additions and transforms RChars back to a string.

evaluateRChar :: RChar -> ByteString Source #

If RChar is marked as deleted, it'll be evaluated to its replacement string, otherwise original character will be returned.

nextChunk :: [RChar] -> (Chunk, [RChar]) Source #

From [RChar], obtain a (Chunk, [RChars]) where the Chunk is the next Chunk and the [RChar] are the remaining RChars.

allChunks :: [RChar] -> [Chunk] Source #

Splits [RChar] into Chunks.

evaluateChunks :: [Chunk] -> ByteString Source #

Transform a list of Chunks into a single string, applying continuation lines when neccessary.

evaluateChunks_ :: [Chunk] -> Int64 -> Maybe Char -> ByteString Source #

This expands the chunks from the left to right. If the length of what has already been put into the current line exceeds the limit of 72 characters (excluding inline comments starting with ! and implicit comments starting at column 73) then it ends the current line with a continuation, otherwise it simply adds the line as-is. It also calculates if the chunk is inside or outside of a string literal, using that to determine where explicit comments are if any.

In either case, we make sure that we are padding implicit comments *from the original source* even if the tail of that line has been moved onto a continuation line.

isInsertion :: Replacement -> Bool Source #

Return TRUE iff the Replacement constitutes a character insertion.

setReplacement :: [RChar] -> Replacement -> [RChar] Source #

Sets a single Replacement given a list of RChars.

setReplacements :: [RChar] -> [Replacement] -> [RChar] Source #

Sets a list of Replacements given a list of RChars.

adjustLineWrap :: [RChar] -> [RChar] Source #

heuristic to wrap line after comma or right parenthesis if applicable

deleteRC :: RChar -> RChar Source #

Mark removal for the input RChar

appendRC :: RChar -> Char -> RChar Source #

Append the input character to the replacement string

areDisjoint :: Replacement -> Replacement -> Bool Source #

Checks whether two Replacements are not overlapping.

isValidRange :: SourceRange -> [RChar] -> Bool Source #

Checks whether:

  1. the start is before the end of the range and
  2. both start and end locations are within the code.

applyReplacements :: ByteString -> [Replacement] -> ByteString Source #

Applies Replacements to a string and return it.

Firstly, it transforms the string into a list of RChars.

After that, it validates the SourceRange of each Replacement.

In the end, it splits up RChars in Chunks, set the Replacements and evaluates the Chunks.