[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pattern matching lines starting with double comment characters

From: Koichi Murase
Subject: Re: Pattern matching lines starting with double comment characters
Date: Sun, 26 Feb 2023 20:57:18 +0900

2023年2月26日(日) 17:02 Tapani Tarvainen <>:
> > The only portable way is to specify each just the same as you do for //:
> >
> > pn_ere = "^[[:space:]]*(##|;;|!!|@c|//)[[:space:]]+"
> Yes. Assuming the intent is to allow exactly two of the comment
> characters. Which the OP apparently wanted, but at least offhand
> I can't think of any language that requires blank space after
> the comment marker and it is actually rather common to use
> more of them at times.

To me, the OP's question is clear enough about the double comment
characters, and it does not feel so strange.  Rather, generalizing it
to an arbitrary number of comment characters seems strange.  I naively
wonder what would be the use case for detecting an arbitrary number of
comment characters.

It is typical to use duplicate comment characters to include code
documents, code annotation, or other types of meta information in the
source code. Doxygen and other code documentation frameworks for C/C++
use /// and /** */ as well as //!, etc.  PostScript uses %% for meta
information.  I'm not so familiar with Emacs Lisp, but GNU Emacs
appears to distinguish ;; and ; in editing Emacs Lisp though they are
treated equivalently by the language itself.  Some people seem to
distinguish %% and % in TeX.  Javadoc also uses /** */.  Python uses
""" ... """ (though it is lexically a variant of the duplicate string

In particular, when one wants to manipulate the comments by a program,
the target is likely a kind of meta information rather than the
general random user comments.  In such a case, the target type of the
comments needs to be differentiated by a certain form of comments
which is restricted from the general comment syntax allowed by the
language.  If one wants to introduce one's own comment form for one's
own meta information, I think <double comment character plus at least
one whitespace character> is one of the reasonable options.

In this perspective, there doesn't seem to be use cases to invent two
or more different comment formats for one purpose.  I have never seen
a language where people introduce an arbitrary number of different
meta-languages with the count of duplicate comment characters.  It is
interesting to observe how people from different backgrounds alter the
original question, which seems to clearly state the "double comment
character", to more general cases that apparently do not seem to be
associated with real use cases.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]