I think I understand your question. I'm not really parsing a general stream, but simply want to use JodaTime from a Scala combinator parser. This is a complete combinator parser that simply wraps JodaTime's DateTimeFormat (with my CharSeq-change) :
trait DateParsers extends RegexParsers { def dateTime(pattern: String): Parser[DateTime] = new Parser[DateTime] { val dateFormat = DateTimeFormat.forPattern(pattern) val dateParser = dateFormat.getParser def jodaParse(text: CharSequence, offset: Int) = { val mutableDateTime = new MutableDateTime val newPos = dateFormat.parseInto(mutableDateTime, text, offset); (mutableDateTime.toDateTime, newPos) } def apply(in: Input) = { val source = in.source val offset = in.offset val start = handleWhiteSpace(source, offset) val (dateTime, endPos) = jodaParse(source, start) if (endPos >= 0) Success(dateTime, in.drop(endPos - offset)) else Failure("Failed to parse date", in.drop(start - offset)) } } } I think the relevant code to your question is the Input class defined in the Scala standard lib: in Parsers.scala: /** The parser input is an abstract reader of input elements, i.e. the type of input the parsers in this component * expect. */ type Input = Reader[Elem] and Reader: /** An interface for streams of values that have positions. * * @author Martin Odersky, Adriaan Moors */ abstract class Reader[+T] { /** If this is a reader over character sequences, the underlying char sequence * If not, throws a <code>NoSuchMethodError</code> exception. */ def source: java.lang.CharSequence = throw new NoSuchMethodError("not a char sequence reader") def offset: Int = throw new NoSuchMethodError("not a char sequence reader") /** Returns the first element of the reader */ def first: T /** Returns an abstract reader consisting of all elements except the first * * @return If <code>atEnd</code> is <code>true</code>, the result will be * <code>this'; otherwise, it's a <code>Reader</code> containing * more elements. */ def rest: Reader[T] /** Returns an abstract reader consisting of all elements except the first * <code>n</code> elements. */ def drop(n: Int): Reader[T] = { var r: Reader[T] = this var cnt = n while (cnt > 0) { r = r.rest; cnt -= 1 } r } /** The position of the first element in the reader */ def pos: Position /** true iff there are no more elements in this reader */ def atEnd: Boolean } As you see, there is no concrete impl. of the source method that I use to pass to JodaTime. There are a few different implementations of Reader. One with a noteworthy note would be: /** A StreamReader reads from a character sequence, typically created as a PagedSeq * from a java.io.Reader * * NOTE: * StreamReaders do not really fulfill the new contract for readers, which * requires a `source' CharSequence representing the full input. * Instead source is treated line by line. * As a consequence, regex matching cannot extend beyond a single line * when a StreamReader are used for input. * * If you need to match regexes spanning several lines you should consider * class <code>PagedSeqReader</code> instead. * * @author Miles Sabin * @author Martin Odersky */ sealed class StreamReader(seq: PagedSeq[Char], off: Int, lnum: Int) extends PagedSeqReader(seq, off) { … But in my case I'm doing a CLI and I actually just pass a String into the framework. This is wrapped in a CharSequenceReader, which just wraps a CharSequence. So I'm not really trying to parse general streams, but rather just bridge the API-mismatch of the combinator parsers and JodaTime. Am I making sense? If theres a public API that's based on CharSequence that would be good enough for me I think? If DateTimeParser or equivalent is part of the public API? I just looked at the source over at http://java.net/projects/jsr-310/sources/svn/content/trunk/jsr-310-ri/src/main/java/javax/time/calendar/format/DateTimeParser.java?rev=1339, and it didn't look like it, but is this the right place to look? Cheers, Viktor On Mon, Jul 11, 2011 at 10:42 AM, Stephen Colebourne <scolebou...@joda.org> wrote: > The JSR-310 public API is based on CharSequence. The private API is > based on String. > > I can't see how CharSequence alone allows you to parse a stream, > because CharSequence's methods are all about random access to a data > structure. Perhaps you can enlighten me? > > Stephen > > > On 11 July 2011 09:32, Viktor Hedefalk <hedef...@gmail.com> wrote: >> Would it be possible to have this change in 310? >> >> Cheers, >> Viktor >> >> On Sat, Feb 5, 2011 at 1:52 AM, Stephen Colebourne <scolebou...@joda.org> >> wrote: >>> OK. >>> >>> I've looked at this, and I don't feel I can make the proposed change >>> without causing jar-hell. While there are no google references to >>> implementations, the reality is that I would be changing the main >>> parsing API on DateTimeFormatter, used by everyone. Methods like >>> parseDateTime(String). >>> >>> Changing it from String to CharSequence is source compatible but >>> binary incompatible (method is bound at compile time). >>> >>> Adding an override taking CharSequence if source compatible and binary >>> upwards compatible, but not downward compatible (code compiled against >>> the new version couldn't run on the old version. >>> >>> Thus, its my opinion that the damage far outweighs the benefits on this. >>> Stephen >>> >>> >>> On 5 February 2011 00:11, James Richardson <ja...@time4tea.net> wrote: >>>> I Get where you are coming from. But if you did want to make a breaking >>>> change then this would be a really appropriate place to do it. I mean if >>>> not >>>> on a major version number then when? >>>> Just a thought. >>>> James >>>> >>>> On 5 Feb 2011 00:03, "Stephen Colebourne" <scolebou...@joda.org> wrote: >>>>> The problem is that the major release number is mostly about removing >>>>> a few deprecated methods. Were I to make this change it would break >>>>> user code, which no other change so far would cause. I don't want to >>>>> get into the JAR-hell situation. >>>>> >>>>> Stephen >>>>> >>>>> >>>>> On 4 February 2011 23:57, James Richardson <ja...@time4tea.net> wrote: >>>>>> Well there is a major release version coming up... That would be an >>>>>> appropriate time to make a breaking change, no? >>>>>> James >>>>>> >>>>>> On 4 Feb 2011 23:43, "Stephen Colebourne" <scolebou...@joda.org> wrote: >>>>>>> On 4 February 2011 23:39, Viktor Hedefalk <hedef...@gmail.com> wrote: >>>>>>>> I guess the most obvious backwards compatability issue would be if >>>>>>>> someone had implemented his own DateTimeParser. Hopefully that >>>>>>>> shouldn't be too common though, it's really just an internal >>>>>>>> interface, right? >>>>>>> >>>>>>> Unfortunately, no. I have encouraged users to implement this interface >>>>>>> to solve some formatting issues. Thus I can't change it. Nor would I >>>>>>> want to create a DateTimeParser2. >>>>>>> >>>>>>> Stephen >>>>>>> >>>>>>> >>>>>>> >>>>>>> ------------------------------------------------------------------------------ >>>>>>> The modern datacenter depends on network connectivity to access >>>>>>> resources >>>>>>> and provide services. The best practices for maximizing a physical >>>>>>> server's >>>>>>> connectivity to a physical network are well understood - see how these >>>>>>> rules translate into the virtual world? >>>>>>> http://p.sf.net/sfu/oracle-sfdevnlfb >>>>>>> _______________________________________________ >>>>>>> Joda-interest mailing list >>>>>>> Joda-interest@lists.sourceforge.net >>>>>>> https://lists.sourceforge.net/lists/listinfo/joda-interest >>>>>>> >>>>>> >>>>>> >>>>>> ------------------------------------------------------------------------------ >>>>>> The modern datacenter depends on network connectivity to access resources >>>>>> and provide services. The best practices for maximizing a physical >>>>>> server's >>>>>> connectivity to a physical network are well understood - see how these >>>>>> rules translate into the virtual world? >>>>>> http://p.sf.net/sfu/oracle-sfdevnlfb >>>>>> _______________________________________________ >>>>>> Joda-interest mailing list >>>>>> Joda-interest@lists.sourceforge.net >>>>>> https://lists.sourceforge.net/lists/listinfo/joda-interest >>>>>> >>>>>> >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> The modern datacenter depends on network connectivity to access resources >>>>> and provide services. The best practices for maximizing a physical >>>>> server's >>>>> connectivity to a physical network are well understood - see how these >>>>> rules translate into the virtual world? >>>>> http://p.sf.net/sfu/oracle-sfdevnlfb >>>>> _______________________________________________ >>>>> Joda-interest mailing list >>>>> Joda-interest@lists.sourceforge.net >>>>> https://lists.sourceforge.net/lists/listinfo/joda-interest >>>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> The modern datacenter depends on network connectivity to access resources >>>> and provide services. The best practices for maximizing a physical server's >>>> connectivity to a physical network are well understood - see how these >>>> rules translate into the virtual world? >>>> http://p.sf.net/sfu/oracle-sfdevnlfb >>>> _______________________________________________ >>>> Joda-interest mailing list >>>> Joda-interest@lists.sourceforge.net >>>> https://lists.sourceforge.net/lists/listinfo/joda-interest >>>> >>>> >>> >>> ------------------------------------------------------------------------------ >>> The modern datacenter depends on network connectivity to access resources >>> and provide services. The best practices for maximizing a physical server's >>> connectivity to a physical network are well understood - see how these >>> rules translate into the virtual world? >>> http://p.sf.net/sfu/oracle-sfdevnlfb >>> _______________________________________________ >>> Joda-interest mailing list >>> Joda-interest@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/joda-interest >>> >> >> ------------------------------------------------------------------------------ >> All of the data generated in your IT infrastructure is seriously valuable. >> Why? It contains a definitive record of application performance, security >> threats, fraudulent activity, and more. Splunk takes this data and makes >> sense of it. IT sense. And common sense. >> http://p.sf.net/sfu/splunk-d2d-c2 >> _______________________________________________ >> Joda-interest mailing list >> Joda-interest@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/joda-interest >> > > ------------------------------------------------------------------------------ > All of the data generated in your IT infrastructure is seriously valuable. > Why? It contains a definitive record of application performance, security > threats, fraudulent activity, and more. Splunk takes this data and makes > sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-d2d-c2 > _______________________________________________ > Joda-interest mailing list > Joda-interest@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/joda-interest > ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ Joda-interest mailing list Joda-interest@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/joda-interest