yin | 20 Jul 15:50 2005
Picon

How to parsing files

Hi,

I need to parse a file in this format:
   float float float
   float float float
Each row has 3-columns of floating procision number divided by white
space. The number of lines is undefined. I use (lines (readFile "..."))
to read the file.

Thnks.

Matej 'Yin' Gagyi
Jake Luck | 20 Jul 18:11 2005

Re: How to parsing files

> I need to parse a file in this format:
>   float float float
>   float float float
> Each row has 3-columns of floating procision number divided by white
> space. The number of lines is undefined. I use (lines (readFile "..."))
> to read the file.

Text.ParserCombinators.Parsec sounds perfect, no?
Henning Thielemann | 20 Jul 18:24 2005
Picon

Re: How to parsing files


On Wed, 20 Jul 2005, Jake Luck wrote:

> > I need to parse a file in this format:
> >   float float float
> >   float float float
> > Each row has 3-columns of floating procision number divided by white
> > space. The number of lines is undefined. I use (lines (readFile "..."))
> > to read the file.
>
> Text.ParserCombinators.Parsec sounds perfect, no?

That's certainly overkill since 'lines', 'words', 'read' will suffice.
Sebastian Sylvan | 22 Jul 16:24 2005
Picon

Re: How to parsing files

On 7/20/05, yin <yin <at> atom.sk> wrote:
> Hi,
> 
> I need to parse a file in this format:
>    float float float
>    float float float
> Each row has 3-columns of floating procision number divided by white
> space. The number of lines is undefined. I use (lines (readFile "..."))
> to read the file.
> 

Off the top of my head:

readVecs :: String -> IO [Vector3 GLfloat]
readVecs f =
    do str <- readFile f
         let mkVec [x,y,z] = Vector3 x y z
         return $ map (mkVec . read . words)  $ lines str

Of course this won't exactly fail gracefully if the file is corrupt or
anything like that...

/S

--

-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862

Gmane