atom / language-clojure

Clojure package for Atom
Other
49 stars 48 forks source link

Ignore form reader macro should "comment" the following form #72

Open mattly opened 7 years ago

mattly commented 7 years ago

Description

From the Clojure reader reference

The form following #_ is completely skipped by the reader. (This is a more complete removal than the comment macro which yields nil)

grammar guides for other editors will highlight the affected forms as comments.

Steps to Reproduce

  1. put the characters #_ in front of any form, with any amount of whitespace preceding it

Expected behavior: The following form should be interpreted as a comment

Actual behavior: The following form is not interpreted as a comment

Reproduces how often: always

Versions

This has happened on every version of Atom I've used, including 1.19.0

peter-lyons-kehl commented 5 years ago

Additionally, could you make such comments collapsible, please. I know that for other languages, Atom doesn't make all inline comments collapsible; but for some of them it does. For example, following comment is collapsible in PHP:

  /* any multiline
     comment with code right after*/ $v= 1;
eskemojoe007 commented 5 years ago

I took a quick look into this, but I am far from an expert on the subject of atom languages. But atom uses Tree-sitter to parse the content of the file. It parses line by line and not with multi-line support (this is an underlying assumption that is important to my argument). It relies on regex to match the opening and closing of multi-line comments (and other parameters). Other block commented languages often have a unique opening and closing statement such as /* and */ make it easier to find the closing statement. The reader macro is only closed by a paren.

Consider the following simple function:

(defn func1
  [args]
  (clojure.string/join " " (map func2 args)))

We could implement the reader macro (#_()) in a number of different places which would need to select different closing parens. I'll indicate where the comment should stop with the | character.

#_(defn func1
    [args]
    (clojure.string/join " " (map func2 args)))|

(defn func1
  [args]
  #_(clojure.string/join " " (map func2 args))|)

(defn func1
  [args]
  (clojure.string/join " " #_(map func2 args)|))

There are regex ways (using recursion) to find the opening and closing matching parens, but given that tree-sitter doesn't have knowledge of the previous lines this becomes challening to identify the right closing paren using just the built in regex tree-sitter formatting.

Needless, I've given up modifying the simple grammar/clojure.cson

Aerijo commented 5 years ago

@eskemojoe007 mostly right; but Tree-sitter does work across multiple lines.

The grammar you were looking at was a TextMate grammar. Clojure does not have a Tree sitter grammar in Atom yet though, so your argument doesn’t change.