Skip to content

Clojure reader fixes (6 bugs), fixed with tests in realgenekim/dryer fork #14

Open

Description

@realgenekim

Hi, Bob — kudos on all the great work here. I'm eager adopting this into my repos.

Funny, I created https://github.com/realgenekim/clj-surgeon, which required parsing Clojure, and ran into many of these same issues.

I'll have another PR coming in with some enhancements to compare methods inside defrecord, extend-protocol and the like, and to read syntax-quote gensyms (t0#). CRAP scores equal or higher than before. :)

Keep up the great work! (The rest written by Claude Code).

===

Six Clojure reader bugs on master, one commit each with a failing test, plus two follow-up commits that close gaps in items 4 and 6.

  1. #_#_ a b c reads as b c. Clojure reads c.
  2. #::alias{:a 1} reads as the symbol alias plus a map. Clojure reads one map.
  3. (f #^String x) is a read error. #^ is the old spelling of ^.
  4. #! hi mid-file takes ! as a tag that swallows the next form. Clojure reads #! as a line comment anywhere. A later commit ends that comment at \r as well as \n.
  5. (clojure.core/ns demo) is compared as a candidate. Only a bare ns head was left out.
  6. #'handle is a read error that drops the rest of the file. It now reads as (var handle). A later commit makes #' and #^ read past a discard: (#' #_x y) now reads ((var y)), as Clojure does.

Each new test fails on its commit's parent.

crapper src master this branch
tests 80 pass 88 pass
mean coverage 95.87% 96.69%
over CRAP 10 parse_args 16.0 parse_args 16.0

Every changed function has 100% coverage.

On a 126-file Clojure codebase, read warnings dropped from 15 to 4 and duplicate pairs rose from 65 to 76, because files that stopped at the first #' are now read in full.

Not included: Clojure rejects \a', and this reader accepts it. Known divergence, left as is: '#_ a b and @#_ a b read the quote or deref with no operand, where Clojure takes b. An existing test pins '#_x as (quote), so that's your call.

This is an offer, not a request. Take it, change it, or leave it.

Branch: realgenekim/dryer@master...clojure-reader-fixes (PRs here are limited to collaborators, so linking the branch instead.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions