Skip to content

Add object method components #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mlx/jsx_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ let make_jsx_element ~raise ~loc:_ ~tag ~end_tag ~props ~children () =
match tag, end_tag with
| (`Module, _, s), (`Module, _, e) -> equal_longindent s e
| (`Value, _, s), (`Value, _, e) -> equal_longindent s e
| (`Method _, _, s), (`Method _, _, e) -> equal_longindent s e
| (`Obj, _, s), (`Object, _, e) -> equal_longindent s e
| _ -> false
in
if not eq then
Expand All @@ -60,6 +62,15 @@ let make_jsx_element ~raise ~loc:_ ~tag ~end_tag ~props ~children () =
| `Module, loc, txt ->
let txt = Longident.Ldot (txt, "createElement") in
mkexp ~loc (Pexp_ident { loc = make_loc loc; txt })
| `Method (obj, objloc, oploc, op), loc, _ ->
let obj =
mkexp ~loc:objloc
(Pexp_ident { loc = make_loc objloc; txt = obj })
in
mkexp ~loc (Pexp_send (obj, { loc = make_loc oploc; txt = op }))
| `Obj, loc, txt ->
let obj = mkexp ~loc (Pexp_ident { loc = make_loc loc; txt }) in
mkexp ~loc (Pexp_send (obj, { loc = make_loc loc; txt = "make" }))
in
let props =
let prop_exp ~loc name =
Expand Down
5,225 changes: 2,893 additions & 2,332 deletions mlx/parser.ml

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions mlx/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -3662,20 +3662,40 @@ mk_longident(prefix,final):
jsx_longident(uident, lident):
| id = uident { `Module, $sloc, Lident id }
| id = lident { `Value, $sloc, Lident id }
| prefix = uident DOT id = mod_longident {
| id = lident HASH op = LIDENT
{ (`Method (Lident id, $loc(id),$loc(op),op)), $sloc, Lident id}
| prefix = uident DOT id = mod_longident {
let rec rebase = function
| Lident id -> Ldot (Lident prefix, id)
| Ldot (prefix', id) -> Ldot (rebase prefix', id)
| Lapply _ -> assert false
in
`Module, $sloc, rebase id }
| prefix = uident DOT id = val_longident {
| id= lident HASH
{ `Obj, $sloc, Lident id}
| prefix = uident DOT id = val_longident {
let rec rebase = function
| Lident id -> Ldot (Lident prefix, id)
| Ldot (prefix', id) -> Ldot (rebase prefix', id)
| Lapply _ -> assert false
in
`Value, $sloc, rebase id }
| prefix = uident DOT id = val_longident HASH op = LIDENT{
let rec rebase = function
| Lident id -> Ldot (Lident prefix, id)
| Ldot (prefix', id) -> Ldot (rebase prefix', id)
| Lapply _ -> assert false
in
let id = rebase id in
((`Method (id, $loc(id),$loc(op),op)), $sloc, id) }
| prefix = uident DOT id = val_longident HASH {
let rec rebase = function
| Lident id -> Ldot (Lident prefix, id)
| Ldot (prefix', id) -> Ldot (rebase prefix', id)
| Lapply _ -> assert false
in
let id = rebase id in
(`Obj, $sloc, id) }
;
val_longident:
mk_longident(mod_longident, val_ident) { $1 }
Expand Down
11 changes: 11 additions & 0 deletions ocamlmerlin_mlx/ocaml/preprocess/jsx_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ let make_jsx_element ~raise ~loc:_ ~tag ~end_tag ~props ~children () =
match tag, end_tag with
| (`Module, _, s), (`Module, _, e) -> equal_longindent s e
| (`Value, _, s), (`Value, _, e) -> equal_longindent s e
| (`Method _, _, s), (`Method _, _, e) -> equal_longindent s e
| (`Obj, _, s), (`Object, _, e) -> equal_longindent s e
| _ -> false
in
if not eq then
Expand All @@ -61,6 +63,15 @@ let make_jsx_element ~raise ~loc:_ ~tag ~end_tag ~props ~children () =
| `Module, loc, txt ->
let txt = Longident.Ldot (txt, "createElement") in
mkexp ~loc (Pexp_ident { loc = make_loc loc; txt })
| `Method (obj, objloc, oploc, op), loc, _ ->
let obj =
mkexp ~loc:objloc
(Pexp_ident { loc = make_loc objloc; txt = obj })
in
mkexp ~loc (Pexp_send (obj, { loc = make_loc oploc; txt = op }))
| `Obj, loc, txt ->
let obj = mkexp ~loc (Pexp_ident { loc = make_loc loc; txt }) in
mkexp ~loc (Pexp_send (obj, { loc = make_loc loc; txt = "make" }))
in
let props =
let prop_exp ~loc name =
Expand Down
Binary file modified ocamlmerlin_mlx/ocaml/preprocess/parser_raw.cmly
Binary file not shown.
Loading