-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom tag names via
type[@mel.tag "foo"] t = ..
(#1189)
* feat: custom tag names via `type[@mel.tag "foo"] t = ..` * test: add cram test * refactor: use inline record for J.Caml_block_tag * chore: add changelog entry
- Loading branch information
1 parent
b455221
commit f4612d0
Showing
16 changed files
with
204 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
Test `@@mel.tag` attribute for discriminated unions | ||
|
||
$ . ./setup.sh | ||
$ cat > x.ml <<EOF | ||
> type foo = { a : string; b : string } | ||
> type[@mel.tag "lol"] t = Foo of foo | Bar of { c : string; d : string } | ||
> let x, y = | ||
> let x = Foo { a = "a"; b = "b" } in | ||
> let y = Bar { c = "c"; d = "d" } in | ||
> (x, y) | ||
> let s = function Foo { a; b } -> (a, b) | Bar { c; d } -> (c, d) | ||
> EOF | ||
$ melc -ppx melppx x.ml | ||
// Generated by Melange | ||
'use strict'; | ||
function s(param) { | ||
if (param.lol !== /* Foo */0) { | ||
return [ | ||
param.c, | ||
param.d | ||
]; | ||
} | ||
const match = param._0; | ||
return [ | ||
match.a, | ||
match.b | ||
]; | ||
} | ||
const x = { | ||
lol: /* Foo */0, | ||
_0: { | ||
a: "a", | ||
b: "b" | ||
} | ||
}; | ||
const y = { | ||
lol: /* Bar */1, | ||
c: "c", | ||
d: "d" | ||
}; | ||
exports.x = x; | ||
exports.y = y; | ||
exports.s = s; | ||
/* No side effect */ | ||
`@mel.tag` + `[@mel.as "string"]` | ||
$ cat > x.ml <<EOF | ||
> type foo = { a : string; b : string } | ||
> type[@mel.tag "lol"] t = | ||
> | Foo of foo | ||
> | Bar of { c : string; d : string } [@mel.as "bar"] | ||
> let x, y = | ||
> let x = Foo { a = "a"; b = "b" } in | ||
> let y = Bar { c = "c"; d = "d" } in | ||
> (x, y) | ||
> let s = function Foo { a; b } -> (a, b) | Bar { c; d } -> (c, d) | ||
> EOF | ||
$ melc -ppx melppx x.ml | ||
// Generated by Melange | ||
'use strict'; | ||
function s(param) { | ||
if (param.lol !== /* Foo */0) { | ||
return [ | ||
param.c, | ||
param.d | ||
]; | ||
} | ||
const match = param._0; | ||
return [ | ||
match.a, | ||
match.b | ||
]; | ||
} | ||
const x = { | ||
lol: /* Foo */0, | ||
_0: { | ||
a: "a", | ||
b: "b" | ||
} | ||
}; | ||
const y = { | ||
lol: /* Bar */"bar", | ||
c: "c", | ||
d: "d" | ||
}; | ||
exports.x = x; | ||
exports.y = y; | ||
exports.s = s; | ||
/* No side effect */ |
Submodule melange-compiler-libs
updated
3 files
+1 −1 | lambda/lambda.ml | |
+1 −1 | lambda/lambda.mli | |
+10 −2 | typing/typedecl.ml |