Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[feature] opa syntax: sugar for immediate execution of a dom transfor…

…mation
  • Loading branch information...
commit 41273b9cfef8df7f7c8985e57d8763060539bf6a 1 parent f008678
@OpaOnWindowsNow OpaOnWindowsNow authored
View
1  opacapi/opacapi.ml
@@ -77,6 +77,7 @@ struct
let (!!) s = !! ("Dom_" ^ s)
let select_class = !! "select_class"
let select_id = !! "select_id"
+ let transform = !! "transform"
end
module Core_server_code =
View
50 opalang/syntax/opa_parser.trx
@@ -445,8 +445,8 @@ pattern = deco just_pattern_as_coerce
*)
;/** expression **/
-expr <- expr_1
-;expr_1 = deco just_expr_1;
+expr <- top_expr
+;top_expr = deco just_top_expr;
;expr0 = deco just_expr0;
;expr7 = deco just_expr7;
;expr8 = deco just_expr8;
@@ -472,17 +472,44 @@ let ident_careful_deco rule = (=careful_deco(rule)):t {{let (i,label) = t in (Id
;NegOp = ident_careful_deco( "-." !OpCont {{ Opacapi.unary_minus_dot }}
/ "-" !OpCont {{ Opacapi.unary_minus }})
+
(**
{7 The different levels of expressions }
*)
-just_expr_1 <- (=deco(Parser_path.path_write)):pa (=deco(larrow)):p expr:e
- {{ let (path,pos) = pa in
- let ident = var_to_exprvar ("<-",label p) in
- Apply (ident,encode_tuple_pos [(DBPath (path,QmlAst.Db.Ref),pos);e]) }}
- / expr0:e1 (=deco(larrow)):p expr:e2
- {{ let ident = var_to_exprvar ("<-",label p) in
- Apply (ident, encode_tuple_pos [e1;e2]) }}
- / just_expr0
+
+/** db path write destination **/
+db_path_write <- (=deco(Parser_path.path_write)):pa
+{{
+ let (path,pos) = pa in (DBPath (path,QmlAst.Db.Ref),pos)
+}}
+
+/** db path write **/
+write_expr <- (=deco(larrow)):p expr0:e2 {{ e2 }}
+
+/** side effect expr **/
+se_expr = deco just_se_expr;
+
+just_se_expr <-
+ (* on dom *)
+ / pos:p Action.action:a
+ {{
+ let l = list_expr_of_expr_list [a] p in
+ dom_transform l
+ }}
+ (* dbpath write *)
+ / db_path_write:e1 write_expr:e2 {{ db_write e1 e2 }}
+
+/** top expr **/
+just_top_expr <-
+ / just_se_expr
+
+ / expr0:e1 write_expr?:e2 (* normal expr + dbpath write *)
+ {{
+ match e2 with
+ | Some e2 -> db_write e1 e2
+ | None -> undecorate e1
+ }}
+
just_expr0 <- expr1:e (=exact_symbol("%"))?:o
{{ match o with
| None -> undecorate e
@@ -883,7 +910,8 @@ letin <- pos:pos1 local_binding_directives:dirs Opa_lexer.REC (=list1pos(rec_bin
and <- spacing pos:p Opa_lexer.AND {{ p }}
(* the ! here is here to prevent code such as {r=123x} to parse as {r=123 x}
* because the user then have ununderstandable type errors *)
-separator <- (spacing semic / not_assign ![~a-zA-Z`_]) pos:p {{ p }}
+strict_separator <- spacing semic
+separator <- (strict_separator / not_assign ![~a-zA-Z`_]) pos:p {{ p }}
not_assign <- !(spacing may_coerce assign)
(**
View
11 opalang/syntax/parser_utils.ml
@@ -764,6 +764,9 @@ let cssentrymap_empty label = dots ["Css_private";"Entry_map_empty"] label
let stringmap_add pos k v map = dots ["StringMap";"add"] pos & [k;v;map]
let cssentrymap_add pos k v map = dots ["Css_private";"Entry_map_add"] pos & [k;v;map]
let map_add_merge pos k data map = ident Opacapi.internal__add_css_entry pos & [k;data;map]
+let db_write e1 e2 =
+ let ident = var_to_exprvar ("<-",label e2) in
+ Apply (ident, encode_tuple_pos [e1;e2])
(*
* Utils on patterns
@@ -1386,3 +1389,11 @@ and rewrite_record_update (e:(_,_) expr) (ts:tree list) =
let rewrite_long_extend_record fields expr =
let trees = make_record_tree fields in
rewrite_record_update expr trees
+
+(*
+ * Functions that are expected to be defined later
+ *)
+let dom_transform l =
+ let ident = var_to_exprvar ("Dom_transform", nlabel l) in
+ Apply(ident, encode_tuple_pos [l])
+
View
2  opalang/syntax/parser_utils.mli
@@ -256,6 +256,8 @@ val cssentrymap_empty : annot -> (string, 'a) expr
val stringmap_add : annot -> (string, 'a) expr -> (string, 'a) expr -> (string, 'a) expr -> (string, 'a) expr
val cssentrymap_add : annot -> (string, 'a) expr -> (string, 'a) expr -> (string, 'a) expr -> (string, 'a) expr
val map_add_merge : annot -> (string, 'a) expr -> (string, 'a) expr -> (string, 'a) expr -> (string, 'a) expr
+val db_write : (string, 'a) expr -> (string, 'a) expr -> (string, 'a) expr_node
+val dom_transform : (string, [> `coerce ] as 'a) expr -> (string, 'a) expr_node
(** Utilities on patterns *)
val if_then_else : ('a, 'b) coerced_expr -> ('a, 'b) expr -> ('a, 'b) expr option -> ('a, 'b) expr_node
View
3  stdlib/core/xhtml/dom.opa
@@ -2072,6 +2072,9 @@ type Dom.Transformation.verb = { append } / {prepend} / {set}
@opacapi type Dom.Transformation.subject = { value: string} / {content:xhtml} / {css:`Css.properties`} / {property : string ; value_p : string}
@opacapi type Dom.transformation = { jq : dom ; subject : Dom.Transformation.subject ; verb : Dom.Transformation.verb} // TODO: turn into @abstract.
+@opacapi Dom_transform = Dom.transform
+
+
/**
* @deprecated
*/

0 comments on commit 41273b9

Please sign in to comment.
Something went wrong with that request. Please try again.