Safe Haskell | None |
---|---|
Language | Haskell2010 |
Language.Fortran.Parser
Description
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)
- byVerNoTransform :: FortranVersion -> 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)
- byVerFromFilename :: Parser (ProgramFile A0)
- byVerStmt :: FortranVersion -> Parser (Statement A0)
- f66StmtNoTransform :: Parser (Statement A0)
- f77StmtNoTransform :: Parser (Statement A0)
- f77eStmtNoTransform :: Parser (Statement A0)
- f77lStmtNoTransform :: Parser (Statement A0)
- f90StmtNoTransform :: Parser (Statement A0)
- f95StmtNoTransform :: Parser (Statement A0)
- f2003StmtNoTransform :: Parser (Statement A0)
- byVerInclude :: FortranVersion -> Parser [Block A0]
- f66IncludesNoTransform :: Parser [Block A0]
- f77IncludesNoTransform :: Parser [Block A0]
- f77eIncludesNoTransform :: Parser [Block A0]
- f77lIncludesNoTransform :: Parser [Block A0]
- f90IncludesNoTransform :: Parser [Block A0]
- f95IncludesNoTransform :: Parser [Block A0]
- f2003IncludesNoTransform :: Parser [Block 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
- data ParseErrorSimple = ParseErrorSimple {}
- 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]
- throwIOLeft :: (Exception e, MonadIO m) => Either e a -> m a
- byVerInlineIncludes :: FortranVersion -> [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0)
- f66InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0)
- f77InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0)
- f77eInlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0)
- f77lInlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0)
- f90InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0)
- f95InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0)
- f2003InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile 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
byVerNoTransform :: FortranVersion -> Parser (ProgramFile A0) Source #
f66NoTransform :: Parser (ProgramFile A0) Source #
f77NoTransform :: Parser (ProgramFile A0) Source #
f90NoTransform :: Parser (ProgramFile A0) Source #
f95NoTransform :: Parser (ProgramFile A0) Source #
Other parsers
byVerFromFilename :: Parser (ProgramFile A0) Source #
Obtain a Fortran parser by assuming the version from the filename provided.
Statement
byVerInclude :: FortranVersion -> Parser [Block A0] Source #
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
.
data ParseErrorSimple Source #
Constructors
ParseErrorSimple | |
Instances
Exception ParseErrorSimple Source # | |
Defined in Language.Fortran.Parser Methods toException :: ParseErrorSimple -> SomeException # | |
Show ParseErrorSimple Source # | |
Defined in Language.Fortran.Parser Methods showsPrec :: Int -> ParseErrorSimple -> ShowS # show :: ParseErrorSimple -> String # showList :: [ParseErrorSimple] -> ShowS # |
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 #
throwIOLeft :: (Exception e, MonadIO m) => Either e a -> m a Source #
May be used to lift parse results into IO and force unwrap.
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.
byVerInlineIncludes :: FortranVersion -> [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0) Source #
f66InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0) Source #
f77InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0) Source #
f77eInlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0) Source #
f77lInlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0) Source #
f90InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0) Source #
f95InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0) Source #
f2003InlineIncludes :: [FilePath] -> ModFiles -> String -> ByteString -> IO (ProgramFile A0) Source #