Commits

Paweł Wieczorek committed 8bfb48c

added psp_with_own_priority

Comments (0)

Files changed (2)

     psp_reprioritize (f_prio x) (f x)
 
 
+let psp_with_own_priority f_prio f x = 
+    let priority = f_prio x in
+    psp_reprioritize priority (f priority x)
+
 (*--------------------------------------------------------------------------------------------------------------------
- * 
+ * Infix
  *)
 
 let psp_associative_infix f_left f_right prio oper left right =
     psp_infix (f_assoc oper) (f_prio oper) (f_paint oper)
 
 (*--------------------------------------------------------------------------------------------------------------------
+ * Prefix
+ *)
+
+let psp_associative_prefix f_param prio oper param =
+    let prio_param = get_priority param in
+    psp_group_with_priority prio
+        [ oper
+        ; psp_decide_std_bracket (f_param prio prio_param) param
+        ]
+
+let psp_prefix = psp_associative_prefix
+    (fun prio prio_param -> prio > prio_param)
+
+(*--------------------------------------------------------------------------------------------------------------------
  * Output
  *)
 
 val psp_infix : associativity -> priority -> painter -> painter -> painter -> painter
 
 
+val psp_prefix : priority -> painter -> painter -> painter
+
 (**
    Practical helper.
 
 val psp_gen_infix : ('a -> associativity) -> ('a -> priority) -> ('a -> painter)
                  -> 'a -> painter -> painter -> painter
 
+
+(** {2 Various helpers} *)
+
+(**
+    Align priority of obtained painter. 
+
+    {[ psp_correct_priority_after f_prio f t = psp_reprioritize (f_prio t) (f t) ]}
+
+    With this helper a function in similar shape to defined below
+
+    {[
+    let rec psp_expr t = match t with
+        | SomeNode(...) -> psp_group_with_priority (expr_priority t)
+            [ ...
+            ]
+
+    ]}
+
+    can be rewritten to form where priority of constructed painter is set in one place:
+
+    {[
+
+    let rec _psp_expr = function
+        | SomeNode(...) -> psp_group
+            [ ...
+            ]
+
+    and psp_expr = psp_correct_priority_after expr_priority _psp_expr
+
+    ]}
+
+
+*)
+val psp_correct_priority_after : ('a -> priority) -> ('a -> painter) -> 'a -> painter
+
+
+(**
+
+    Another practical helper. Run function with priority of given argument, then
+    reprioritizes computed painter.
+
+    {[
+    psp_with_own_priority f_prio f x = let priority = f_prio x in psp_reprioritize priority (f priority) x
+    }]
+
+    Example:
+
+    {[
+
+    let rec _psp_exr priority = function
+        | SomeNode(...) -> psp_group
+            [ ...
+            ]
+
+    and psp_expr = psp_with_own_priority expr_priority _psp_expr
+
+    ]}
+
+
+ *)
+val psp_with_own_priority : ('a -> priority) -> (priority -> 'a -> painter) -> 'a -> painter
+
+
 (** {2 Output} *)
 
 (**