fork download
  1. import Data.Attoparsec.Text
  2. import qualified Data.Text as T
  3. import Prelude hiding (takeWhile, take)
  4.  
  5. data IndexedFace
  6. = IndexedFaceTriangle Int Int Int
  7. | IndexedFaceQuad Int Int Int Int
  8. deriving (Show)
  9.  
  10. -- | block of faces-lines
  11. faces :: Parser [[(Int, IndexedFace)]]
  12. faces = faceLine `sepBy` endOfLine
  13.  
  14. -- | Line containing up to two indexed faces
  15. faceLine :: Parser [(Int, IndexedFace)]
  16. faceLine = face `sepBy` (take 6)
  17.  
  18. -- | single indexed-face
  19. face :: Parser (Int, IndexedFace)
  20. face = do
  21. i <- index
  22. v1 <- index
  23. v2 <- index
  24. v3 <- index
  25. v4 <- index
  26. case v4 of
  27. 0 -> return (i, IndexedFaceTriangle v1 v2 v3)
  28. _ -> return (i, IndexedFaceQuad v1 v2 v3 v4)
  29.  
  30. -- | node or face index 6 wide
  31. index :: Parser Int
  32. index = do
  33. i <- take 6
  34. return . read . T.unpack $ i
  35.  
  36.  
  37. test1 = do
  38. let ele = T.pack " 1 10 1 9 0 2 1 2 9 0\n"
  39. r = parse faceLine ele
  40. case r of
  41. Partial _ -> print $ feed r (T.pack "")
  42. _ -> print r
  43.  
  44. test2 = do
  45. let eles = T.pack $ concat [" 1 10 1 9 0 2 1 2 9 0\n"
  46. ," 3 11 9 2 0\n"
  47. ," 4 12 8 1 0\n"
  48. ]
  49. r = parse faces eles
  50. case r of
  51. Partial _ -> print $ feed r (T.pack "")
  52. _ -> print r
  53.  
  54. test3 = do
  55. let eles = T.pack $ concat [" 1 10 1 9 0 2 1 2 9 0\n"
  56. ," 3 11 9 2 0\n"
  57. ," 4 12 8 1 0\n"
  58. ]
  59. r = parse faces eles
  60. case r of
  61. Partial _ -> print $ feed r (T.pack "")
  62. _ -> print r
  63.  
  64.  
  65.  
  66. test4 = do
  67. let eles = T.pack $ concat [" 1 10 1 9 0 2 1 2 9 0\n"
  68. ," 3 11 9 2 0\n"
  69. ," 4 12 8 1 0\n"
  70. ]
  71. r = parse faces eles
  72. case r of
  73. Partial _ -> print $ feed r (T.pack "")
  74. _ -> print r
  75.  
  76.  
  77. test5 = do
  78. let eles = T.pack $ concat [" 1 10 1 9 0 2 1 2 9 0\n"
  79. ," 3 11 9 2 0 4 12 8 1 0\n"
  80. ]
  81. r = parse faces eles
  82. case r of
  83. Partial _ -> print $ feed r (T.pack "")
  84. _ -> print r
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.hs:2:18:
    Could not find module `Data.Text'
    Perhaps you meant Data.Set (from containers-0.4.2.1)
    Use -v to see a list of the files searched for.
stdout
Standard output is empty