Commits

Sébastien Ferré committed 5ee57b2

Extended modifiers with boundness (defined/undefined).

Comments (0)

Files changed (2)

     | `Count -> "count"
     | `Highest -> "highest"
     | `Lowest -> "lowest"
-    | `Mod (order,offset,limit) -> "("; 'order; " "; print_int of offset; " "; print_int of limit; ")" ]
+    | `Mod (order,offset,limit,boundness) -> "("; 'order; " "; print_int of offset; " "; print_int of limit; " "; 'boundness; ")" ]
 and print_term = ipp
     [ Var s -> "?"; 's
     | Uri s -> 's
 	| _ = kwd "sample" -> `Appl "SAMPLE"
 	| _ = kwd "concat" -> `Appl "GROUP_CONCAT" ]
     method parse_modif : 'p = dcg
-	[ "decreasing" -> `Mod ("DESC",0,-1)
-        | "increasing" -> `Mod ("ASC",0,-1)
+	[ boundness = self#parse_boundness -> `Mod ("",0,-1, boundness)
+        | order, offset, limit = self#parse_modif_order_offset_limit;
+	  ( _ = ws; boundness = self#parse_boundness -> `Mod (order,offset,limit, boundness)
+          |  -> `Mod (order,offset,limit,"") ) ]
+    method private parse_modif_order_offset_limit = dcg
+	[ "decreasing" -> ("DESC",0,-1)
+        | "increasing" -> ("ASC",0,-1)
         | offset, limit = self#parse_offset_limit;
-	  ( _ = ws; order = self#parse_order -> `Mod (order,offset,limit)
-          |  -> `Mod ("",offset,limit) )
+	  ( _ = ws; order = self#parse_order -> (order,offset,limit)
+          |  -> ("",offset,limit) )
         | limit = Syntax.parse_nat; _ = ws;
-	  ( _ = kwd "first" -> `Mod ("",0,limit)
-	  | order = self#parse_order -> `Mod (order,0,limit) )
-        | order = self#parse_order -> `Mod (order,0,1) ]
+	  ( _ = kwd "first" -> ("",0,limit)
+	  | order = self#parse_order -> (order,0,limit) )
+        | order = self#parse_order -> (order,0,1) ]
     method private parse_offset_limit = dcg
 	[ ord1 = Syntax.parse_ordinal;
 	  ( _ = ws; _ = kwd "to"; _ = ws;
     method private parse_order = dcg
 	[ _ = kwds ["greatest"; "highest"; "latest"] -> "DESC"
         | _ = kwds ["least"; "lowest"; "earliest"] -> "ASC" ]
+    method private parse_boundness = dcg
+	[ _ = kwds ["defined"; "bound"] -> "BOUND"
+        | _ = kwds ["undefined"; "unbound"] -> "!BOUND" ]
 
   end
 
 let rec print = ipp
     [ ls -> LIST0 print_s SEP "\n" of ls; EOF ]
 and print_s = ipp
-    [ `ASK f -> "ASK { "; print_g of f; "}"
+    [ `ASK (`Exists (_, `Modif (`Mod (_,_,_,boundness),x,f))) -> "ASK { "; print_g_boundness of boundness, x, f; "}"
+    | `ASK (`Modif (`Mod (_,_,_,boundness),x,f)) -> "ASK { "; print_g_boundness of boundness, x, f; "}"
+    | `ASK f -> "ASK { "; print_g of f; "}"
     | `SELECT (xs, (`Modif _ as f)) -> print_modif of (xs,f)
     | `SELECT (xs, `Exists (_, (`Modif _ as f))) -> print_modif of (xs,f)
     | `SELECT (_, (`Aggreg _ as f)) -> print_aggreg of f
 and print_modif = ipp
     [ xs, `Modif (op,x,f) ->
       "SELECT DISTINCT "; [ [] -> "*" | xs -> LIST1 print_term SEP " " of xs ] of xs;
-      " WHERE { "; print_g of f; "} "; print_modif_op of (op,x) ]
+      " WHERE { "; print_modif_op of (op,x,f) ]
 and print_modif_op = ipp
-    [ `Highest, x -> print_modif_op of `Mod ("DESC",0,1), x
-    | `Lowest, x -> print_modif_op of `Mod ("ASC",0,1), x
-    | `Mod (order,offset,limit), x -> print_order of order, x; print_offset of offset; print_limit of limit ]
+    [ `Highest, x, f -> print_modif_op of `Mod ("DESC",0,1,""), x, f
+    | `Lowest, x, f -> print_modif_op of `Mod ("ASC",0,1,""), x, f
+    | `Mod (order,offset,limit,boundness), x, f -> print_g_boundness of boundness, x, f; "} "; print_order of order, x; print_offset of offset; print_limit of limit ]
+and print_g_boundness = ipp
+    [ "", x, f -> print_g of f
+    | pred, x, f -> "OPTIONAL { "; print_g of f; "} FILTER ("; 'pred; "("; print_term of x; ")) " ]
 and print_order = ipp
     [ "", x -> 
     | order, x -> "ORDER BY "; 'order; "("; print_term of x; ") " ]