This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-07-27
Channels
- # announcements (16)
- # architecture (19)
- # beginners (31)
- # calva (2)
- # cider (1)
- # clerk (4)
- # clj-yaml (58)
- # cljdoc (2)
- # cljs-dev (10)
- # clojure (77)
- # clojure-europe (108)
- # clojure-norway (26)
- # clojure-sanfrancisco (2)
- # conjure (1)
- # cursive (2)
- # datahike (5)
- # datomic (13)
- # emacs (7)
- # etaoin (3)
- # hyperfiddle (15)
- # introduce-yourself (3)
- # kaocha (1)
- # off-topic (21)
- # reagent (4)
- # releases (1)
- # shadow-cljs (41)
- # spacemacs (28)
- # specter (8)
- # squint (30)
- # yamlscript (2)
Greetings all!
I'm hoping to port https://metacpan.org/pod/YAMLScript to Clojure using clj-yaml.
Might need some help. 🙂
Welcome @ingy, I think most of us just bumble our way through with YAML. Nice to have the actual inventor of the data format right here with us!
Good to be here!
YAML is a complex beast, despite it mostly being seen as a better way to write JSON.
Feel free to ask me anything about it.
The tiny YAML core team hangs out here: https://matrix.to/#/#chat:yaml.io Andrey (SnakeYAML author) used to hang out there too.
I know enough of SnakeYAML to run it in our tested YAMLs against the suite and to integrate it into this: https://play.yaml.io/main/parser
Oh, and if you read through the history here, please forgive us @ingy for any snarky YAML remarks. I think we were just trying to cope with our confusion, but now that the delightful human being who invented YAML is here... well, some of it feels outright cringey! Sorry about that!
Also SnakeYAML is basically a port of PyYAML iirc. I maintain PyYAML so know that well. PyYAML has all the API things I need to make a YAMLScript reader, so I assume that SnakeYAML does too, and I hope that clj-yaml exposes the right things 🙂
I think I want to write a yamlscript.clj library with a load-file-ys
function that reads ys instead of clj.
Can you point me at other custom readers for clojure?
Hope so, but if not, we can figure it out. Or even create a new wrapper lib if that makes sense. Is the fact that SnakeYAML is only a YAML 1.1 parser problematic for you?
It will be fun to write the YS reader in YS!
Eventually I want to write a full YAML reference parser in YS.
If there were a pure clojure yaml parser I could do that now.
I like that in YS at about any level you can use pure Clojure syntax.
I certainly don't expect that Clojure people would prefer YS to Clojure. I don't even prefer that. But I see YS as having at least 2 important things to offer. 1. A way to do the anything programmatic with the full power of Clojure inside YAML, instead of 100 different hacks of trying to do this in 100 domains. 2. A gateway drug to Clojure for people who know enough YAML and say Python to be dangerous.
I think the impetus for clj-yaml has been a Clojure developer who needed some way to read some random YAML. We might need to get more sophisticated to support your use case, but that's cool!
Yeah that was my worry. That you would only expose a yaml-load-string
and yaml-load-file
you can just use raw snakeyml java interop if you need to get more stuff though, in a JVM. In babashka you can't, but usually in babashka people only parse basic yaml
I basically need access to the YAML parser events. The parser is one part of the load stack: read->scan->parse->compose->resolve->construct
yep, makes sense
But... as a YAML expert you might see some obvious general/useful things that clj-yaml is missing. Happy to learn about those if you stumble on them.
> Can you point me at other custom readers for clojure? I'm not sure exactly what you are asking but @borkdude's https://github.com/borkdude/edamame comes to mind.
If you are asking about parsing other things, https://github.com/engelberg/instaparse comes to mind.
@borkdude as long as you are here, I was trying to figure out how I could implement a load-file-ys
fn that called out to the perl YAMLScript::Reader with the source string and got edn back to eval into clojure. (does that make sense?)
But then yesterday I realized I should just port that Perl code to clojure and be done with it
ClojureScript and ClojureCLR (others?) use the JVM clojure compiler, right?
So then having this port would give YS support to ClojureScript at the same time...
hmmm. ok. Is all EDN eval-able as Clojure?
nvm. I guess I don't have anything I'm stuck on atm. Was just looking for assurance that I was heading in the paths of least resistance to get YS runnable on the JVM and JS.
Perhaps #sci could also be useful as part of YS on JVM / JS. It allows you to read values from strings and evaluate them in both of those hosts
@ingy Does YS work like this: parse YAML where the clojure code is a string and then you want to process + eval that string? if so, SCI would fit naturally there I think
In Lingy read-string
reads clojure code and returns a Lingy AST, like:
user=> (XXX (read-string "(prn 42)"))
--- !perl/array:Lingy::List
- !perl/scalar:Lingy::Symbol
=: prn
- !perl/scalar:Lingy::Number
=: '42'
...
Sorry wasn't finished
And YS (just a subclass of Lingy) has a read-string-ys
user=> read-string-ys: "prn: 42"
(prn 42)
that does the same thing with YS input instead of clojure.
right, so you read the ys syntax and get back out an s-expression (or string of an s-expression) which you then need to evaluate
Obviously for YS in Clojure I'm not going to produce that AST. I would likely produce EDN, and??? eval it?
I don't know the differences I guess
well, EDN is a data format, like JSON. It's basically Clojure is to EDN what JavaScript is to JSON
ok, so yes I would produce clojure forms