my $rxParsePath = qr {(?x) # Use extended regular expression syntax to # allow comments and white space ^ # Anchor pattern to beginning of string (?=.) # Zero-width look ahead assertion to ensure # that there must be at least one character # for the match to succeed (.*/)? # A memory grouping (1st) for path, greedy # match of any characters up to and including # the rightmost slash (the path part) with a # quantifier of '?' (0 or 1), i.e. there # may or may not be a directory part ( # Open memory grouping (2nd) for file name (.*?) # A memory grouping (3rd) for file name stub # of a non-greedy match of any character # without a quantifier since, if there is a # file name part, at least some of it will # form a stub otherwise it would be a dot-file ( # A memory grouping (4th) for file name # extension (?<=[^/]) # zero width look behind assertion such # that following pattern will only succeed # if preceded by any caracter other than # a slash '/' \.[^.]+ # a literal dot '.' followed by one or more # non-dots )? # Close memory grouping (4th) with a quantifier # of '?' (0 or 1), i.e. there may or may not # be a file name extension part )? # Close memory grouping (2nd) with a quantifier # of '?' (0 or 1), i.e. there may or may not # be a file name part $ # Anchor pattern to end of string };
Name:
Anonymous2015-11-06 14:53
Comments that are nothing more than verbose English rehashes of the code suck.
Name:
Anonymous2015-11-06 18:20
Writing monadic parsers is much easier and you almost never have to write a book to document them.
parse :: String -> Either Error Result parse str = - case flatten $ p str of - ("", "", "") -> Left "No path" - (d, f, e) -> Right $ R d (f ++ e) f e + case p str of + ("", ("", "")) -> Left "No path" + (d, (f, e)) -> Right $ R d (f ++ e) f e
>>7 some test cases: "foo/bar/baz.boo.bee" should return ".bee" as the extension and "baz.boo" as the basename "foo/.bar" should return ".bar" as the basename and no extension. "foo/bar." should return "bar." as the basename and no extension
Name:
Anonymous2015-11-08 14:10
>>11 Why? Why is it the job of the regex to determine ".bar" is actually the whole filename? Dealing with such a platform-specific special case would logically be the job of the enclosing program.
>>16 The ellipsis was a prompt for you to finish the sentence as a continuation of the statement in >>14. Acceptable responses include ``need not be correct, obviously'' and ``is unrelated to the problem domain''.
>>18 Let's go through the conversation I would have liked to have had with you.
A. Why? Why is it the job of the regex to determine ".bar" is actually the whole filename? Dealing with such a platform-specific special case would logically be the job of the enclosing program. B. Because your code should be correct. A. And the specification...? B. The specification need not be correct, obviously. The specification is unrelated to the problem domain.
Now can you please stop ruining my fantasies?
Name:
Anonymous2015-11-09 23:47
>>17,19 The ellipsis adds what is known as a `pregnant' or `meaningful' pause, and signifies that you'd like the listener to carefully consider the meaning of the preceding sentence, but does not usually prompt a direct continuation by your opponent.
The pause is correct, but you would have to additionally roll your hands in front of you in the way that in this part of the world is recognized as meaning `go on' or `continue'.
Name:
Anonymous2015-11-10 19:28
>>20 I did gesture for you to continue, you just weren't there to see it.
Name:
Anonymous2015-11-10 20:49
>>21 I hereby register a gesture for you to check these duplicated digits.
Name:
Anonymous2015-11-11 1:40
This thread is very readable. Except for the Perl parts.
Name:
Anonymous2015-11-11 8:27
This thread is very checkable. Except for the non-dubs parts.