language-c-0.6.1: Analysis and generation of C code

Copyright | (c) 2008 Benedikt Huber
License | BSD-style
Maintainer | benedikt.huber@gmail.com
Stability | experimental
Portability | ghc
Safe Haskell | None
Language | Haskell98

Language.C.Parser

Contents

- Simple API
- Parser Monad
- Exposed Parsers
- Parser Monad

Description

Language.C parser

Synopsis

- parseC :: InputStream -> Position -> Either ParseError CTranslUnit
- data P a
- execParser :: P a -> InputStream -> Position -> [Ident] -> [Name] -> Either ParseError (a, [Name])
- execParser_ :: P a -> InputStream -> Position -> Either ParseError a
- builtinTypeNames :: [Ident]
- translUnitP :: P CTranslUnit
- extDeclP :: P CExtDecl
- statementP :: P CStat
- expressionP :: P CExpr
- newtype ParseError = ParseError ([String], Position)

# Simple API

parseC :: InputStream -> Position -> Either ParseError CTranslUnit #

`parseC input initialPos` parses the given preprocessed C-source input and returns the AST or a list of parse errors.

# Parser Monad

data P a #

Instances

Monad P # |
Methods (>>=) :: P a -> (a -> P b) -> P b # (>>) :: P a -> P b -> P b # return :: a -> P a # fail :: String -> P a #
Functor P # |
Methods fmap :: (a -> b) -> P a -> P b # (<$) :: a -> P b -> P a #
Applicative P # |
Methods pure :: a -> P a # (<*>) :: P (a -> b) -> P a -> P b # (*>) :: P a -> P b -> P b # (<*) :: P a -> P b -> P a #

execParser :: P a -> InputStream -> Position -> [Ident] -> [Name] -> Either ParseError (a, [Name]) #

execute the given parser on the supplied input stream. returns `ParseError` if the parser failed, and a pair of result and remaining name supply otherwise

Synopsis: `execParser parser inputStream initialPos predefinedTypedefs uniqNameSupply`

execParser_ :: P a -> InputStream -> Position -> Either ParseError a #

run the given parser using a new name supply and builtin typedefs see `execParser`

Synopsis: `runParser parser inputStream initialPos`

builtinTypeNames :: [Ident] #

# Exposed Parsers

translUnitP :: P CTranslUnit #

`translUnitP` provides a parser for a complete C translation unit, i.e. a list of external declarations.

extDeclP :: P CExtDecl #

`extDeclP` provides a parser for an external (file-scope) declaration

statementP :: P CStat #

`statementP` provides a parser for C statements

expressionP :: P CExpr #

`expressionP` provides a parser for C expressions

# Parser Monad

newtype ParseError #

Constructors

ParseError ([String], Position) |

Instances

Show ParseError # |
Methods showsPrec :: Int -> ParseError -> ShowS # show :: ParseError -> String # showList :: [ParseError] -> ShowS #