summaryrefslogtreecommitdiff
path: root/src/Codec/Wavefront/Token.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Codec/Wavefront/Token.hs')
-rw-r--r--src/Codec/Wavefront/Token.hs28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/Codec/Wavefront/Token.hs b/src/Codec/Wavefront/Token.hs
index 71691a8..01acd5c 100644
--- a/src/Codec/Wavefront/Token.hs
+++ b/src/Codec/Wavefront/Token.hs
@@ -81,7 +81,7 @@ cleanupTokens = catMaybes
81-- Location ---------------------------------------------------------------------------------------- 81-- Location ----------------------------------------------------------------------------------------
82 82
83location :: Parser Location 83location :: Parser Location
84location = skipSpace *> string "v " *> skipHSpace *> parseXYZW <* eol 84location = string "v " *> skipHSpace *> parseXYZW <* eol
85 where 85 where
86 parseXYZW = do 86 parseXYZW = do
87 xyz <- float `sepBy1` skipHSpace 87 xyz <- float `sepBy1` skipHSpace
@@ -96,7 +96,7 @@ location = skipSpace *> string "v " *> skipHSpace *> parseXYZW <* eol
96-- Normal ------------------------------------------------------------------------------------------ 96-- Normal ------------------------------------------------------------------------------------------
97 97
98normal :: Parser Normal 98normal :: Parser Normal
99normal = skipSpace *> string "vn " *> skipHSpace *> parseIJK <* eol 99normal = string "vn " *> skipHSpace *> parseIJK <* eol
100 where 100 where
101 parseIJK = do 101 parseIJK = do
102 ijk <- float `sepBy1` skipHSpace 102 ijk <- float `sepBy1` skipHSpace
@@ -108,7 +108,7 @@ normal = skipSpace *> string "vn " *> skipHSpace *> parseIJK <* eol
108-- Texture coordinates ----------------------------------------------------------------------------- 108-- Texture coordinates -----------------------------------------------------------------------------
109 109
110texCoord :: Parser TexCoord 110texCoord :: Parser TexCoord
111texCoord = skipSpace *> string "vt " *> skipHSpace *> parseUVW <* eol 111texCoord = string "vt " *> skipHSpace *> parseUVW <* eol
112 where 112 where
113 parseUVW = do 113 parseUVW = do
114 uvw <- float `sepBy1` skipHSpace 114 uvw <- float `sepBy1` skipHSpace
@@ -121,7 +121,7 @@ texCoord = skipSpace *> string "vt " *> skipHSpace *> parseUVW <* eol
121-- Parameter-space coordinates ----------------------------------------------------------------------------- 121-- Parameter-space coordinates -----------------------------------------------------------------------------
122 122
123paramCoord :: Parser ParamCoord 123paramCoord :: Parser ParamCoord
124paramCoord = skipSpace *> string "vp " *> skipHSpace *> parseUVW <* eol 124paramCoord = string "vp " *> skipHSpace *> parseUVW <* eol
125 where 125 where
126 parseUVW = do 126 parseUVW = do
127 uvw <- float `sepBy1` skipHSpace 127 uvw <- float `sepBy1` skipHSpace
@@ -134,13 +134,12 @@ paramCoord = skipSpace *> string "vp " *> skipHSpace *> parseUVW <* eol
134-- Points ------------------------------------------------------------------------------------------ 134-- Points ------------------------------------------------------------------------------------------
135 135
136points :: Parser [Point] 136points :: Parser [Point]
137points = skipSpace *> string "p " *> skipHSpace *> fmap Point decimal `sepBy1` skipHSpace <* eol 137points = string "p " *> skipHSpace *> fmap Point decimal `sepBy1` skipHSpace <* eol
138 138
139---------------------------------------------------------------------------------------------------- 139----------------------------------------------------------------------------------------------------
140-- Lines ------------------------------------------------------------------------------------------- 140-- Lines -------------------------------------------------------------------------------------------
141lines :: Parser [Line] 141lines :: Parser [Line]
142lines = do 142lines = do
143 skipSpace
144 _ <- string "l " 143 _ <- string "l "
145 skipHSpace 144 skipHSpace
146 pointIndices <- parsePointIndices 145 pointIndices <- parsePointIndices
@@ -159,7 +158,6 @@ lines = do
159-- Faces ------------------------------------------------------------------------------------------- 158-- Faces -------------------------------------------------------------------------------------------
160face :: Parser Face 159face :: Parser Face
161face = do 160face = do
162 skipSpace
163 _ <- string "f " 161 _ <- string "f "
164 skipHSpace 162 skipHSpace
165 faceIndices <- parseFaceIndices 163 faceIndices <- parseFaceIndices
@@ -184,37 +182,37 @@ face = do
184-- Groups ------------------------------------------------------------------------------------------ 182-- Groups ------------------------------------------------------------------------------------------
185 183
186groups :: Parser [Text] 184groups :: Parser [Text]
187groups = skipSpace *> string "g " *> skipHSpace *> name `sepBy` skipHSpace <* eol 185groups = string "g " *> skipHSpace *> name `sepBy` skipHSpace <* eol
188 186
189---------------------------------------------------------------------------------------------------- 187----------------------------------------------------------------------------------------------------
190-- Objects ----------------------------------------------------------------------------------------- 188-- Objects -----------------------------------------------------------------------------------------
191 189
192object :: Parser Text 190object :: Parser Text
193object = skipSpace *> string "o " *> skipHSpace *> spacedName <* eol 191object = string "o " *> skipHSpace *> spacedName <* eol
194 192
195---------------------------------------------------------------------------------------------------- 193----------------------------------------------------------------------------------------------------
196-- Material libraries ------------------------------------------------------------------------------ 194-- Material libraries ------------------------------------------------------------------------------
197 195
198mtllib :: Parser [Text] 196mtllib :: Parser [Text]
199mtllib = skipSpace *> string "mtllib " *> skipHSpace *> name `sepBy1` skipHSpace <* eol 197mtllib = string "mtllib " *> skipHSpace *> name `sepBy1` skipHSpace <* eol
200 198
201---------------------------------------------------------------------------------------------------- 199----------------------------------------------------------------------------------------------------
202-- Using materials --------------------------------------------------------------------------------- 200-- Using materials ---------------------------------------------------------------------------------
203 201
204usemtl :: Parser Text 202usemtl :: Parser Text
205usemtl = skipSpace *> string "usemtl " *> skipHSpace *> spacedName <* eol 203usemtl = string "usemtl " *> skipHSpace *> spacedName <* eol
206 204
207---------------------------------------------------------------------------------------------------- 205----------------------------------------------------------------------------------------------------
208-- Smoothing groups -------------------------------------------------------------------------------- 206-- Smoothing groups --------------------------------------------------------------------------------
209smoothingGroup :: Parser Natural 207smoothingGroup :: Parser Natural
210smoothingGroup = skipSpace *> string "s " *> skipHSpace *> offOrIndex <* skipHSpace <* eol 208smoothingGroup = string "s " *> skipHSpace *> offOrIndex <* skipHSpace <* eol
211 where 209 where
212 offOrIndex = string "off" *> pure 0 <|> decimal 210 offOrIndex = string "off" *> pure 0 <|> decimal
213 211
214---------------------------------------------------------------------------------------------------- 212----------------------------------------------------------------------------------------------------
215-- Comments ---------------------------------------------------------------------------------------- 213-- Comments ----------------------------------------------------------------------------------------
216comment :: Parser () 214comment :: Parser ()
217comment = skipSpace *> string "#" *> (() <$ manyTill anyChar eol) 215comment = string "#" *> (() <$ manyTill anyChar eol)
218 216
219---------------------------------------------------------------------------------------------------- 217----------------------------------------------------------------------------------------------------
220-- Special parsers --------------------------------------------------------------------------------- 218-- Special parsers ---------------------------------------------------------------------------------
@@ -250,6 +248,6 @@ untilEnd :: Parser a -> Parser [a]
250untilEnd p = go 248untilEnd p = go
251 where 249 where
252 go = do 250 go = do
253 a <- p 251 skipSpace
254 end <- atEnd 252 end <- atEnd
255 if end then pure [a] else fmap (a:) go 253 if end then pure [] else (:) <$> p <*> go