Re: Parsing byte sequences

If you just want it to work (as opposed to being incredibly efficient), then use scala.util.parsing.input.StreamReader( ... )to create a parser-compatible reader from any Java reader. (This uses apply(...) from the companion object; it's not a constructor call.)

To read an InputStream, use new java.io.InputStreamReader( myInputStream )in place of the "..." above.

To read a byte array, wrap your byte array in a ByteArrayInputStream: new java.io.InputStreamReader( new java.io.ByteArrayInputStream( myArray ) )

In this case, though, if you really wanted/needed efficiency, you'd likely be better off by subclassing Reader[Char] to use a byte array as a buffer. I don't know whether you'd need to wrap your byte array in something that made it obey the java.lang.CharSequence interface; if so, you could just do that directly and use scala.util.parsing.input.CharSequenceReader to get the reader for the parser.

Re: Parsing byte sequences

On Wed, Dec 30, 2009 at 12:36:07AM +1100, John Ky wrote:
> Anyone know how to use the parser combinators on byte arrays and
> InputStreams? I want to write a parser that will parse bytes rather
> than characters.

I happen to be working on a very entertaining project involving that at
this very moment. I'll publish this all pretty soon but here are a few
classes I use to make the standard library seem more byte oriented.
(Some of this is specific to my project.)

On Wed, Dec 30, 2009 at 12:36:07AM +1100, John Ky wrote:
> Anyone know how to use the parser combinators on byte arrays and
> InputStreams? I want to write a parser that will parse bytes rather
> than characters.

I happen to be working on a very entertaining project involving that at
this very moment. I'll publish this all pretty soon but here are a few
classes I use to make the standard library seem more byte oriented.
(Some of this is specific to my project.)

On Wed, Dec 30, 2009 at 12:36:07AM +1100, John Ky wrote:
> Anyone know how to use the parser combinators on byte arrays and
> InputStreams? I want to write a parser that will parse bytes rather
> than characters.

I happen to be working on a very entertaining project involving that at
this very moment. I'll publish this all pretty soon but here are a few
classes I use to make the standard library seem more byte oriented.
(Some of this is specific to my project.)

On Wed, Dec 30, 2009 at 12:36:07AM +1100, John Ky wrote:
> Anyone know how to use the parser combinators on byte arrays and
> InputStreams? I want to write a parser that will parse bytes rather
> than characters.

I happen to be working on a very entertaining project involving that at
this very moment. I'll publish this all pretty soon but here are a few
classes I use to make the standard library seem more byte oriented.
(Some of this is specific to my project.)