Replies: 2 comments 2 replies
-
|
Glad to see you were able to figure out the C ffi, looks great! Yeah, API design is hard in general, but with no standard "idiomatic" reference for Koka it is even harder to figure out what the API should look like. I agree that since the primary purpose will likely be using it to serialize into a type it might be best to focus on that. In particular, it looks like it currently supports a streaming API, but I don't think that will be the most common usage pattern. (Streaming is very useful when you need it, but overkill when you don't). I know that the C library is oriented around that. For streaming based APIs that encapsulate resources I've liked using first-class named effects. https://github.com/koka-lang/koka/tree/dev/samples/handlers/named. (I used this pattern for an http parser here: https://github.com/TimWhiting/koka/blob/llhttp/lib/llhttp/llhttp.kk). |
Beta Was this translation helpful? Give feedback.
-
|
@TimWhiting I am not sure how to use named handler yet. So, I end up completed the basic parser and represents the yaml nodes that user can rely on to construct their struct. I end up using this: pub type yaml-value
Scalar(anchor: anchor, tag: tag, value: string, style: style, plain-implicit: bool, quoted-implicit: bool)
Alias(name: anchor-name)
Sequence(tag: tag, anchor: anchor, members: list<yaml-value>, implicit: bool)
Mapping(tag: tag, anchor: anchor, members: list<(yaml-value, yaml-value)>, implicit: bool)then I have a parser that will take If we have something like Next step, is probably convert yaml-value to json-value. I defined the json-value at the library too: /**
* yaml-json is subset of a Yaml document that is compatible with JSON. This
* type should be enough to convert to any json library that Koka will have
* in the future.
*/
pub type yaml-json
YamlNull
YamlBool(b: bool)
YamlDouble(double: float64)
YamlString(string: string)
YamlSequence(sequence: list<yaml-json>)
YamlMapping(mapping: list<(string, yaml-json)>)Probably need to keep anchor map we built, then resolve Alias to correct node. So far, I ended liking this language! I think we need more basic OS operations. sync functions is ok I think, since not all application need async. ie, spawn process with config like environment, current cwd etc is missing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I played with this project lately, and need a YAML parser functionality. So, I created one here: https://github.com/syaiful6/yaml.kk It also can be used as reference how to call FFI, especially C. I also learned a lot. But, to my surprise it far more easier than writing OCaml FFI. 👍
It still not completed, currently it will yield libyaml event for the given file. I am still tinkering how the API will look like. It will be nice, if we can serialize/deserialize it into our struct/data type.
Beta Was this translation helpful? Give feedback.
All reactions