rewrite-clj icon indicating copy to clipboard operation
rewrite-clj copied to clipboard

The use of the term "whitespace" can be confusing

Open lread opened this issue 4 years ago • 6 comments

The zip API has fns:

  • whitespace? - returns true if Clojure whitespace
  • whitespace-or-comment? - returns true if Clojure whitespace or comment

All good. But... the zip API also has:

  • skip-whitespace - which skips Clojure whitespace AND comments.
  • skip-whitespace-left - ditto

While reading code that uses the above functions from the zip API, I get confused.

Perhaps we can clean things up a bit (without breaking the existing API) when we get to #70. If we can't do that we'll stress the oddity in docs.

lread avatar Mar 23 '21 17:03 lread

Maybe copying those functions to a new name while deprecating the old ones works.

borkdude avatar Mar 23 '21 17:03 borkdude

Yeah, thanks, I think they will get deprecated, I'll wait and see what new fns #70 introduce here.

Interesting also that we have (skip-whitespace f zloc). Having zloc as the first arg is more the norm in zip API, and more thread-first macro friendly.

lread avatar Mar 23 '21 18:03 lread

I agree that this is confusing. Am I correct that checking for :tag is a safe way to get the exact node type? For example, I want to distinguish spaces and newlines but there doesn't seem to be a function that is checking for that, such as spaces? or newline?.

mrkam2 avatar Mar 17 '24 15:03 mrkam2

Yes, I don't think we documented :tag as part of the public API, but you can safely use it.

Here's maybe some useful inspiration from cljfmt: https://github.com/weavejester/cljfmt/blob/f3ba8d4d26d3894acdc4875f8b24477c306a3f4b/cljfmt/src/cljfmt/core.cljc#L77-L87

lread avatar Mar 17 '24 15:03 lread

Yes, I don't think we documented :tag as part of the public API, but you can safely use it.

Here's maybe some useful inspiration from cljfmt: https://github.com/weavejester/cljfmt/blob/f3ba8d4d26d3894acdc4875f8b24477c306a3f4b/cljfmt/src/cljfmt/core.cljc#L77-L87

Interesting that they consider comment to be a line break.

mrkam2 avatar Mar 17 '24 16:03 mrkam2

Interesting that they consider comment to be a line break.

For their purposes, it might make sense: a comment always ends with a line break.

lread avatar Mar 17 '24 16:03 lread