Skip to content

Commit 1901c85

Browse files
committed
Reformatted with hindent.
1 parent c975d91 commit 1901c85

File tree

5 files changed

+2891
-2517
lines changed

5 files changed

+2891
-2517
lines changed

RegistryProcessor/src/DeclarationParser.hs

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
-- A very simple-minded parser for C declarations of the following syntax:
22
-- "const"? type-specifier ("*" "const"?)* identifier ("[" number "]")?
3-
module DeclarationParser ( parse ) where
3+
module DeclarationParser
4+
( parse
5+
) where
46

57
import Control.Monad
68
import Data.Char
@@ -26,51 +28,56 @@ optionalConst :: ReadP ()
2628
optionalConst = option' () (void (token "const"))
2729

2830
parseTypeSpecifier :: ReadP String
29-
parseTypeSpecifier = choice' [
30-
token "void" >> return "()",
31-
token "float" >> return "CFloat",
32-
token "double" >> return "CDouble",
33-
token "int32_t" >> return "Int32",
34-
token "int64_t" >> return "Int64",
35-
do c <- option' "CChar" (token "signed" >> return "CSChar")
36-
choice' [
37-
token "char" >> return c,
38-
token "short" >> return "CShort",
39-
token "int" >> return "CInt",
40-
token "long" >> choice' [token "long" >> return "CLLong",
41-
return "CLong"]],
42-
do _ <- token "unsigned"
43-
choice' [
44-
token "char" >> return "CUChar",
45-
token "short" >> return "CUShort",
46-
token "int" >> return "CUInt",
47-
token "long" >> choice' [token "long" >> return "CULLong",
48-
return "CULong"]],
49-
token "struct" >> parseIdentifier >> return "()", -- Hmmm...
50-
token "GLvoid" >> return "()", -- glGetPerfQueryDataINTEL still mentions this
51-
parseIdentifier ]
31+
parseTypeSpecifier =
32+
choice'
33+
[ token "void" >> return "()"
34+
, token "float" >> return "CFloat"
35+
, token "double" >> return "CDouble"
36+
, token "int32_t" >> return "Int32"
37+
, token "int64_t" >> return "Int64"
38+
, do c <- option' "CChar" (token "signed" >> return "CSChar")
39+
choice'
40+
[ token "char" >> return c
41+
, token "short" >> return "CShort"
42+
, token "int" >> return "CInt"
43+
, token "long" >>
44+
choice' [token "long" >> return "CLLong", return "CLong"]
45+
]
46+
, do _ <- token "unsigned"
47+
choice'
48+
[ token "char" >> return "CUChar"
49+
, token "short" >> return "CUShort"
50+
, token "int" >> return "CUInt"
51+
, token "long" >>
52+
choice' [token "long" >> return "CULLong", return "CULong"]
53+
]
54+
, token "struct" >> parseIdentifier >> return "()" -- Hmmm...
55+
, token "GLvoid" >> return "()" -- glGetPerfQueryDataINTEL still mentions this
56+
, parseIdentifier
57+
]
5258

5359
parseIdentifier :: ReadP String
5460
parseIdentifier = do
5561
skipSpaces
5662
x <- satisfy (\c -> isAlpha c || c == '_')
57-
xs <- munch (\c ->isAlphaNum c || c == '_')
58-
return (x:xs)
63+
xs <- munch (\c -> isAlphaNum c || c == '_')
64+
return (x : xs)
5965

6066
parseArray :: ReadP Int
61-
parseArray = choice' [
62-
do _ <- token "["
63-
skipSpaces
64-
_ <- munch1 isDigit
65-
_ <- token "]"
66-
return 1,
67-
return 0 ]
67+
parseArray =
68+
choice'
69+
[ do _ <- token "["
70+
skipSpaces
71+
_ <- munch1 isDigit
72+
_ <- token "]"
73+
return 1
74+
, return 0
75+
]
6876

6977
token :: String -> ReadP String
7078
token s = skipSpaces >> string s
7179

7280
-- deterministic versions
73-
7481
choice' :: [ReadP a] -> ReadP a
7582
choice' = foldr (<++) pfail
7683

0 commit comments

Comments
 (0)