Re: removing comment



Walter Roberson wrote On 09/26/07 10:07,:
In article <1190814438.015492.177410@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
vim <vgstech@xxxxxxxxx> wrote:

Use text processing languages
lex and yaac
Use regular expressions in that


You cannot reliably detect comments using regular expressions.


#define COMMENT /*
#define ENDCOMMENT */

This much defines COMMENT as an object-like
macro with an empty replacement list.

COMMENT

This expands COMMENT, producing nothing at all.

this is a comment

This is syntax error, and there's no point
in further analysis.

[...]
The points:
- comments can be triggered by macros

If "triggered by" means "generated by expansion of,"
this is false.

- comment formation is affected by preprocessor conditions that a
textual parser cannot know the answer to

False.

- inside string literals, comment-like sequences are just
regular characters

True. The same holds for character literals, too:

char c = '/* no comment starts here';
char d = '// nor here';

- determining whether you are inside a string literal requires
matching double-quotes, which is made non-trivial due to
backslashes

True.

Summary:
You cannot remove comments from source without something approaching
the power of the preprocessor, with complete knowledge of the
defines in effect.

False. The preprocessor has no knowledge of comments,
no influence on comments, and nothing to do with comments.
You need only a lexical analyzer; no knowledge or processing
of macros is required or desired.

--
Eric.Sosman@xxxxxxx
.



Relevant Pages

  • Re: Editor support for refactoring with macros?
    ... but indeed, since the forms are not regular expressions, this cannot ... Well actually, it should work ok on emacs lisp sources, but on Common ... there may be some problems relative to reader macros. ... transformer lambda expression directly from the defmacro form, ...
    (comp.lang.lisp)
  • Re: Editor support for refactoring with macros?
    ... Pascal Bourguignon wrote: ... but indeed, since the forms are not regular expressions, this cannot ... Well actually, it should work ok on emacs lisp sources, but on Common ... there may be some problems relative to reader macros. ...
    (comp.lang.lisp)
  • Re: for a laught (???)
    ... regular expressions in editors that support them, often with macros. ...
    (comp.lang.cobol)