Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jsexplain
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verified Software
jsexplain
Commits
aa4ce4b3
Commit
aa4ce4b3
authored
8 years ago
by
Alan Schmitt
Committed by
Thomas Wood
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
let%some
parent
cd277b69
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
generator/monad_ppx.ml
+40
-29
40 additions, 29 deletions
generator/monad_ppx.ml
generator/tests/jsref/JsInterpreter.ml
+248
-245
248 additions, 245 deletions
generator/tests/jsref/JsInterpreter.ml
generator/tests/jsref/JsInterpreterMonads.ml
+1
-0
1 addition, 0 deletions
generator/tests/jsref/JsInterpreterMonads.ml
with
289 additions
and
274 deletions
generator/monad_ppx.ml
+
40
−
29
View file @
aa4ce4b3
...
...
@@ -6,12 +6,12 @@ open Longident
let
monad_mapping
=
[(
"run"
,
"if_run"
);
(*("spec", "if_spec"); *)
(
"string"
,
"if_string"
);
(
"object"
,
"if_object"
);
(
"value"
,
"if_value"
);
(
"prim"
,
"if_prim"
);
(
"number"
,
"if_number"
);
(
"some"
,
"if_some"
);
(*("success", "ifsuccess")*)
]
...
...
@@ -28,7 +28,6 @@ becomes
*)
let
generate_mapper
namesid
=
function
argv
->
{
default_mapper
with
expr
=
fun
mapper
expr
->
...
...
@@ -36,37 +35,49 @@ let generate_mapper namesid = function argv ->
match
expr
with
(* Is this an extension node? *)
|
{
pexp_desc
=
(* Should have name "getenv". *)
Pexp_extension
({
txt
=
name
;
loc
}
,
pstr
)}
->
begin
try
let
ident
=
List
.
assoc
name
namesid
in
match
pstr
with
|
PStr
[{
pstr_desc
=
Pstr_eval
({
pexp_loc
=
loc
;
pexp_desc
=
Pexp_let
(
rf
,
[{
pvb_pat
=
{
ppat_desc
=
Ppat_tuple
[
p1
;
p2
]};
pvb_expr
=
e
}]
,
cont
)
}
,
_
)}]
->
Exp
.
apply
~
loc
(
Exp
.
ident
(
Location
.
mkloc
(
Longident
.
Lident
ident
)
Location
.
none
))
[(
""
,
aux
e
);
(
""
,
Exp
.
fun_
""
None
p1
(
Exp
.
fun_
""
None
p2
(
aux
cont
)))]
|
_
->
try
let
ident
=
List
.
assoc
name
namesid
in
match
pstr
with
|
PStr
[{
pstr_desc
=
Pstr_eval
({
pexp_loc
=
loc
;
pexp_desc
=
Pexp_let
(
rf
,
[{
pvb_pat
=
{
ppat_desc
=
Ppat_var
_
}
as
p
;
pvb_expr
=
e
}]
,
cont
)
}
,
_
)}]
->
Exp
.
apply
~
loc
(
Exp
.
ident
(
Location
.
mkloc
(
Longident
.
Lident
ident
)
Location
.
none
))
[(
""
,
aux
e
);
(
""
,
Exp
.
fun_
""
None
p
(
aux
cont
))]
|
PStr
[{
pstr_desc
=
Pstr_eval
({
pexp_loc
=
loc
;
pexp_desc
=
Pexp_let
(
rf
,
[{
pvb_pat
=
{
ppat_desc
=
Ppat_tuple
[
p1
;
p2
]};
pvb_expr
=
e
}]
,
cont
)
}
,
_
)}]
->
Exp
.
apply
~
loc
(
Exp
.
ident
(
Location
.
mkloc
(
Longident
.
Lident
ident
)
Location
.
none
))
[(
""
,
aux
e
);
(
""
,
Exp
.
fun_
""
None
p1
(
Exp
.
fun_
""
None
p2
(
aux
cont
)))]
|
_
->
raise
(
Location
.
Error
(
Location
.
error
~
loc
(
"error with let%"
^
name
)))
with
|
Not_found
->
raise
(
Location
.
Error
(
Location
.
error
~
loc
(
"error with let%"
^
name
)))
with
|
Not_found
->
raise
(
Location
.
Error
(
Location
.
error
~
loc
(
"no let%"
^
name
)))
Location
.
error
~
loc
(
"no let%"
^
name
)))
end
(* Delegate to the default mapper. *)
|
x
->
default_mapper
.
expr
mapper
x
;
(* Delegate to the default mapper. *)
|
x
->
default_mapper
.
expr
mapper
x
;
}
let
()
=
register
"my_monads"
(
generate_mapper
monad_mapping
)
This diff is collapsed.
Click to expand it.
generator/tests/jsref/JsInterpreter.ml
+
248
−
245
View file @
aa4ce4b3
This diff is collapsed.
Click to expand it.
generator/tests/jsref/JsInterpreterMonads.ml
+
1
−
0
View file @
aa4ce4b3
...
...
@@ -362,3 +362,4 @@ let ifx_prim w k = if_prim w k
let
ifx_number
w
k
=
if_number
w
k
let
ifx_string
w
k
=
if_string
w
k
let
ifx_success_state
a
b
c
=
if_success_state
a
b
c
let
ifx_some_or_default
v
d
f
=
if_some_or_default
v
d
f
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment