[m-rev.] for review: fix a comment

Ian MacLarty maclarty at csse.unimelb.edu.au
Tue May 3 15:33:54 AEST 2011


On Mon, May 02, 2011 at 12:23:49PM +1000, Julien Fischer wrote:
> 
> On Thu, 28 Apr 2011, Ian MacLarty wrote:
> 
> >For review by anyone.
> >
> >Branches: main
> >
> >Change the comment describing the behaviour of parsing_utils.separated_list to
> >match its actual behaviour.
> >
> >I didn't change the behaviour to match the comment, because the test case
> >already tests that the predicate fails for empty sequences,
> 
> That behaviour seems odd - I suspect the test case is wrong.
> 

Ok I agree.  Here's a new diff:

Branches: main

Change the behaviour of parsing_utils.separated_list to return an
empty list instead of failing if its ho argument doesn't match
any input, as documented in the comments.

library/parsing_utils.m:
    As above.

tests/general/test_parsing_utils.exp:
tests/general/test_parsing_utils.m:
    Expect empty lists from separated_list and comma_separated_list.

Index: library/parsing_utils.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/parsing_utils.m,v
retrieving revision 1.7
diff -u -r1.7 parsing_utils.m
--- library/parsing_utils.m	20 Apr 2011 01:19:44 -0000	1.7
+++ library/parsing_utils.m	3 May 2011 05:21:54 -0000
@@ -665,9 +665,12 @@
         punct(Separator, CommaPSrc, _, !PS),
         P(CommaPSrc, CommaPX, !PS)
     ),
-    P(Src, X, !PS),
-    zero_or_more(CommaP, Src, Xs, !PS),
-    Result = [X | Xs].
+    ( P(Src, X, !PS) ->
+        zero_or_more(CommaP, Src, Xs, !PS),
+        Result = [X | Xs]
+    ;
+        Result = []
+    ).
 
 %-----------------------------------------------------------------------------%
 
@@ -678,9 +681,12 @@
         punct(Separator, CommaPSrc, _, !PS),
         P(CommaPSrc, CommaPX, !S, !PS)
     ),
-    P(Src, X, !S, !PS),
-    zero_or_more(CommaP, Src, Xs, !S, !PS),
-    Result = [X | Xs].
+    ( P(Src, X, !S, !PS) ->
+        zero_or_more(CommaP, Src, Xs, !S, !PS),
+        Result = [X | Xs]
+    ;
+        Result = []
+    ).
 
 %-----------------------------------------------------------------------------%
 
Index: tests/general/test_parsing_utils.exp
===================================================================
RCS file: /home/mercury1/repository/tests/general/test_parsing_utils.exp,v
retrieving revision 1.5
diff -u -r1.5 test_parsing_utils.exp
--- tests/general/test_parsing_utils.exp	20 Apr 2011 01:19:44 -0000	1.5
+++ tests/general/test_parsing_utils.exp	3 May 2011 05:21:55 -0000
@@ -194,9 +194,11 @@
 	returned unit as expected
 	[6 chars consumed]
 pass: separated_list("+", punct("!")) on ""
-	failed as expected
+	returned [] as expected
+	[0 chars consumed]
 pass: separated_list("+", punct("!")) on "abc"
-	failed as expected
+	returned [] as expected
+	[0 chars consumed]
 pass: separated_list("+", punct("!")) on "!   abc"
 	returned [unit] as expected
 	[4 chars consumed]
@@ -204,9 +206,11 @@
 	returned [unit, unit, unit] as expected
 	[11 chars consumed]
 pass: comma_separated_list(punct("!")) on ""
-	failed as expected
+	returned [] as expected
+	[0 chars consumed]
 pass: comma_separated_list(punct("!")) on "abc"
-	failed as expected
+	returned [] as expected
+	[0 chars consumed]
 pass: comma_separated_list(punct("!")) on "!   abc"
 	returned [unit] as expected
 	[4 chars consumed]
Index: tests/general/test_parsing_utils.m
===================================================================
RCS file: /home/mercury1/repository/tests/general/test_parsing_utils.m,v
retrieving revision 1.5
diff -u -r1.5 test_parsing_utils.m
--- tests/general/test_parsing_utils.m	20 Apr 2011 01:19:44 -0000	1.5
+++ tests/general/test_parsing_utils.m	3 May 2011 05:21:55 -0000
@@ -291,10 +291,10 @@
 
 test_case("separated_list(\"+\", punct(\"!\"))",
     stringify(separated_list("+", punct("!"))),
-    "", no).
+    "", yes("[]")).
 test_case("separated_list(\"+\", punct(\"!\"))",
     stringify(separated_list("+", punct("!"))),
-    "abc", no).
+    "abc", yes("[]")).
 test_case("separated_list(\"+\", punct(\"!\"))",
     stringify(separated_list("+", punct("!"))),
     "!   abc", yes("[unit]")).
@@ -304,10 +304,10 @@
 
 test_case("comma_separated_list(punct(\"!\"))",
     stringify(comma_separated_list(punct("!"))),
-    "", no).
+    "", yes("[]")).
 test_case("comma_separated_list(punct(\"!\"))",
     stringify(comma_separated_list(punct("!"))),
-    "abc", no).
+    "abc", yes("[]")).
 test_case("comma_separated_list(punct(\"!\"))",
     stringify(comma_separated_list(punct("!"))),
     "!   abc", yes("[unit]")).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list