treating spaces with Parsec

ben.a benedikt.ahrens at web.de
Mon Dec 8 08:22:47 EST 2008


The solution you suggested works really fine. 

Thanks a lot for your effort.

ben



Pixel-2 wrote:
> 
> "ben.a" <benedikt.ahrens at web.de> writes:
> 
> [...]
> 
>> "LC.app : 0 , 2 22. abs : 1 ."
> 
> [...]
> 
>> line = do
>>         spaces
>>         constru <- word
>>         spaces
>>         (char ':')
>>         spaces
>>         ar <- sepBy number separator
>>         return (constru, ar)
> 
> [...]
> 
>> --------   a separator between two integers is a space or a comma
>> separator :: Parser ()
>> separator = skipMany1 (space <|> char ',')
> 
> the culprit is "sepBy number separator": for things like "1 2 " it
> will read a separator, and so will wait for the next number, and won't
> expect eol.
> 
> replace "sepBy number separator" with "endBy number separator" and see
> it will work.
> 
> this is quite ugly though since it allows "xxx : 1, ."
> 
> 
> a better solution could be to use:
> 
> separated_numbers1 :: Parser [Integer]
> separated_numbers1 =
>     do x <- number
>        spaces
>        xs <- (char ',' >> spaces >> separated_numbers1) <|> option []
> separated_numbers1
>        return (x : xs)
> 

-- 
View this message in context: http://www.nabble.com/treating-spaces-with-Parsec-tp20857293p20895257.html
Sent from the Haskell - Libraries mailing list archive at Nabble.com.



More information about the Libraries mailing list