Giter Club home page Giter Club logo

Comments (9)

borkdude avatar borkdude commented on June 4, 2024 1

Well, project.clj isn't technically EDN.

from babashka.

borkdude avatar borkdude commented on June 4, 2024 1

@skat-kurt I recommend using something like edamame for this, which is built into babashka as well. You can tweak whatever you want to allow in your .ednish or .cljish file. E.g. if you want to have EDN + regexes but never a location, you can do this:

(require '[edamame.core :as e])
(e/parse-string "..." {:regex true :location? (constantly false)})

from babashka.

borkdude avatar borkdude commented on June 4, 2024

@skat-kurt It's not recommended to use read-string for reading EDN files. This is what we have clojure.edn/read-string for. read-string is for reading code.

from babashka.

skat-kurt avatar skat-kurt commented on June 4, 2024

Thanks, using clojure.edn/read-string works perfectly (and I should have known...)

from babashka.

borkdude avatar borkdude commented on June 4, 2024

Nonetheless, I'll try to align bb's behavior to clj's.

from babashka.

skat-kurt avatar skat-kurt commented on June 4, 2024

I'll have to stick with my original work-around for now. The original file I want to read contains a regex, which edn/readstring doesn't like

(edn/read-string "#\"test\"")

Results in the

java.lang.RuntimeException: No dispatch macro for: "

exception, mentioned in another issue as well. That behavior is identical with standard clojure though.

from babashka.

borkdude avatar borkdude commented on June 4, 2024

regexes aren't part of EDN, so if your file ends with .edn I would say this is just invalid syntax

from babashka.

skat-kurt avatar skat-kurt commented on June 4, 2024

You are right. A pity that the clojure.edn namespace isn't symetric. I mean, there is no clojure.edn/write-string function that could throw when serializing data to edn that cannot be expressed in it. I use pr-str instead, which happily writes regex etc.

Some background. The "edn" files form the basis to auto-generate leiningen compatible project.clj files and some of them need :userjar-merge-with in combination with regex, as seen in the example project.clj file https://gitlab.com/technomancy/leiningen/blob/master/sample.project.clj#L436. I'll find another way to express this in the source edn files, so that they become valid edn files and take it from there.

from babashka.

skat-kurt avatar skat-kurt commented on June 4, 2024

I think I'll go with introducing a reader tag for regex, so that the edn files at least become valid, while edn/read-string returns regex data. Something like the following.

(edn/read-string
            {:readers {'regex re-pattern}}
            "#regex \"the-pattern\"")

from babashka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.