-
Notifications
You must be signed in to change notification settings - Fork 273
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
ocaml-decoders conversion experiment #1280
Changes from 1 commit
45c15a1
1f9a186
235073d
aa78b63
d37baa9
45e303b
49a00aa
da81252
853aecf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,118 +51,39 @@ module Decode = { | |
let engine = field("vscode", string); | ||
|
||
let manifest = | ||
field("name", string) | ||
>>= ( | ||
name => | ||
field("version", string) | ||
>>= ( | ||
version => | ||
one_of([ | ||
("author", field("author", author)), | ||
("publisher", field("publisher", string)), | ||
("default", succeed("Unknown Author")), | ||
]) | ||
>>= ( | ||
author => | ||
field_opt("displayName", LocalizedToken.decode) | ||
>>= ( | ||
displayName => | ||
field_opt("description", string) | ||
>>= ( | ||
description => | ||
field_opt("main", string) | ||
>>= ( | ||
main => | ||
field_opt("icon", string) | ||
>>= ( | ||
icon => | ||
field_opt("categories", list(string)) | ||
|> default([]) | ||
>>= ( | ||
categories => | ||
field_opt("keywords", list(string)) | ||
|> default([]) | ||
>>= ( | ||
keywords => | ||
field("engines", engine) | ||
>>= ( | ||
engines => | ||
field_opt( | ||
"activationEvents", | ||
list(string), | ||
) | ||
|> default([]) | ||
>>= ( | ||
activationEvents => | ||
field_opt( | ||
"extensionDependencies", | ||
list(string), | ||
) | ||
|> default([]) | ||
>>= ( | ||
extensionDependencies => | ||
field_opt( | ||
"extensionPack", | ||
list(string), | ||
) | ||
|> default([]) | ||
>>= ( | ||
extensionPack => | ||
field_opt( | ||
"extensionKind", | ||
kind, | ||
) | ||
|> default(Ui) | ||
>>= ( | ||
extensionKind => | ||
field( | ||
"contributes", | ||
ExtensionContributions.decode, | ||
) | ||
>>= ( | ||
contributes => | ||
field_opt( | ||
"enableProposedApi", | ||
bool, | ||
) | ||
|> default( | ||
false, | ||
) | ||
>>= ( | ||
enableProposedApi => | ||
succeed({ | ||
name, | ||
version, | ||
author, | ||
displayName, | ||
description, | ||
main, | ||
icon, | ||
categories, | ||
keywords, | ||
engines, | ||
activationEvents, | ||
extensionDependencies, | ||
extensionPack, | ||
extensionKind, | ||
contributes, | ||
enableProposedApi, | ||
}) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
Json.Decode.( | ||
obj(({field, whatever, _}) => | ||
{ | ||
name: field.required("name", string), | ||
version: field.required("version", string), | ||
author: | ||
whatever( | ||
one_of([ | ||
("author", field.monadic("author", author)), | ||
("publisher", field.monadic("publisher", string)), | ||
("default", succeed("Unknown Author")), | ||
]), | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one of the shortcomings of the |
||
displayName: field.optional("displayName", LocalizedToken.decode), | ||
description: field.optional("description", string), | ||
main: field.optional("main", string), | ||
icon: field.optional("icon", string), | ||
categories: field.withDefault("categories", [], list(string)), | ||
keywords: field.withDefault("keywords", [], list(string)), | ||
engines: field.required("engines", engine), | ||
activationEvents: | ||
field.withDefault("activationEvents", [], list(string)), | ||
extensionDependencies: | ||
field.withDefault("extensionDependencies", [], list(string)), | ||
extensionPack: | ||
field.withDefault("extensionPack", [], list(string)), | ||
extensionKind: field.withDefault("extensionKind", Ui, kind), | ||
contributes: | ||
field.required("contributes", ExtensionContributions.decode), | ||
enableProposedApi: | ||
field.withDefault("enableProposedApi", false, bool), | ||
} | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise I think this looks significantly better than the alternatives. |
||
); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example of a small decoder using
obj