comments and whitespace
Text the language ignores. Both separate tokens and mean nothing beyond that, so either may go anywhere a token boundary may go, the file header included.
// A line comment ends with the line.
/* A block comment spans
as many lines as it needs. */
const max_range_m: int32 = 40000; // and may follow codeComments
- A line comment runs from
//to the end of the line. - A block comment runs from
/*to the first*/, across as many lines as that takes. - Block comments do not nest. An inner
/*is part of the comment, and the first*/ends it. ///is a line comment. Nothing reads it as documentation.- A comment may sit inside an expression, between any two tokens.
/* A comment may precede the header. */
module radar::sensors.tracking
const max_range_m: int32 = /* and may interrupt an expression */ 40000;Whitespace
There is no layout rule and no significant newline. A declaration may be written across as many lines as it needs, or on one.
- Any run of spaces, tabs, and newlines is one separator.
- A separator is needed only where running two tokens together would make a different token.
const xis two tokens;constxis one name.
const max_range_m:int32=40000;
const bearing_deg:
float32
= 41.5;Errors
A block comment that is never closed
/* the rest of the file is inside this comment // error: unterminated-block-comment
const max_range_m: int32 = 40000;A block comment closed by an inner one
The first */ ends the comment, so what the author meant as the end of it is code.
/* outer /* inner */ still meant to be a comment */ // error: unexpected
const max_range_m: int32 = 40000;Related
- identifiers — what the tokens a separator keeps apart may be named.
- module — the header a comment may precede.