Extensions.Module

extensions-0.1.0.2: Parse Haskell Language Extensions

Copyright | (c) 2020-2022 Kowainik
License | MPL-2.0
Maintainer | Kowainik <xrom.xkov@gmail.com>
Safe Haskell | None
Language | Haskell2010

Extensions.Module

Contents

- Internal Parsers

Description

Parser for Haskell Modules to get all Haskell Language Extensions used.

Synopsis

- parseFile :: FilePath -> IO (Either ModuleParseError ParsedExtensions)
- parseSource :: ByteString -> Either ModuleParseError ParsedExtensions
- parseSourceWithPath :: FilePath -> ByteString -> Either ModuleParseError ParsedExtensions
- extensionsP :: Parser [ParsedExtension]
- singleExtensionsP :: Parser [ParsedExtension]
- extensionP :: Parser ParsedExtension
- languagePragmaP :: Parser a -> Parser a
- optionsGhcP :: Parser [a]
- pragmaP :: Parser () -> Parser a -> Parser a
- commentP :: Parser [a]
- cppP :: Parser [a]

# Documentation

parseFile :: FilePath -> IO (Either ModuleParseError ParsedExtensions) #

By the given file path, reads the file and returns `ParsedExtensions`, if parsing succeeds.

parseSource :: ByteString -> Either ModuleParseError ParsedExtensions #

By the given file source content, returns `ParsedExtensions`, if parsing succeeds.

parseSourceWithPath :: FilePath -> ByteString -> Either ModuleParseError ParsedExtensions #

By the given file path and file source content, returns `ParsedExtensions`, if parsing succeeds.

This function takes a path to a Haskell source file. The path is only used for error message. Pass empty string or use `parseSource`, if you don't have a path to a Haskell module.

# Internal Parsers

extensionsP :: Parser [ParsedExtension] #

The main parser of `ParsedExtension`.

It parses language pragmas or comments until end of file or the first line with the functionimportmodule name.

singleExtensionsP :: Parser [ParsedExtension] #

Single LANGUAGE pragma parser.

     {-# LANGUAGE XXX
      , YYY ,
      ZZZ
     #-}

extensionP :: Parser ParsedExtension #

Parses all known and unknown `OnOffExtension`s or `SafeHaskellExtension`s.

languagePragmaP :: Parser a -> Parser a #

Parser for standard language pragma keywords: `{-# LANGUAGE XXX #-}`

optionsGhcP :: Parser [a] #

Parser for GHC options pragma keywords: `{-# OPTIONS_GHC YYY #-}`

pragmaP :: Parser () -> Parser a -> Parser a #

Parser for GHC pragmas with a given pragma word.

commentP :: Parser [a] #

Haskell comment parser. Supports both single-line comments:

     -- I am a single comment

and multi-line comments:

     {- I
     AM
     MULTILINE
     -}

cppP :: Parser [a] #

CPP syntax parser.

     #if __GLASGOW_HASKELL__ < 810
     -- Could be more Language pragmas that should be parsed
     #endif