www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4627] New: Ideas for std.regex.match usage syntax

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4627

           Summary: Ideas for std.regex.match usage syntax
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Ideas for possible changes in std.regex.match() user interface, mostly to
shorten it, but also to make it simpler to use.

This is what you currently ned to use to iterate on matches:

stringtext = "...";
foreach (m; match(text, regex(r"\d")).captures) { ... }


The regex() there is useful because you can add attributes like "g" as second
argument, but often I don't need attributes, while often I may appreciate a
shorter syntax (even if I don't need a built-in regex syntax as in Ruby and
Perl).

So match() can accept as second argument both an engine (regex) or a string,
when attributes are not necessary:

foreach (m; match(text, r"\d").captures) { ... }


Another possible idea to shorten the syntax is to make match() iterable (I
don't know if this is possible or if it is a good idea), this also makes it
simpler to use (no need to know about 'captures'):

foreach (m; match(text, r"\d")) { ... }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4627


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4627


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com



08:41:35 PDT ---
It works exactly like that.

Keeping in mind that captures is a range [full match, submatch0, submatch1,
...] fro a given match.
And foreach (m; match(text, r"\d")) { ... } iterates over consecutive matches
of regex (if "g" option is set, otherwise it's one iteration).

Resolved ?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4627





 Resolved ?
You have improved the D regular expressions a lot, it seems. To me this program crashes at runtime (DMD 2.053): import std.stdio, std.regex; void main() { foreach (m; match("125 155 ss25", r"\d+")) writeln(m); } If I use this line it works: writeln(m.toString()); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4627




10:43:32 PDT ---
Yeah, that's very embarassing bug related to writeln/formattedWrite. 
The reason is that toString seems to have less priority then range formatting.
And ranges that return elements of the same type as range itself are unexpected
in that formatting code.

In essence, it's the same issue as this one
http://d.puremagic.com/issues/show_bug.cgi?id=4604


So let's keep thing where they belong and if you have no futher things for this
bugzilla, I think you should close it. 

And I think adding this simple example in issue 4604 won't hurt.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 06 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4627


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED





 So let's keep thing where they belong and if you have no futher things for this
 bugzilla, I think you should close it.
Right. A benchmark for the regex: http://shootout.alioth.debian.org/debian/program.php?test=regexdna&lang=gdc&id=4
 And I think adding this simple example in issue 4604 won't hurt.
Done. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 06 2011