[Idea] [Pitch] Distinguishing code comments from text comments


(Doug McKenna) #1

Dmitri Gribenko responded:

Suppose an analysis program that takes source code as mere text input

That is the root of the issue. You shouldn't be parsing source code
with ad-hoc tools. You need to use a real compiler.

One may want to use a real compiler, but one doesn't need an entire compiler to parse otherwise ignored source code just looking for comments.

Just because it
happened to work with, say C, does not mean that you got it right. I
doubt that a program that you described was correctly handling, say,
line continuations in comments.

You would be incorrect in my case (I handle even the weirdest situations like backslash line continuation in the middle of a delimiter), but point taken for simple-minded tools. The fact that C or other source code can have some weird legal constructions (and I'm assuming Swift has fewer such possible weird constructions) doesn't mean the user is required to employ those very rare constructions.

The point is to make the job easier, at almost no cost, for simple tools. And if the compiler doesn't recognize text comments as distinguishable from code comments, then relying on a complete compiler to do the source parsing isn't going to help any, especially since it presumably just tosses the text in the comment.

The bottom line is, you need to use a real compiler frontend to parse
source code.

It's not about parsing the meat of the source code. It's about robustly and easily recognizing a delimiter that signals the basic purpose of an otherwise-ignored comment. It's about wanting unambiguously to know which part of a source file is text comment for humans and which part is excised code being kept around for later uses. The alternative is doing some kind of non-robust statistical test on the text to make the call as to what its purpose is (which is also language-specific).

All I'm advocating is that with a tiny little bit of *standardized* help that harms no one and is upwardly compatible, the world could be a better place for everyone, not just me with my private /*{ ... }*/ solution.

Doug McKenna
Mathemaesthetics, Inc.