Files
carbon-lang/docs/design/lexical_conventions/comments.md
T
Aswin Shailajan 33f26bd37b Added design of comments in design docs (#2641)
The [Comments #198](https://github.com/carbon-language/carbon-lang/pull/198) got accepted but the details were not updated in the design docs. Added `comments.md` file to add the details of the proposal and its discussion.

Closes #1994
2023-03-30 09:51:47 -07:00

1.7 KiB

Comments

Table of contents

Overview

A comment is a lexical element beginning with the characters // and running to the end of the line. We have no mechanism for physical line continuation, so a trailing \ does not extend a comment to subsequent lines.

Details

In the comments after the // a whitespace character is required to make the comment valid. Newline is a whitespace character, so a line containing only // is a valid comment. The end of the file also constitutes whitespace.

All comments are removed prior to formation of tokens.

Example:

// This is a comment and is ignored. \
This is not a comment.

var Int: x; // error, trailing comments not allowed

Currently no support for block comments is provided. Commenting out larger regions of human-readable text or code is accomplished by commenting out every line in the region.

Alternatives considered

References