Safe Haskell | None |
---|---|
Language | Haskell2010 |
Views of C datatypes. While Language.C.Types.Parse defines datatypes for
representing the concrete syntax tree of C types, this module provides
friendlier views of C types, by turning them into a data type matching more
closely how we read and think about types, both in Haskell and in C. To
appreciate the difference, look at the difference between
ParameterDeclaration
and ParameterDeclaration
.
As a bonus, routines are provided for describing types in natural language
(English) -- see describeParameterDeclaration
and describeType
.
- newtype Identifier = Identifier {}
- data StorageClassSpecifier
- data TypeQualifier
- data FunctionSpecifier = INLINE
- data ArrayType
- data Specifiers = Specifiers {}
- data Type
- data TypeSpecifier
- data Sign
- data ParameterDeclaration = ParameterDeclaration {}
- type IsTypeName = Identifier -> Bool
- type CParser m = (Monad m, Functor m, Applicative m, MonadPlus m, Parsing m, CharParsing m, TokenParsing m, LookAheadParsing m, MonadReader IsTypeName m)
- runCParser :: Stream s Identity Char => IsTypeName -> String -> s -> ReaderT IsTypeName (Parsec s ()) a -> Either ParseError a
- quickCParser :: IsTypeName -> String -> ReaderT IsTypeName (Parsec String ()) a -> a
- quickCParser_ :: String -> ReaderT IsTypeName (Parsec String ()) a -> a
- parseParameterDeclaration :: CParser m => m ParameterDeclaration
- parseParameterList :: CParser m => m [ParameterDeclaration]
- parseIdentifier :: CParser m => m Identifier
- parseType :: CParser m => m Type
- data UntangleErr
- untangleParameterDeclaration :: ParameterDeclaration -> Either UntangleErr ParameterDeclaration
- tangleParameterDeclaration :: ParameterDeclaration -> ParameterDeclaration
- describeParameterDeclaration :: ParameterDeclaration -> Doc
- describeType :: Type -> Doc
Types
newtype Identifier Source
data TypeQualifier Source
data FunctionSpecifier Source
data TypeSpecifier Source
Parsing
type IsTypeName = Identifier -> Bool Source
Function used to determine whether an Id
is a type name.
type CParser m = (Monad m, Functor m, Applicative m, MonadPlus m, Parsing m, CharParsing m, TokenParsing m, LookAheadParsing m, MonadReader IsTypeName m) Source
All the parsing is done using the type classes provided by the
parsers
package. You can use the parsing routines with any of the parsers
that implement the classes, such as parsec
or trifecta
.
The MonadReader
with IsTypeName
is required for parsing C, see
http://en.wikipedia.org/wiki/The_lexer_hack.
:: Stream s Identity Char | |
=> IsTypeName | Function determining if an identifier is a type name. |
-> String | Source name. |
-> s | String to parse. |
-> ReaderT IsTypeName (Parsec s ()) a | Parser. Anything with type |
-> Either ParseError a |
Runs a
using CParser
parsec
.
:: IsTypeName | Function determining if an identifier is a type name. |
-> String | String to parse. |
-> ReaderT IsTypeName (Parsec String ()) a | Parser. Anything with type |
-> a |
Useful for quick testing. Uses "quickCParser"
as source name, and throws
an error
if parsing fails.
:: String | String to parse. |
-> ReaderT IsTypeName (Parsec String ()) a | Parser. Anything with type |
-> a |
Like quickCParser
, but uses
as const
False
IsTypeName
.
parseParameterList :: CParser m => m [ParameterDeclaration] Source
parseIdentifier :: CParser m => m Identifier Source
Convert to and from high-level views
data UntangleErr Source
untangleParameterDeclaration :: ParameterDeclaration -> Either UntangleErr ParameterDeclaration Source
To english
describeType :: Type -> Doc Source