June 20, 2010
Andrei Alexandrescu wrote:

> IMHO it's more general if the regexp took the string type as a
> parameter. This is because later that is easier generalizable to
> accepting a range that's different from an array.

Agreed.

Given T which may be an immutable type, what is the cleanest way of creating a mutable copy of that type? typeof(array.dup) works on arrays but what if T is a value type or any type where .dup doesn't exist?

Ali
June 20, 2010
On 06/20/2010 02:29 PM, Ali Çehreli wrote:
> Andrei Alexandrescu wrote:
>
>  > IMHO it's more general if the regexp took the string type as a
>  > parameter. This is because later that is easier generalizable to
>  > accepting a range that's different from an array.
>
> Agreed.
>
> Given T which may be an immutable type, what is the cleanest way of
> creating a mutable copy of that type? typeof(array.dup) works on arrays
> but what if T is a value type or any type where .dup doesn't exist?
>
> Ali

std.conv.to should work with most sensible combinations.

Andrei
June 21, 2010
Hi Andrei,

== Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article
> On 06/20/2010 12:56 PM, Ali Çehreli wrote:
> > Ben Hanson wrote:
> >> == Quote from Justin Spahr-Summers (Justin.SpahrSummers@gmail.com)'s
> >>> "string" is actually an alias for "immutable(char)[]" (and
> >> similarly for
> >>> the other string types), so its contents are not modifiable, though
> >> its
> >>> length can be adjusted and contents appended. If you need to be
> >> able to
> >>> modify the characters, just use char[] instead. You can then use the .idup property to get a string afterward.
> >>
> >> I'm converted temp_ to CharT[] as suggested, but the conversion back to a string is failing:
> >>
> >> _charset = temp_.idup;
> >>
> >> main.d(76): Error: cannot implicitly convert expression (_adDupT((&
> >> D58TypeInfo_AT4main14__T5regexTAyaZ18basic_string_token5CharT6__initZ),cast
> >>
> >> (string)temp_)) of type immutable(CharT)[] to string
> >
> >
> > Would it work for you if the regex template took the character type instead of the string type?
> >
> > The relevant lines:
> >
> > template regex(CharT)
> > {
> > // ...
> > alias CharT[] StringT;
> > StringT _charset;
> > enum size_t MAX_CHARS = CharT.max + 1;
> > // ...
> > _charset = squeeze(_charset.idup).dup;
> >
> > And then, in main:
> >
> > regex!(char).basic_string_token token_;
> >
> > Ali
> IMHO it's more general if the regexp took the string type as a
> parameter. This is because later that is easier generalizable to
> accepting a range that's different from an array.
> My dream: to have a compile-time-generated regex engine that can operate
> on any input stream.
> Andrei

I'm currently using strings for the regex strings themselves. In lexertl, I use templated free functions what work with iterators, which means input can come from different sources. This sounds like the kind of thing you are talking about?

Regards,

Ben
June 21, 2010
On 06/21/2010 03:37 AM, Ben Hanson wrote:
> I'm currently using strings for the regex strings themselves. In lexertl, I use
> templated free functions what work with iterators, which means input can come
> from different sources. This sounds like the kind of thing you are talking
> about?
>
> Regards,
>
> Ben

Sounds about right!

Andrei
1 2
Next ›   Last »