Skip to content
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

Add support for namespaced maps #17

Merged
merged 3 commits into from Sep 29, 2023
Merged

Add support for namespaced maps #17

merged 3 commits into from Sep 29, 2023

Conversation

iarenaza
Copy link
Contributor

@iarenaza iarenaza commented Sep 8, 2023

parseclj already added support for namespaced maps in 2018 (in commit b40670a56147214f0486763529897cb688a09692).

As Alex Miller said in edn-format/edn#78

Clojure introduced namespace map syntax in Clojure 1.9. The Clojure
edn reader was also updated to support the non-autoresolved parts of
namespace map syntax

The edn spec should be updated to a new version that includes the
namespace map syntax such as #:foo{:bar 1} (syntax alternative for
{:foo/bar 1}).

So it's pretty clear that the intention is for edn spec to support namespaced maps (the reference implementation in Clojure already does!).

In addition to the use case mentioned in issue #16, not supporting this seems to cause trouble in CIDER when integrating with shadow-cljs (clojure-emacs/cider#3437

Fixes: #16

Copy link
Member

@vemv vemv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice to see this! Kudos.

I cannot meaningfully review the implementation, however I spotted some opportunity in the tests.

test/parseedn-test-data.el Show resolved Hide resolved
test/parseedn-test-data.el Outdated Show resolved Hide resolved
parseclj already added support for namespaced maps in 2018 (in commit
b40670a56147214f0486763529897cb688a09692).

As Alex Miller said in edn-format/edn#78

> Clojure introduced namespace map syntax in Clojure 1.9. The Clojure
> edn reader was also updated to support the non-autoresolved parts of
> namespace map syntax (edn doesn't do anything autoresolved like
> ::foo or #::foo{}).
>
> The edn spec should be updated to a new version that includes the
> namespace map syntax such as #:foo{:bar 1} (syntax alternative for
> {:foo/bar 1}).

So it's pretty clear that the intention is for edn spec to support
namespaced maps (the reference implementation in Clojure already
does!).

In addition to the use case mentioned in issue clojure-emacs#16, not supporting
this seems to cause trouble in CIDER when integrating with
shadow-cljs (clojure-emacs/cider#3437)

Fixes: clojure-emacs#16
parseedn-read never sees the full value of the `:ast` keys as defined
in `parseedn-test-data.el`. In fact, it doesn't know about it at
all. The only functions that see anything related to the `:ast` values
are `parseedn-reduce-leaf` and `parseedn-reduce-branch`. But they are
called back from `parseclj` when needed, to "reduce" (transform the
current AST node definition into the associated Emacs Lisp data type).

As commented in clojure-emacs#17 (comment),
they very likely are remnants of when parseedn and parseclj were the
same library.
@vemv vemv requested a review from plexus September 12, 2023 08:05
Copy link
Member

@vemv vemv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intent to merge this soon - was simply leaving some headroom in case someone else also wanted to review.

One last suggestion.

parseedn.el Outdated
@@ -113,10 +113,24 @@ on available options."
((eq :lbracket token-type) (apply #'vector children))
((eq :set token-type) (list 'edn-set children))
((eq :lbrace token-type) (let* ((kvs (seq-partition children 2))
(hash-map (make-hash-table :test 'equal :size (length kvs))))
(hash-map (make-hash-table :test 'equal :size (length kvs)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing the 'before' and 'after' of defun parseedn-reduce-branch, I sense that now it mixes levels of abstraction.

Before it looked more concise and higher-level.

The simplest fix would be to extract most of the logic to a separate defun. Although possibly this might mean something else (e.g. this could be fixed in parseclj?) - analysis much welcome.

Before adding the code to support prefixed maps, the branch reduction
function looked more concise and higher-level. After adding the support
it seemed like it mixed levels of abstraction.

Extracting the nitty-gritty details of how to build the maps
(especially in the prefixed map case) should help in keeping the
levels of abstraction separated.
@vemv vemv merged commit 803c26f into clojure-emacs:main Sep 29, 2023
vemv pushed a commit that referenced this pull request Sep 29, 2023
parseedn-read never sees the full value of the `:ast` keys as defined
in `parseedn-test-data.el`. In fact, it doesn't know about it at
all. The only functions that see anything related to the `:ast` values
are `parseedn-reduce-leaf` and `parseedn-reduce-branch`. But they are
called back from `parseclj` when needed, to "reduce" (transform the
current AST node definition into the associated Emacs Lisp data type).

As commented in #17 (comment),
they very likely are remnants of when parseedn and parseclj were the
same library.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't read namespace maps
2 participants