-
-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add regex match iterator #2109
Add regex match iterator #2109
Conversation
b363cde
to
3e8c2d0
Compare
packages/regex/match_iter.pony
Outdated
@@ -0,0 +1,38 @@ | |||
class MatchIterator is Iterator[Match] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per the pony file naming conventions this file shoudl be called match_interator.pony
packages/regex/_test.pony
Outdated
@@ -61,6 +63,43 @@ class iso _TestEq is UnitTest | |||
h.assert_true(r == "1234", """ \d+ =~ "1234" """) | |||
h.assert_true(r != "asdf", """ \d+ !~ "asdf" """) | |||
|
|||
class iso _TestMatchIter is UnitTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be _TestMatchIterator or _TestMatches
packages/regex/match_iter.pony
Outdated
""" | ||
let m = _regex(_subject, _offset)? | ||
_offset = m.end_pos() + 1 | ||
m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a newline at the end of the file?
This looks pretty good, couple small changes. |
packages/regex/match_iterator.pony
Outdated
false | ||
end | ||
|
||
fun ref next() : Match? => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style-wise, the :
here should not have a preceding space, and the ?
should.
When in doubt on style, check the style guide as well as surrounding code.
let m = _regex(_subject, _offset)? | ||
_offset = m.end_pos() + 1 | ||
m | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This little symbol on GitHub is indicating that this file is missing an empty line at the end of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the little symbol, and there is a line at the end of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's odd - it may be indicating that there is extra whitespace on the line at the end of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means "there's no newline at the end of the file".
packages/regex/regex.pony
Outdated
fun matches(subject: String): MatchIterator => | ||
""" | ||
Creates a match iterator from the regular expression that will iterate | ||
over the supplied subject returning matches |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a period at the end of this sentence?
I'm a little bit concerned that the implementation will execute every match twice in a for loop, where both However, that could be optimized by somebody who cared enough about the performance boost to do it, so I'm not necessarily averse to leaving it as-is for now. |
How about removing the It would avoid this sort of problem, where checking if there is a next element can be expensive. There are even cases where it is impossible to check if there's a next value without consuming it. The workaround is kind of awkward and requires caching the value, such as in the I've just had a go at implementing it in the compiler and stdlib. All uses of |
@plietar The problem with that is that every iterator-based loop would have to exit with an exception, which is very expensive. I think caching would be the best solution here if performance turns out to be a problem. |
@plietar - note that in cases where it's impossible to write a |
This is sync approved with a tiny caveat. @autodidaddict can you address @jemc's couple of small formatting issues and then we can merge this? |
I already addressed the formatting issues @SeanTAllen. It's in the "style guidelines" commit. |
I added the missing '.' that was required for this to be merged. |
Add regex match iterator Issue 2093, RFC 044