Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Common interface to various Fortran parsers.
Each parser exports various Happy-generated functions. All export a top-level
ProgramFile
parser. Most also export intermediate parsers e.g. for
Statement
s and Expression
s. Fixed form and free form parsers use different
lexing schemes. And, due to headaches with Fortran's syntax, we usually want to
enforce some post-parse transformations.
This module provides a common wrapper over all that functionality. Internal combinators are exposed to assist in manually configuring parsers.
Synopsis
- byVer :: FortranVersion -> Parser (ProgramFile A0)
- byVerWithMods :: ModFiles -> FortranVersion -> Parser (ProgramFile A0)
- f66 :: Parser (ProgramFile A0)
- f77 :: Parser (ProgramFile A0)
- f77e :: Parser (ProgramFile A0)
- f77l :: Parser (ProgramFile A0)
- f90 :: Parser (ProgramFile A0)
- f95 :: Parser (ProgramFile A0)
- f2003 :: Parser (ProgramFile A0)
- f66NoTransform :: Parser (ProgramFile A0)
- f77NoTransform :: Parser (ProgramFile A0)
- f77eNoTransform :: Parser (ProgramFile A0)
- f77lNoTransform :: Parser (ProgramFile A0)
- f90NoTransform :: Parser (ProgramFile A0)
- f95NoTransform :: Parser (ProgramFile A0)
- f2003NoTransform :: Parser (ProgramFile A0)
- f90Expr :: Parser (Expression A0)
- transformAs :: Data a => FortranVersion -> Parser (ProgramFile a) -> ModFiles -> Parser (ProgramFile a)
- defaultTransformation :: Data a => FortranVersion -> Transform a ()
- type Parser a = String -> ByteString -> Either ParseErrorSimple a
- type StateInit s = String -> FortranVersion -> ByteString -> ParseState s
- type ParserMaker ai tok a = Parse ai tok a -> FortranVersion -> Parser a
- makeParser :: (Loc ai, LastToken ai tok, Show tok) => StateInit ai -> ParserMaker ai tok a
- makeParserFixed :: ParserMaker AlexInput Token a
- makeParserFree :: ParserMaker AlexInput Token a
- initParseStateFixed :: StateInit AlexInput
- initParseStateFree :: StateInit AlexInput
- initParseStateFixedExpr :: StateInit AlexInput
- initParseStateFreeExpr :: StateInit AlexInput
- parseUnsafe :: Parser a -> ByteString -> a
- collectTokensSafe :: forall a b. (Loc b, Tok a, LastToken b a, Show a) => Parse b a a -> ParseState b -> Maybe [a]
- collectTokens :: forall a b. (Loc b, Tok a, LastToken b a, Show a) => Parse b a a -> ParseState b -> [a]
- f77lIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0)
- f77lIncIncludes :: [FilePath] -> String -> ByteString -> IO [Block A0]
Main parsers (ProgramFile, with transformation)
byVer :: FortranVersion -> Parser (ProgramFile A0) Source #
byVerWithMods :: ModFiles -> FortranVersion -> Parser (ProgramFile A0) Source #
Main parsers without post-parse transformation
f66NoTransform :: Parser (ProgramFile A0) Source #
f77NoTransform :: Parser (ProgramFile A0) Source #
f90NoTransform :: Parser (ProgramFile A0) Source #
f95NoTransform :: Parser (ProgramFile A0) Source #
Other parsers
Various combinators
transformAs :: Data a => FortranVersion -> Parser (ProgramFile a) -> ModFiles -> Parser (ProgramFile a) Source #
defaultTransformation :: Data a => FortranVersion -> Transform a () Source #
The default post-parse AST transformation for each Fortran version.
Formed by composing transformations end-to-end.
Note that some transformations are noncommutative e.g. labeled DO grouping must be done before block DO grouping.
type Parser a = String -> ByteString -> Either ParseErrorSimple a Source #
Our common Fortran parser type takes a filename and input, and returns
either a normalized error (tokens are printed) or an untransformed
ProgramFile
.
type StateInit s = String -> FortranVersion -> ByteString -> ParseState s Source #
type ParserMaker ai tok a = Parse ai tok a -> FortranVersion -> Parser a Source #
makeParser :: (Loc ai, LastToken ai tok, Show tok) => StateInit ai -> ParserMaker ai tok a Source #
initParseStateFreeExpr :: StateInit AlexInput Source #
Initialize free-form parser state with the lexer configured for standalone expression parsing.
The free-form lexer needs a non-default start code for lexing standaloe expressions.
parseUnsafe :: Parser a -> ByteString -> a Source #
Convenience wrapper to easily use a parser unsafely.
This throws a catchable runtime IO exception, which is used in the tests.
collectTokensSafe :: forall a b. (Loc b, Tok a, LastToken b a, Show a) => Parse b a a -> ParseState b -> Maybe [a] Source #
collectTokens :: forall a b. (Loc b, Tok a, LastToken b a, Show a) => Parse b a a -> ParseState b -> [a] Source #
F77 with inlined includes
The Fortran 77 parser can parse and inline includes at parse time. Parse errors are thrown as IO exceptions.
Can be cleaned up and generalized to use for other parsers.
f77lIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0) Source #
f77lIncIncludes :: [FilePath] -> String -> ByteString -> IO [Block A0] Source #
Entry point for include files
We can't perform full analysis (though it might be possible to do in future) but the AST is enough for certain types of analysis/refactoring