Skip to content
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

fix regex serialization #11844

Merged
merged 1 commit into from
Jun 26, 2015
Merged

fix regex serialization #11844

merged 1 commit into from
Jun 26, 2015

Conversation

tanmaykm
Copy link
Member

This should fix serialization of Regex types broken by recent changes.
Also added a test, and comparison methods (required for the test).

@StefanKarpinski
Copy link
Sponsor Member

How about a test to make sure it doesn't regress again?

@tanmaykm
Copy link
Member Author

Yes. Added regex serialization test.

!isequal(a.compile_options, b.compile_options) && return false
!isequal(a.match_options, b.match_options) && return false
return true
end
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

== and isequal do the same thing on all of these types, so the second definition is unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, kept is so as to avoid a regression if any of it changes in future. But probably better to remove it.

function ==(a::Regex, b::Regex)
(a.pattern != b.pattern) && return false
(a.compile_options != b.compile_options) && return false
(a.match_options != b.match_options) && return false
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better:

a.pattern == b.pattern && a.compile_options == b.compile_options && a.match_options == b.match_options

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's much more concise.

@tanmaykm
Copy link
Member Author

Not sure why having == on Regex is breaking Dates parsing

@quinnj
Copy link
Member

quinnj commented Jun 25, 2015

Probably this line. Basically, when parsing a date, a "transition" delimter (from one date part to another) can be a character, string, or regex. This code probably needs a cleanup.

@tanmaykm
Copy link
Member Author

@quinnj Changing that to
slot = (isa(tran, Regex) && (tran == r"$")) || (tran == "") ? FixedWidthSlot : DelimitedSlot
didn't seem to have an effect.

Any ideas?


function ==(a::Regex, b::Regex)
a.pattern == b.pattern && a.compile_options == b.compile_options && a.match_options == b.match_options
end
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StefanKarpinski do we need to define hash also?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. This ought to do it:

const hashre_seed = UInt === UInt64 ? 0x67e195eb8555e72d : 0xe32373e4

function hash(r::Regex, h::UInt)
    h += hashre_seed
    h = hash(r.pattern, h)
    h = hash(r.compile_options, h)
    h = hash(r.match_options, h)
end

@quinnj
Copy link
Member

quinnj commented Jun 25, 2015

Changing that line to slot = tran == "" ? FixedWidthSlot : DelimitedSlot actually allows all tests to pass for me. Don't ask me why it was in there in the first place, but I guess we didn't need it (*ducks from not remembering the reason for own code...).

@StefanKarpinski
Copy link
Sponsor Member

Ok – once this passes CI and gets merged, we can revert that commit and make your change.

also:
- add regex comparison method and serialization test
- define hash for regex
- fix date parsing
@quinnj
Copy link
Member

quinnj commented Jun 26, 2015

Poor travis is getting a beating this week!

@tanmaykm
Copy link
Member Author

Yeah, unfortunately. But we got a green from Travis now!

StefanKarpinski added a commit that referenced this pull request Jun 26, 2015
@StefanKarpinski StefanKarpinski merged commit 412918a into JuliaLang:master Jun 26, 2015
@@ -71,7 +71,7 @@ function DateFormat(f::AbstractString,locale::AbstractString="english")
for (i,k) in enumerate(s)
k == "" && break
tran = i >= endof(s) ? r"$" : match(Regex("(?<=$(s[i])).*(?=$(s[i+1]))"),f).match
slot = tran == "" || tran == r"$" ? FixedWidthSlot : DelimitedSlot
slot = tran == "" ? FixedWidthSlot : DelimitedSlot
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why was this change reasonable? Was the logic just wrong before and happened to work because of the lack of an equality operator for regular expressions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. If tran <: Regex, slot must be a DelimitedSlot for the correct getslot method to be invoked. It was working till now because the equality test on Regex types was failing.
@quinnj ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I think that's the case. The slot-parsing code here went through a few iterations, so my guess is that it may have been more relevant at an earlier iteration, but then didn't matter as much and didn't cause anything else to fail since it was always false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants