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

Keywords with double colons can't be parsed #301

Closed
dhleong opened this issue Jun 28, 2019 · 6 comments
Closed

Keywords with double colons can't be parsed #301

dhleong opened this issue Jun 28, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@dhleong
Copy link

dhleong commented Jun 28, 2019

version

v2019.06.16-alpha

platform

macOS 10.14.5

problem

I'm using a garden-based CSS solution in clojurescript, and it's supported keywords like :&::before without problem (the & refers to the parent "node") but kondo barfs on it, saying it can't parse the file due to things like that being an invalid keyword.

repro

I think having any such keyword in a file would produce this

expected behavior

At least not barf on the keyword; possibly use an info to inform, if you like, but the reader happily accepts it and uses it.

actual behavior

Error:

/var/folders/9q/s674cplx7qv122xbwcchw3jm0000gn/T/vULpnvX/530/style.cljs:0:0: error: can't parse /var/folders/9q/s674cplx7qv122xbwcchw3jm0000gn/T/vULpnvX/530/style.cljs, [line 46, col 15] Invalid keyword: &::before.         

(from ALE)

@borkdude
Copy link
Member

borkdude commented Jun 28, 2019

@dhleong Thank you. To be sure, can you paste a full self-consistent example? Your example :&::before doesn't work in Clojure proper when I paste it in a REPL, but :&:foo does and clj-kondo doesn't barf on the latter one:

$ clj
Clojure 1.10.0
(ns before)

(ns foo (:require [before]))

:&::before
Syntax error reading source at (REPL:6:0).
Invalid token: :&::before
foo=>

@dhleong
Copy link
Author

dhleong commented Jun 28, 2019

Interesting. It does work fine in a cljs repl via lein figwheel, for example:

dev:cljs.user=> :&::before
:&::before
dev:cljs.user=> :&::::not-really-a-thing
:&::::not-really-a-thing

It's not a namespace, since there's that & at the beginning. Clojure seems to happily accept it if fed into (keyword), it just doesn't like it at the reader:

$ clj
Clojure 1.10.0
user=> :&::before
Syntax error reading source at (REPL:2:0).
Invalid token: :&::before
user=> (keyword "&::before")
:&::before

I suppose if you're just using the clojure reader to parse the file contents into list or something, then there may not be much that can reasonably be done here besides formatting the error....

@borkdude
Copy link
Member

I'll check if there's something in rewrite-clj that I can tweak. If this is in tools.reader, I'm not sure if it's easily fixable.

@borkdude
Copy link
Member

borkdude commented Jun 28, 2019

@borkdude
Copy link
Member

borkdude commented Jun 28, 2019

@dhleong I modified the keyword reading a bit, so it should work now. Can you test if this work for you? E.g. with clj:

clj -Sdeps '{:deps {clj-kondo {:git/url "https://github.com/borkdude/clj-kondo" :sha "87d2d9b4d002d909de9d1006afecfa74e9aff85f"}}}' -A:clj-kondo --lint src

A new Mac binary can be downloaded here:
https://4156-176829714-gh.circle-artifacts.com/0/release/clj-kondo-2019.06.24-alpha-SNAPSHOT-macos-amd64.zip

@borkdude borkdude added this to the next-release milestone Jun 28, 2019
@borkdude borkdude changed the title Can't parse keywords starting with & Keywords with double colons in the middle can't be parsed Jun 28, 2019
@borkdude borkdude changed the title Keywords with double colons in the middle can't be parsed Keywords with double colons can't be parsed Jun 28, 2019
@borkdude borkdude added the enhancement New feature or request label Jun 28, 2019
@dhleong
Copy link
Author

dhleong commented Jun 29, 2019

That worked, thanks! I was able to run without error against the e6f6bf0 commit:

 clj -Sdeps '{:deps {clj-kondo {:git/url "https://github.com/borkdude/clj-kondo" :sha "e6f6bf097072c0ad0f6f5ffec13379d9c79db4e2"}}}' -m clj-kondo.main --lint src  

Thanks so much for your help!

lread added a commit to lread/rewrite-cljc-playground that referenced this issue Oct 21, 2019
A while ago @borkdude mentioned clj-kondo/clj-kondo#301

Thought I'd add some small tests to see how rewrite-cljc behaves - seems to
handle the garden-style syntax just fine.
lread added a commit to lread/rewrite-cljc-playground that referenced this issue Oct 22, 2019
Turns out I was accidentally using clojure.tools.reader instead of
clojure.tools.read.edn. I made a decision to use clojure.tools.reader.edn
because it is safe in that it does not execute code.

When I corrected my reader, garden-style keywords parsing failed. After adopting
borkdude's fix for clj-kondo/clj-kondo#301, we are
good again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants