inline-c-0.9.1.10: Write Haskell source files including C code inline. No FFI required.

Safe Haskell | None
Language | Haskell2010

Language.C.Types.Parse

Contents

- Parser configuration
  - Default configuration
- Parser type
- Types and parsing
- YACC grammar
- Testing utilities

Description

A parser for C99 declarations. Currently, the parser has the following limitations:

- Array sizes can only be `*`, `n` (where n is a positive integer), `x` (where `x` is a C identifier). In C99 they can be arbitrary expressions. See the ``ArrayType`` data type.
- `_Bool`, `_Complex`, and `_Imaginary` are not present.
- Untyped parameter lists (pre-K&R C) are not allowed.

The parser is incremental and generic (see `CParser`). `Pretty` and `Arbitrary` instances are provided for all the data types.

The entry point if you want to parse C declarations is ``parameter_declaration``.

Synopsis

- type TypeNames = HashSet CIdentifier
- data CParserContext i = CParserContext {
  - cpcIdentName :: String
  - cpcTypeNames :: TypeNames
  - cpcParseIdent :: forall (m :: Type -> Type). CParser i m => m i
  - cpcIdentToString :: i -> String
  - cpcEnableCpp :: Bool
  }
- data CIdentifier
- unCIdentifier :: CIdentifier -> String
- cIdentifierFromString :: Bool -> String -> Either String CIdentifier
- cCParserContext :: Bool -> TypeNames -> CParserContext CIdentifier
- type CParser i (m :: Type -> Type) = (Monad m, Functor m, Applicative m, MonadPlus m, Parsing m, CharParsing m, TokenParsing m, LookAheadParsing m, MonadReader (CParserContext i) m, MonadFail m, Hashable i)
- runCParser :: Stream s Identity Char => CParserContext i -> String -> s -> ReaderT (CParserContext i) (Parsec s ()) a -> Either ParseError a
- quickCParser :: CParserContext i -> String -> ReaderT (CParserContext i) (Parsec String ()) a -> a
- quickCParser_ :: Bool -> String -> ReaderT (CParserContext CIdentifier) (Parsec String ()) a -> a
- identifier_no_lex :: CParser i m => m i
- data DeclarationSpecifier
  - = StorageClassSpecifier StorageClassSpecifier
  - | TypeSpecifier TypeSpecifier
  - | TypeQualifier TypeQualifier
  - | FunctionSpecifier FunctionSpecifier
- declaration_specifiers :: CParser i m => m [DeclarationSpecifier]
- data StorageClassSpecifier
  - = TYPEDEF
  - | EXTERN
  - | STATIC
  - | AUTO
  - | REGISTER
- storage_class_specifier :: CParser i m => m StorageClassSpecifier
- data TypeSpecifier
  - = VOID
  - | BOOL
  - | CHAR
  - | SHORT
  - | INT
  - | LONG
  - | FLOAT
  - | DOUBLE
  - | SIGNED
  - | UNSIGNED
  - | Struct CIdentifier
  - | Enum CIdentifier
  - | TypeName CIdentifier
  - | Template CIdentifier [[TypeSpecifier]]
  - | TemplateConst String
  - | TemplatePointer TypeSpecifier
- type_specifier :: CParser i m => m TypeSpecifier
- data TypeQualifier
  - = CONST
  - | RESTRICT
  - | VOLATILE
- type_qualifier :: CParser i m => m TypeQualifier
- data FunctionSpecifier = INLINE
- function_specifier :: CParser i m => m FunctionSpecifier
- data Declarator i = Declarator {
  - declaratorPointers :: [Pointer]
  - declaratorDirect :: DirectDeclarator i
  }
- declarator :: CParser i m => m (Declarator i)
- data DirectDeclarator i
  - = DeclaratorRoot i
  - | ArrayOrProto (DirectDeclarator i) (ArrayOrProto i)
  - | DeclaratorParens (Declarator i)
- direct_declarator :: CParser i m => m (DirectDeclarator i)
- data ArrayOrProto i
  - = Array (ArrayType i)
  - | Proto [ParameterDeclaration i]
- array_or_proto :: CParser i m => m (ArrayOrProto i)
- data ArrayType i
  - = VariablySized
  - | Unsized
  - | SizedByInteger Integer
  - | SizedByIdentifier i
- array_type :: CParser i m => m (ArrayType i)
- data Pointer = Pointer [TypeQualifier]
- pointer :: CParser i m => m Pointer
- data ParameterDeclaration i = ParameterDeclaration {
  - parameterDeclarationSpecifiers :: [DeclarationSpecifier]
  - parameterDeclarationDeclarator :: DeclaratorOrAbstractDeclarator i
  }
- data DeclaratorOrAbstractDeclarator i
  - = IsDeclarator (Declarator i)
  - | IsAbstractDeclarator (AbstractDeclarator i)
- parameter_declaration :: CParser i m => m (ParameterDeclaration i)
- parameter_list :: CParser i m => m [ParameterDeclaration i]
- data AbstractDeclarator i = AbstractDeclarator {
  - abstractDeclaratorPointers :: [Pointer]
  - abstractDeclaratorDirect :: Maybe (DirectAbstractDeclarator i)
  }
- abstract_declarator :: CParser i m => m (AbstractDeclarator i)
- data DirectAbstractDeclarator i
  - = ArrayOrProtoHere (ArrayOrProto i)
  - | ArrayOrProtoThere (DirectAbstractDeclarator i) (ArrayOrProto i)
  - | AbstractDeclaratorParens (AbstractDeclarator i)
- direct_abstract_declarator :: CParser i m => m (DirectAbstractDeclarator i)
- cIdentStart :: [Char]
- cIdentLetter :: [Char]
- cReservedWords :: HashSet String
- isTypeName :: Bool -> TypeNames -> String -> Bool

# Parser configuration

type TypeNames = HashSet CIdentifier Source #

A collection of named types (typedefs)

data CParserContext i Source #

Constructors

CParserContext |

Fields

- cpcIdentName :: String
- cpcTypeNames :: TypeNames

  Function used to determine whether an identifier is a type name.

- cpcParseIdent :: forall (m :: Type -> Type). CParser i m => m i

  Parses an identifier, *without consuming whitespace afterwards*.

- cpcIdentToString :: i -> String
- cpcEnableCpp :: Bool

## Default configuration

data CIdentifier Source #

A type for C identifiers.

#### Instances

Instances details

IsString CIdentifier Source # |
Instance details Defined in Language.C.Types.Parse Methods fromString :: String -> CIdentifier Source #
Show CIdentifier Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> CIdentifier -> ShowS Source # show :: CIdentifier -> String Source # showList :: [CIdentifier] -> ShowS Source #
Eq CIdentifier Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: CIdentifier -> CIdentifier -> Bool Source # (/=) :: CIdentifier -> CIdentifier -> Bool Source #
Ord CIdentifier Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

compare :: CIdentifier -> CIdentifier -> Ordering Source #

(<) :: CIdentifier -> CIdentifier -> Bool Source #

(<=) :: CIdentifier -> CIdentifier -> Bool Source #

(>) :: CIdentifier -> CIdentifier -> Bool Source #

(>=) :: CIdentifier -> CIdentifier -> Bool Source #

max :: CIdentifier -> CIdentifier -> CIdentifier Source #

min :: CIdentifier -> CIdentifier -> CIdentifier Source #

Hashable CIdentifier Source # |
Instance details Defined in Language.C.Types.Parse Methods hashWithSalt :: Int -> CIdentifier -> Int Source # hash :: CIdentifier -> Int Source #
Pretty CIdentifier Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: CIdentifier -> Doc ann Source # prettyList :: [CIdentifier] -> Doc ann Source #

unCIdentifier :: CIdentifier -> String Source #

cIdentifierFromString :: Bool -> String -> Either String CIdentifier Source #

cCParserContext :: Bool -> TypeNames -> CParserContext CIdentifier Source #

# Parser type

type CParser i (m :: Type -> Type) = (Monad m, Functor m, Applicative m, MonadPlus m, Parsing m, CharParsing m, TokenParsing m, LookAheadParsing m, MonadReader (CParserContext i) m, MonadFail m, Hashable i) 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`.

We parametrize the parsing by the type of the variable identifiers, `i`. We do so because we use this parser to implement anti-quoters referring to Haskell variables, and thus we need to parse Haskell identifiers in certain positions.

runCParser Source #

Arguments

:: Stream s Identity Char |
=> CParserContext i |
-> String | Source name.
-> s | String to parse.
-> ReaderT (CParserContext i) (Parsec s ()) a | Parser. Anything with type `forall m. CParser i m => m a` is a valid argument.
-> Either ParseError a |

Runs a ``CParser`` using `parsec`.

quickCParser Source #

Arguments

:: CParserContext i |
-> String | String to parse.
-> ReaderT (CParserContext i) (Parsec String ()) a | Parser. Anything with type `forall m. CParser i m => m a` is a valid argument.
-> a |

Useful for quick testing. Uses `"quickCParser"` as source name, and throws an `error` if parsing fails.

quickCParser_ Source #

Arguments

:: Bool |
-> String | String to parse.
-> ReaderT (CParserContext CIdentifier) (Parsec String ()) a | Parser. Anything with type `forall m. CParser i m => m a` is a valid argument.
-> a |

Like `quickCParser`, but uses ``cCParserContext` (`const` `False`)` as `CParserContext`.

# Types and parsing

identifier_no_lex :: CParser i m => m i Source #

data DeclarationSpecifier Source #

Constructors

StorageClassSpecifier StorageClassSpecifier |
TypeSpecifier TypeSpecifier |
TypeQualifier TypeQualifier |
FunctionSpecifier FunctionSpecifier |

#### Instances

Instances details

Show DeclarationSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> DeclarationSpecifier -> ShowS Source # show :: DeclarationSpecifier -> String Source # showList :: [DeclarationSpecifier] -> ShowS Source #
Eq DeclarationSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: DeclarationSpecifier -> DeclarationSpecifier -> Bool Source # (/=) :: DeclarationSpecifier -> DeclarationSpecifier -> Bool Source #
Pretty DeclarationSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: DeclarationSpecifier -> Doc ann Source # prettyList :: [DeclarationSpecifier] -> Doc ann Source #

declaration_specifiers :: CParser i m => m [DeclarationSpecifier] Source #

data StorageClassSpecifier Source #

Constructors

TYPEDEF |
EXTERN |
STATIC |
AUTO |
REGISTER |

#### Instances

Instances details

Show StorageClassSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> StorageClassSpecifier -> ShowS Source # show :: StorageClassSpecifier -> String Source # showList :: [StorageClassSpecifier] -> ShowS Source #
Eq StorageClassSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: StorageClassSpecifier -> StorageClassSpecifier -> Bool Source # (/=) :: StorageClassSpecifier -> StorageClassSpecifier -> Bool Source #
Pretty StorageClassSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: StorageClassSpecifier -> Doc ann Source # prettyList :: [StorageClassSpecifier] -> Doc ann Source #

storage_class_specifier :: CParser i m => m StorageClassSpecifier Source #

data TypeSpecifier Source #

Constructors

VOID |
BOOL |
CHAR |
SHORT |
INT |
LONG |
FLOAT |
DOUBLE |
SIGNED |
UNSIGNED |
Struct CIdentifier |
Enum CIdentifier |
TypeName CIdentifier |
Template CIdentifier [[TypeSpecifier]] |
TemplateConst String |
TemplatePointer TypeSpecifier |

#### Instances

Instances details

Show TypeSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> TypeSpecifier -> ShowS Source # show :: TypeSpecifier -> String Source # showList :: [TypeSpecifier] -> ShowS Source #
Eq TypeSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: TypeSpecifier -> TypeSpecifier -> Bool Source # (/=) :: TypeSpecifier -> TypeSpecifier -> Bool Source #
Pretty TypeSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: TypeSpecifier -> Doc ann Source # prettyList :: [TypeSpecifier] -> Doc ann Source #

type_specifier :: CParser i m => m TypeSpecifier Source #

data TypeQualifier Source #

Constructors

CONST |
RESTRICT |
VOLATILE |

#### Instances

Instances details

Show TypeQualifier Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> TypeQualifier -> ShowS Source # show :: TypeQualifier -> String Source # showList :: [TypeQualifier] -> ShowS Source #
Eq TypeQualifier Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: TypeQualifier -> TypeQualifier -> Bool Source # (/=) :: TypeQualifier -> TypeQualifier -> Bool Source #
Pretty TypeQualifier Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: TypeQualifier -> Doc ann Source # prettyList :: [TypeQualifier] -> Doc ann Source #

type_qualifier :: CParser i m => m TypeQualifier Source #

data FunctionSpecifier Source #

Constructors

INLINE |

#### Instances

Instances details

Show FunctionSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> FunctionSpecifier -> ShowS Source # show :: FunctionSpecifier -> String Source # showList :: [FunctionSpecifier] -> ShowS Source #
Eq FunctionSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: FunctionSpecifier -> FunctionSpecifier -> Bool Source # (/=) :: FunctionSpecifier -> FunctionSpecifier -> Bool Source #
Pretty FunctionSpecifier Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: FunctionSpecifier -> Doc ann Source # prettyList :: [FunctionSpecifier] -> Doc ann Source #

function_specifier :: CParser i m => m FunctionSpecifier Source #

data Declarator i Source #

Constructors

Declarator |

Fields

- declaratorPointers :: [Pointer]
- declaratorDirect :: DirectDeclarator i

#### Instances

Instances details

Functor Declarator Source # |
Instance details Defined in Language.C.Types.Parse Methods fmap :: (a -> b) -> Declarator a -> Declarator b Source # (<$) :: a -> Declarator b -> Declarator a Source #
Foldable Declarator Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

fold :: Monoid m => Declarator m -> m Source #

foldMap :: Monoid m => (a -> m) -> Declarator a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Declarator a -> m Source #

foldr :: (a -> b -> b) -> b -> Declarator a -> b Source #

foldr' :: (a -> b -> b) -> b -> Declarator a -> b Source #

foldl :: (b -> a -> b) -> b -> Declarator a -> b Source #

foldl' :: (b -> a -> b) -> b -> Declarator a -> b Source #

foldr1 :: (a -> a -> a) -> Declarator a -> a Source #

foldl1 :: (a -> a -> a) -> Declarator a -> a Source #

toList :: Declarator a -> [a] Source #

null :: Declarator a -> Bool Source #

length :: Declarator a -> Int Source #

elem :: Eq a => a -> Declarator a -> Bool Source #

maximum :: Ord a => Declarator a -> a Source #

minimum :: Ord a => Declarator a -> a Source #

sum :: Num a => Declarator a -> a Source #

product :: Num a => Declarator a -> a Source #

Traversable Declarator Source # |
Instance details Defined in Language.C.Types.Parse Methods traverse :: Applicative f => (a -> f b) -> Declarator a -> f (Declarator b) Source # sequenceA :: Applicative f => Declarator (f a) -> f (Declarator a) Source # mapM :: Monad m => (a -> m b) -> Declarator a -> m (Declarator b) Source # sequence :: Monad m => Declarator (m a) -> m (Declarator a) Source #
Show i => Show (Declarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> Declarator i -> ShowS Source # show :: Declarator i -> String Source # showList :: [Declarator i] -> ShowS Source #
Eq i => Eq (Declarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: Declarator i -> Declarator i -> Bool Source # (/=) :: Declarator i -> Declarator i -> Bool Source #
Pretty i => Pretty (Declarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: Declarator i -> Doc ann Source # prettyList :: [Declarator i] -> Doc ann Source #

declarator :: CParser i m => m (Declarator i) Source #

data DirectDeclarator i Source #

Constructors

DeclaratorRoot i |
ArrayOrProto (DirectDeclarator i) (ArrayOrProto i) |
DeclaratorParens (Declarator i) |

#### Instances

Instances details

Functor DirectDeclarator Source # |
Instance details Defined in Language.C.Types.Parse Methods fmap :: (a -> b) -> DirectDeclarator a -> DirectDeclarator b Source # (<$) :: a -> DirectDeclarator b -> DirectDeclarator a Source #
Foldable DirectDeclarator Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

fold :: Monoid m => DirectDeclarator m -> m Source #

foldMap :: Monoid m => (a -> m) -> DirectDeclarator a -> m Source #

foldMap' :: Monoid m => (a -> m) -> DirectDeclarator a -> m Source #

foldr :: (a -> b -> b) -> b -> DirectDeclarator a -> b Source #

foldr' :: (a -> b -> b) -> b -> DirectDeclarator a -> b Source #

foldl :: (b -> a -> b) -> b -> DirectDeclarator a -> b Source #

foldl' :: (b -> a -> b) -> b -> DirectDeclarator a -> b Source #

foldr1 :: (a -> a -> a) -> DirectDeclarator a -> a Source #

foldl1 :: (a -> a -> a) -> DirectDeclarator a -> a Source #

toList :: DirectDeclarator a -> [a] Source #

null :: DirectDeclarator a -> Bool Source #

length :: DirectDeclarator a -> Int Source #

elem :: Eq a => a -> DirectDeclarator a -> Bool Source #

maximum :: Ord a => DirectDeclarator a -> a Source #

minimum :: Ord a => DirectDeclarator a -> a Source #

sum :: Num a => DirectDeclarator a -> a Source #

product :: Num a => DirectDeclarator a -> a Source #

Traversable DirectDeclarator Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

traverse :: Applicative f => (a -> f b) -> DirectDeclarator a -> f (DirectDeclarator b) Source #

sequenceA :: Applicative f => DirectDeclarator (f a) -> f (DirectDeclarator a) Source #

mapM :: Monad m => (a -> m b) -> DirectDeclarator a -> m (DirectDeclarator b) Source #

sequence :: Monad m => DirectDeclarator (m a) -> m (DirectDeclarator a) Source #

Show i => Show (DirectDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> DirectDeclarator i -> ShowS Source # show :: DirectDeclarator i -> String Source # showList :: [DirectDeclarator i] -> ShowS Source #
Eq i => Eq (DirectDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: DirectDeclarator i -> DirectDeclarator i -> Bool Source # (/=) :: DirectDeclarator i -> DirectDeclarator i -> Bool Source #
Pretty i => Pretty (DirectDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: DirectDeclarator i -> Doc ann Source # prettyList :: [DirectDeclarator i] -> Doc ann Source #

direct_declarator :: CParser i m => m (DirectDeclarator i) Source #

data ArrayOrProto i Source #

Constructors

Array (ArrayType i) |
Proto [ParameterDeclaration i] |

#### Instances

Instances details

Functor ArrayOrProto Source # |
Instance details Defined in Language.C.Types.Parse Methods fmap :: (a -> b) -> ArrayOrProto a -> ArrayOrProto b Source # (<$) :: a -> ArrayOrProto b -> ArrayOrProto a Source #
Foldable ArrayOrProto Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

fold :: Monoid m => ArrayOrProto m -> m Source #

foldMap :: Monoid m => (a -> m) -> ArrayOrProto a -> m Source #

foldMap' :: Monoid m => (a -> m) -> ArrayOrProto a -> m Source #

foldr :: (a -> b -> b) -> b -> ArrayOrProto a -> b Source #

foldr' :: (a -> b -> b) -> b -> ArrayOrProto a -> b Source #

foldl :: (b -> a -> b) -> b -> ArrayOrProto a -> b Source #

foldl' :: (b -> a -> b) -> b -> ArrayOrProto a -> b Source #

foldr1 :: (a -> a -> a) -> ArrayOrProto a -> a Source #

foldl1 :: (a -> a -> a) -> ArrayOrProto a -> a Source #

toList :: ArrayOrProto a -> [a] Source #

null :: ArrayOrProto a -> Bool Source #

length :: ArrayOrProto a -> Int Source #

elem :: Eq a => a -> ArrayOrProto a -> Bool Source #

maximum :: Ord a => ArrayOrProto a -> a Source #

minimum :: Ord a => ArrayOrProto a -> a Source #

sum :: Num a => ArrayOrProto a -> a Source #

product :: Num a => ArrayOrProto a -> a Source #

Traversable ArrayOrProto Source # |
Instance details Defined in Language.C.Types.Parse Methods traverse :: Applicative f => (a -> f b) -> ArrayOrProto a -> f (ArrayOrProto b) Source # sequenceA :: Applicative f => ArrayOrProto (f a) -> f (ArrayOrProto a) Source # mapM :: Monad m => (a -> m b) -> ArrayOrProto a -> m (ArrayOrProto b) Source # sequence :: Monad m => ArrayOrProto (m a) -> m (ArrayOrProto a) Source #
Show i => Show (ArrayOrProto i) Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> ArrayOrProto i -> ShowS Source # show :: ArrayOrProto i -> String Source # showList :: [ArrayOrProto i] -> ShowS Source #
Eq i => Eq (ArrayOrProto i) Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: ArrayOrProto i -> ArrayOrProto i -> Bool Source # (/=) :: ArrayOrProto i -> ArrayOrProto i -> Bool Source #
Pretty i => Pretty (ArrayOrProto i) Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: ArrayOrProto i -> Doc ann Source # prettyList :: [ArrayOrProto i] -> Doc ann Source #

array_or_proto :: CParser i m => m (ArrayOrProto i) Source #

data ArrayType i Source #

Constructors

VariablySized |
Unsized |
SizedByInteger Integer |
SizedByIdentifier i |

#### Instances

Instances details

Functor ArrayType Source # |
Instance details Defined in Language.C.Types.Parse Methods fmap :: (a -> b) -> ArrayType a -> ArrayType b Source # (<$) :: a -> ArrayType b -> ArrayType a Source #
Foldable ArrayType Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

fold :: Monoid m => ArrayType m -> m Source #

foldMap :: Monoid m => (a -> m) -> ArrayType a -> m Source #

foldMap' :: Monoid m => (a -> m) -> ArrayType a -> m Source #

foldr :: (a -> b -> b) -> b -> ArrayType a -> b Source #

foldr' :: (a -> b -> b) -> b -> ArrayType a -> b Source #

foldl :: (b -> a -> b) -> b -> ArrayType a -> b Source #

foldl' :: (b -> a -> b) -> b -> ArrayType a -> b Source #

foldr1 :: (a -> a -> a) -> ArrayType a -> a Source #

foldl1 :: (a -> a -> a) -> ArrayType a -> a Source #

toList :: ArrayType a -> [a] Source #

null :: ArrayType a -> Bool Source #

length :: ArrayType a -> Int Source #

elem :: Eq a => a -> ArrayType a -> Bool Source #

maximum :: Ord a => ArrayType a -> a Source #

minimum :: Ord a => ArrayType a -> a Source #

sum :: Num a => ArrayType a -> a Source #

product :: Num a => ArrayType a -> a Source #

Traversable ArrayType Source # |
Instance details Defined in Language.C.Types.Parse Methods traverse :: Applicative f => (a -> f b) -> ArrayType a -> f (ArrayType b) Source # sequenceA :: Applicative f => ArrayType (f a) -> f (ArrayType a) Source # mapM :: Monad m => (a -> m b) -> ArrayType a -> m (ArrayType b) Source # sequence :: Monad m => ArrayType (m a) -> m (ArrayType a) Source #
Show i => Show (ArrayType i) Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> ArrayType i -> ShowS Source # show :: ArrayType i -> String Source # showList :: [ArrayType i] -> ShowS Source #
Eq i => Eq (ArrayType i) Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: ArrayType i -> ArrayType i -> Bool Source # (/=) :: ArrayType i -> ArrayType i -> Bool Source #
Pretty i => Pretty (ArrayType i) Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: ArrayType i -> Doc ann Source # prettyList :: [ArrayType i] -> Doc ann Source #

array_type :: CParser i m => m (ArrayType i) Source #

data Pointer Source #

Constructors

Pointer [TypeQualifier] |

#### Instances

Instances details

Show Pointer Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> Pointer -> ShowS Source # show :: Pointer -> String Source # showList :: [Pointer] -> ShowS Source #
Eq Pointer Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: Pointer -> Pointer -> Bool Source # (/=) :: Pointer -> Pointer -> Bool Source #
Pretty Pointer Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: Pointer -> Doc ann Source # prettyList :: [Pointer] -> Doc ann Source #

pointer :: CParser i m => m Pointer Source #

data ParameterDeclaration i Source #

Constructors

ParameterDeclaration |

Fields

- parameterDeclarationSpecifiers :: [DeclarationSpecifier]
- parameterDeclarationDeclarator :: DeclaratorOrAbstractDeclarator i

#### Instances

Instances details

Functor ParameterDeclaration Source # |
Instance details Defined in Language.C.Types.Parse Methods fmap :: (a -> b) -> ParameterDeclaration a -> ParameterDeclaration b Source # (<$) :: a -> ParameterDeclaration b -> ParameterDeclaration a Source #
Foldable ParameterDeclaration Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

fold :: Monoid m => ParameterDeclaration m -> m Source #

foldMap :: Monoid m => (a -> m) -> ParameterDeclaration a -> m Source #

foldMap' :: Monoid m => (a -> m) -> ParameterDeclaration a -> m Source #

foldr :: (a -> b -> b) -> b -> ParameterDeclaration a -> b Source #

foldr' :: (a -> b -> b) -> b -> ParameterDeclaration a -> b Source #

foldl :: (b -> a -> b) -> b -> ParameterDeclaration a -> b Source #

foldl' :: (b -> a -> b) -> b -> ParameterDeclaration a -> b Source #

foldr1 :: (a -> a -> a) -> ParameterDeclaration a -> a Source #

foldl1 :: (a -> a -> a) -> ParameterDeclaration a -> a Source #

toList :: ParameterDeclaration a -> [a] Source #

null :: ParameterDeclaration a -> Bool Source #

length :: ParameterDeclaration a -> Int Source #

elem :: Eq a => a -> ParameterDeclaration a -> Bool Source #

maximum :: Ord a => ParameterDeclaration a -> a Source #

minimum :: Ord a => ParameterDeclaration a -> a Source #

sum :: Num a => ParameterDeclaration a -> a Source #

product :: Num a => ParameterDeclaration a -> a Source #

Traversable ParameterDeclaration Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

traverse :: Applicative f => (a -> f b) -> ParameterDeclaration a -> f (ParameterDeclaration b) Source #

sequenceA :: Applicative f => ParameterDeclaration (f a) -> f (ParameterDeclaration a) Source #

mapM :: Monad m => (a -> m b) -> ParameterDeclaration a -> m (ParameterDeclaration b) Source #

sequence :: Monad m => ParameterDeclaration (m a) -> m (ParameterDeclaration a) Source #

Show i => Show (ParameterDeclaration i) Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> ParameterDeclaration i -> ShowS Source # show :: ParameterDeclaration i -> String Source # showList :: [ParameterDeclaration i] -> ShowS Source #
Eq i => Eq (ParameterDeclaration i) Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: ParameterDeclaration i -> ParameterDeclaration i -> Bool Source # (/=) :: ParameterDeclaration i -> ParameterDeclaration i -> Bool Source #
Pretty i => Pretty (ParameterDeclaration i) Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: ParameterDeclaration i -> Doc ann Source # prettyList :: [ParameterDeclaration i] -> Doc ann Source #

data DeclaratorOrAbstractDeclarator i Source #

Constructors

IsDeclarator (Declarator i) |
IsAbstractDeclarator (AbstractDeclarator i) |

#### Instances

Instances details

Functor DeclaratorOrAbstractDeclarator Source # |
Instance details Defined in Language.C.Types.Parse Methods fmap :: (a -> b) -> DeclaratorOrAbstractDeclarator a -> DeclaratorOrAbstractDeclarator b Source # (<$) :: a -> DeclaratorOrAbstractDeclarator b -> DeclaratorOrAbstractDeclarator a Source #
Foldable DeclaratorOrAbstractDeclarator Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

fold :: Monoid m => DeclaratorOrAbstractDeclarator m -> m Source #

foldMap :: Monoid m => (a -> m) -> DeclaratorOrAbstractDeclarator a -> m Source #

foldMap' :: Monoid m => (a -> m) -> DeclaratorOrAbstractDeclarator a -> m Source #

foldr :: (a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b Source #

foldr' :: (a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b Source #

foldl :: (b -> a -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b Source #

foldl' :: (b -> a -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b Source #

foldr1 :: (a -> a -> a) -> DeclaratorOrAbstractDeclarator a -> a Source #

foldl1 :: (a -> a -> a) -> DeclaratorOrAbstractDeclarator a -> a Source #

toList :: DeclaratorOrAbstractDeclarator a -> [a] Source #

null :: DeclaratorOrAbstractDeclarator a -> Bool Source #

length :: DeclaratorOrAbstractDeclarator a -> Int Source #

elem :: Eq a => a -> DeclaratorOrAbstractDeclarator a -> Bool Source #

maximum :: Ord a => DeclaratorOrAbstractDeclarator a -> a Source #

minimum :: Ord a => DeclaratorOrAbstractDeclarator a -> a Source #

sum :: Num a => DeclaratorOrAbstractDeclarator a -> a Source #

product :: Num a => DeclaratorOrAbstractDeclarator a -> a Source #

Traversable DeclaratorOrAbstractDeclarator Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

traverse :: Applicative f => (a -> f b) -> DeclaratorOrAbstractDeclarator a -> f (DeclaratorOrAbstractDeclarator b) Source #

sequenceA :: Applicative f => DeclaratorOrAbstractDeclarator (f a) -> f (DeclaratorOrAbstractDeclarator a) Source #

mapM :: Monad m => (a -> m b) -> DeclaratorOrAbstractDeclarator a -> m (DeclaratorOrAbstractDeclarator b) Source #

sequence :: Monad m => DeclaratorOrAbstractDeclarator (m a) -> m (DeclaratorOrAbstractDeclarator a) Source #

Show i => Show (DeclaratorOrAbstractDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> DeclaratorOrAbstractDeclarator i -> ShowS Source # show :: DeclaratorOrAbstractDeclarator i -> String Source # showList :: [DeclaratorOrAbstractDeclarator i] -> ShowS Source #
Eq i => Eq (DeclaratorOrAbstractDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: DeclaratorOrAbstractDeclarator i -> DeclaratorOrAbstractDeclarator i -> Bool Source # (/=) :: DeclaratorOrAbstractDeclarator i -> DeclaratorOrAbstractDeclarator i -> Bool Source #

parameter_declaration :: CParser i m => m (ParameterDeclaration i) Source #

parameter_list :: CParser i m => m [ParameterDeclaration i] Source #

data AbstractDeclarator i Source #

Constructors

AbstractDeclarator |

Fields

- abstractDeclaratorPointers :: [Pointer]
- abstractDeclaratorDirect :: Maybe (DirectAbstractDeclarator i)

#### Instances

Instances details

Functor AbstractDeclarator Source # |
Instance details Defined in Language.C.Types.Parse Methods fmap :: (a -> b) -> AbstractDeclarator a -> AbstractDeclarator b Source # (<$) :: a -> AbstractDeclarator b -> AbstractDeclarator a Source #
Foldable AbstractDeclarator Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

fold :: Monoid m => AbstractDeclarator m -> m Source #

foldMap :: Monoid m => (a -> m) -> AbstractDeclarator a -> m Source #

foldMap' :: Monoid m => (a -> m) -> AbstractDeclarator a -> m Source #

foldr :: (a -> b -> b) -> b -> AbstractDeclarator a -> b Source #

foldr' :: (a -> b -> b) -> b -> AbstractDeclarator a -> b Source #

foldl :: (b -> a -> b) -> b -> AbstractDeclarator a -> b Source #

foldl' :: (b -> a -> b) -> b -> AbstractDeclarator a -> b Source #

foldr1 :: (a -> a -> a) -> AbstractDeclarator a -> a Source #

foldl1 :: (a -> a -> a) -> AbstractDeclarator a -> a Source #

toList :: AbstractDeclarator a -> [a] Source #

null :: AbstractDeclarator a -> Bool Source #

length :: AbstractDeclarator a -> Int Source #

elem :: Eq a => a -> AbstractDeclarator a -> Bool Source #

maximum :: Ord a => AbstractDeclarator a -> a Source #

minimum :: Ord a => AbstractDeclarator a -> a Source #

sum :: Num a => AbstractDeclarator a -> a Source #

product :: Num a => AbstractDeclarator a -> a Source #

Traversable AbstractDeclarator Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

traverse :: Applicative f => (a -> f b) -> AbstractDeclarator a -> f (AbstractDeclarator b) Source #

sequenceA :: Applicative f => AbstractDeclarator (f a) -> f (AbstractDeclarator a) Source #

mapM :: Monad m => (a -> m b) -> AbstractDeclarator a -> m (AbstractDeclarator b) Source #

sequence :: Monad m => AbstractDeclarator (m a) -> m (AbstractDeclarator a) Source #

Show i => Show (AbstractDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> AbstractDeclarator i -> ShowS Source # show :: AbstractDeclarator i -> String Source # showList :: [AbstractDeclarator i] -> ShowS Source #
Eq i => Eq (AbstractDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: AbstractDeclarator i -> AbstractDeclarator i -> Bool Source # (/=) :: AbstractDeclarator i -> AbstractDeclarator i -> Bool Source #
Pretty i => Pretty (AbstractDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: AbstractDeclarator i -> Doc ann Source # prettyList :: [AbstractDeclarator i] -> Doc ann Source #

abstract_declarator :: CParser i m => m (AbstractDeclarator i) Source #

data DirectAbstractDeclarator i Source #

Constructors

ArrayOrProtoHere (ArrayOrProto i) |
ArrayOrProtoThere (DirectAbstractDeclarator i) (ArrayOrProto i) |
AbstractDeclaratorParens (AbstractDeclarator i) |

#### Instances

Instances details

Functor DirectAbstractDeclarator Source # |
Instance details Defined in Language.C.Types.Parse Methods fmap :: (a -> b) -> DirectAbstractDeclarator a -> DirectAbstractDeclarator b Source # (<$) :: a -> DirectAbstractDeclarator b -> DirectAbstractDeclarator a Source #
Foldable DirectAbstractDeclarator Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

fold :: Monoid m => DirectAbstractDeclarator m -> m Source #

foldMap :: Monoid m => (a -> m) -> DirectAbstractDeclarator a -> m Source #

foldMap' :: Monoid m => (a -> m) -> DirectAbstractDeclarator a -> m Source #

foldr :: (a -> b -> b) -> b -> DirectAbstractDeclarator a -> b Source #

foldr' :: (a -> b -> b) -> b -> DirectAbstractDeclarator a -> b Source #

foldl :: (b -> a -> b) -> b -> DirectAbstractDeclarator a -> b Source #

foldl' :: (b -> a -> b) -> b -> DirectAbstractDeclarator a -> b Source #

foldr1 :: (a -> a -> a) -> DirectAbstractDeclarator a -> a Source #

foldl1 :: (a -> a -> a) -> DirectAbstractDeclarator a -> a Source #

toList :: DirectAbstractDeclarator a -> [a] Source #

null :: DirectAbstractDeclarator a -> Bool Source #

length :: DirectAbstractDeclarator a -> Int Source #

elem :: Eq a => a -> DirectAbstractDeclarator a -> Bool Source #

maximum :: Ord a => DirectAbstractDeclarator a -> a Source #

minimum :: Ord a => DirectAbstractDeclarator a -> a Source #

sum :: Num a => DirectAbstractDeclarator a -> a Source #

product :: Num a => DirectAbstractDeclarator a -> a Source #

Traversable DirectAbstractDeclarator Source # |

Instance details

Defined in Language.C.Types.Parse

Methods

traverse :: Applicative f => (a -> f b) -> DirectAbstractDeclarator a -> f (DirectAbstractDeclarator b) Source #

sequenceA :: Applicative f => DirectAbstractDeclarator (f a) -> f (DirectAbstractDeclarator a) Source #

mapM :: Monad m => (a -> m b) -> DirectAbstractDeclarator a -> m (DirectAbstractDeclarator b) Source #

sequence :: Monad m => DirectAbstractDeclarator (m a) -> m (DirectAbstractDeclarator a) Source #

Show i => Show (DirectAbstractDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods showsPrec :: Int -> DirectAbstractDeclarator i -> ShowS Source # show :: DirectAbstractDeclarator i -> String Source # showList :: [DirectAbstractDeclarator i] -> ShowS Source #
Eq i => Eq (DirectAbstractDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods (==) :: DirectAbstractDeclarator i -> DirectAbstractDeclarator i -> Bool Source # (/=) :: DirectAbstractDeclarator i -> DirectAbstractDeclarator i -> Bool Source #
Pretty i => Pretty (DirectAbstractDeclarator i) Source # |
Instance details Defined in Language.C.Types.Parse Methods pretty :: DirectAbstractDeclarator i -> Doc ann Source # prettyList :: [DirectAbstractDeclarator i] -> Doc ann Source #

direct_abstract_declarator :: CParser i m => m (DirectAbstractDeclarator i) Source #

# YACC grammar

The parser above is derived from a modification of the YACC grammar for C99 found at http://www.quut.com/c/ANSI-C-grammar-y-1999.html, reproduced below.

    %token IDENTIFIER TYPE_NAME INTEGER

    %token TYPEDEF EXTERN STATIC AUTO REGISTER INLINE RESTRICT
    %token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID
    %token BOOL COMPLEX IMAGINARY
    %token STRUCT UNION ENUM

    %start parameter_list
    %%

    declaration_specifiers
    	: storage_class_specifier
    	| storage_class_specifier declaration_specifiers
    	| type_specifier
    	| type_specifier declaration_specifiers
    	| type_qualifier
    	| type_qualifier declaration_specifiers
    	| function_specifier
    	| function_specifier declaration_specifiers
    	;

    storage_class_specifier
    	: TYPEDEF
    	| EXTERN
    	| STATIC
    	| AUTO
    	| REGISTER
    	;

    type_specifier
    	: VOID
    	| CHAR
    	| SHORT
    	| INT
    	| LONG
    	| FLOAT
    	| DOUBLE
    	| SIGNED
    	| UNSIGNED
    	| BOOL
    	| COMPLEX
    	| IMAGINARY
     	| STRUCT IDENTIFIER
    	| UNION IDENTIFIER
    	| ENUM IDENTIFIER
    	| TYPE_NAME
    	;

    type_qualifier
    	: CONST
    	| RESTRICT
    	| VOLATILE
    	;

    function_specifier
    	: INLINE
    	;

    declarator
    	: pointer direct_declarator
    	| direct_declarator
    	;

    direct_declarator
    	: IDENTIFIER
    	| '(' declarator ')'
    	| direct_declarator '[' type_qualifier_list ']'
    	| direct_declarator '[' type_qualifier_list * ']'
    	| direct_declarator '[' * ']'
     	| direct_declarator '[' IDENTIFIER ']'
    	| direct_declarator '[' INTEGER ']'
    	| direct_declarator '[' ']'
    	| direct_declarator '(' parameter_list ')'
    	| direct_declarator '(' ')'
    	;

    pointer
    	: *
    	| * type_qualifier_list
    	| * pointer
    	| * type_qualifier_list pointer
    	;

    type_qualifier_list
    	: type_qualifier
    	| type_qualifier_list type_qualifier
    	;

    parameter_list
    	: parameter_declaration
    	| parameter_list ',' parameter_declaration
    	;

    parameter_declaration
    	: declaration_specifiers declarator
    	| declaration_specifiers abstract_declarator
    	| declaration_specifiers
    	;

    abstract_declarator
    	: pointer
    	| direct_abstract_declarator
    	| pointer direct_abstract_declarator
    	;

    direct_abstract_declarator
    	: '(' abstract_declarator ')'
    	| '[' ']'
    	| direct_abstract_declarator '[' ']'
    	| '[' * ']'
    	| direct_abstract_declarator '[' * ']'
    	| '[' IDENTIFIER ']'
    	| direct_abstract_declarator '[' IDENTIFIER ']'
    	| '[' INTEGER ']'
    	| direct_abstract_declarator '[' INTEGER ']'
    	| '(' ')'
    	| '(' parameter_list ')'
    	| direct_abstract_declarator '(' ')'
    	| direct_abstract_declarator '(' parameter_list ')'
    	;

    %%
    #include <stdio.h>

    extern char yytext[];
    extern int column;

    void yyerror(char const *s)
    {
    	fflush(stdout);
    	printf("n%*sn%*sn", column, "^", column, s);
    }

# Testing utilities

cIdentStart :: [Char] Source #

cIdentLetter :: [Char] Source #

cReservedWords :: HashSet String Source #

isTypeName :: Bool -> TypeNames -> String -> Bool Source #