Copyright | (c) roki 2019 |
---|---|
License | MIT |
Maintainer | falgon53@yahoo.co.jp |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
The module of the Type parsing
Synopsis
- type ConstantResult i = Maybe (ASTError i)
- constantExp :: forall i. (Bits i, Integral i, Show i, Read i) => [TokenLC i] -> ConstructionData i -> Either (ConstantResult i) ([TokenLC i], i)
- isTypeName :: TokenLC i -> ConstructionData i -> Bool
- takeStructFields :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (Map Text (StructMember i), ConstructionData i)
- takeEnumFiels :: (Integral i, Show i, Read i, Bits i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Either (ASTError i) (Map Text i, ConstructionData i)
- arrayDeclSuffix :: forall i. (Integral i, Bits i, Show i, Read i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Maybe (Either (ASTError i) (StorageClass i, [TokenLC i]))
- absDeclaration :: (Integral i, Bits i, Show i, Read i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, [TokenLC i])
- declaration :: (Integral i, Bits i, Show i, Read i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, Maybe (TokenLC i), [TokenLC i])
- takePreType :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, [TokenLC i], ConstructionData i)
- takeType :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, Maybe (TokenLC i), [TokenLC i], ConstructionData i)
- takeTypeName :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, [TokenLC i])
Constant
type ConstantResult i = Maybe (ASTError i) Source #
constantExp :: forall i. (Bits i, Integral i, Show i, Read i) => [TokenLC i] -> ConstructionData i -> Either (ConstantResult i) ([TokenLC i], i) Source #
constantExp
evaluates to a constant expression from token list.
Utilities
isTypeName :: TokenLC i -> ConstructionData i -> Bool Source #
isTypeName
returns True
if the token is a type name, False
otherwise.
Structure and Enum
takeStructFields :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (Map Text (StructMember i), ConstructionData i) Source #
\[ \begin{array}{ccc} \text{struct-decl}&=&\text{"struct"}\ \text{ident?}\ \left(\text{"\{"}\ \text{struct-member}\ \text{"\}"}\right)\text{?}\\ \text{struct-member}&=&\text{pre-type}\ \text{declaration}\ \text{array-decl-suffix}\ \text{";"} \end{array} \]
takeEnumFiels :: (Integral i, Show i, Read i, Bits i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Either (ASTError i) (Map Text i, ConstructionData i) Source #
\[ \begin{array}{ccc} \text{enum-specifier}&=&\text{"enum"}\ \text{ident}\ \mid\ \text{"enum"}\ \text{ident?}\ \text{"\{"}\ \text{enum-list?}\ \text{"\}"}\\ \text{enum-list}&=&\text{enum-elem}\ \left(\text{","}\ \text{enum-elem}\right)\ast\ \text{","?}\\ \text{enum-elem}&=&\text{ident}\ \left(\text{"="}\ \text{const-expr}\right)\text{?} \end{array} \]
Declarations
arrayDeclSuffix :: forall i. (Integral i, Bits i, Show i, Read i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Maybe (Either (ASTError i) (StorageClass i, [TokenLC i])) Source #
HT.TKReserved "[", n, HT.TKReserved "]"
from the beginning of the token sequence.
arrayDeclSuffix
constructs an array type of the given type t
based on
the token sequence if \(k\leq 1\), wraps it in Right
and Just
and returns it with the rest of the token sequence.
If the token HT.TKReserved "["
exists at the beginning of the token sequence,
but the subsequent token sequence is invalid as an array declaration in C programming language,
an error mesage and the token at the error location are returned wrapped in
Left
and Just
. When \(k=0\), Nothing
is returned.
\[ \text{array-decl-suffix}=\left(\text{"["}\ \text{const-expr?}\ \text{"]"}\ \text{array-decl-suffix}\right)\text{?} \]
absDeclaration :: (Integral i, Bits i, Show i, Read i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, [TokenLC i]) Source #
absDeclaration
parses abstract type declarations:
\[ \text{abs-declaration} = \text{"*"*}\ \left(\text{"("}\ \text{abs-declaration}\ \text{")"}\right)\text{?}\ \text{array-decl-suffix} \]
declaration :: (Integral i, Bits i, Show i, Read i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, Maybe (TokenLC i), [TokenLC i]) Source #
\[ \text{declaration} = \text{"*"*}\ \left(\text{"("}\ \text{declaration}\ \text{")"}\ \mid\ \text{ident}\right)\ \text{array-decl-suffix} \]
Type
takePreType :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, [TokenLC i], ConstructionData i) Source #
It is obtained by parsing the front part of the type from the token string.
e.g. int (*)[4]
applied to this function yields int
.
\[\begin{array}{ccc} \text{pre-type}&=&\text{builtin-type}\ \mid\ \text{struct-decl}\ \mid\ \text{typedef-name}\ \mid\ \text{enum-specifier}\\ \text{builtin-type}&=&\text{"void"}\ \mid\ \text{"_Bool"}\ \mid\ \text{"char"}\ \mid\ \text{"short"}\ \mid\ \text{"int"}\ \mid\ \text{"long"}\ \mid\ \text{"long "long"} \end{array} \]
takeType :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, Maybe (TokenLC i), [TokenLC i], ConstructionData i) Source #
takeTypeName :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, [TokenLC i]) Source #
takeTypeName
is used to parse type names used for sizeof etc. Version without takeType
s identifier.