Re: [Haskell-cafe] Attoparsec: Limiting Parsers to N Bytes, or Combing Parsers?

2011-09-26 Thread Twan van Laarhoven
On 24/09/11 05:21, Evan Laforge wrote: hex2 = (+)$ ((*16)$ higit)* higit higit = subtract (fromEnum '0')$ satisfy isHexDigit color = Color$ hex2* hex2* hex2 How is subtract (fromEnum '0') supposed to convert a hex digit to an Int or Word8? I think you need digitToInt (or an equivalent

Re: [Haskell-cafe] Attoparsec: Limiting Parsers to N Bytes, or Combing Parsers?

2011-09-26 Thread Yitzchak Gale
Evan Laforge wrote: hex2 = (+)$  ((*16)$  higit)*  higit higit = subtract (fromEnum '0')$  satisfy isHexDigit color = Color$  hex2*  hex2*  hex2 Twan van Laarhoven wrote: How is subtract (fromEnum '0') supposed to convert a hex digit to an Int or Word8? I think you need digitToInt (or an

[Haskell-cafe] Attoparsec: Limiting Parsers to N Bytes, or Combing Parsers?

2011-09-23 Thread Michael Craig
Suppose we want to parse a 24-bit hex color value: input :: ByteString input = af093c blah blah blah type Color = (Word8, Word8, Word8) Attoparsec.Char8 exports a nice hexadecimal parser, but it consumes all available hex-flavored input. I'd like to make it consume exactly two bytes, so I

Re: [Haskell-cafe] Attoparsec: Limiting Parsers to N Bytes, or Combing Parsers?

2011-09-23 Thread Evan Laforge
On Fri, Sep 23, 2011 at 8:04 PM, Michael Craig mks...@gmail.com wrote: Suppose we want to parse a 24-bit hex color value: input :: ByteString input = af093c blah blah blah type Color = (Word8, Word8, Word8) Attoparsec.Char8 exports a nice hexadecimal parser, but it consumes all available

Re: [Haskell-cafe] Attoparsec: Limiting Parsers to N Bytes, or Combing Parsers?

2011-09-23 Thread Evan Laforge
BTW you probably want 'data Color = Color !Word8 !Word8 !Word8' On Fri, Sep 23, 2011 at 8:21 PM, Evan Laforge qdun...@gmail.com wrote: On Fri, Sep 23, 2011 at 8:04 PM, Michael Craig mks...@gmail.com wrote: Suppose we want to parse a 24-bit hex color value: input :: ByteString input = af093c

Re: [Haskell-cafe] Attoparsec: Limiting Parsers to N Bytes, or Combing Parsers?

2011-09-23 Thread Michael Craig
I agree on all counts! The hex-handling logic here is so straightforward that it's hardly worth bothering with. In fact, my application's code as it stands looks very similar to what you wrote. I'm really asking because I want to be more fluent in attoparsec. So the question remains: is there a

Re: [Haskell-cafe] Attoparsec: Limiting Parsers to N Bytes, or Combing Parsers?

2011-09-23 Thread Evan Laforge
So the question remains: is there a way to limit a parser to a finite chunk of input? Perhaps a way to run the 'take n' parser on the input and then run another parser on its result? This smells like monadic behavior, but of course with different semantics than the Monad instance for Parser.