Whitespace and comment tokens
Table of contents
Whitespace
Grammar
Whitespace = { PATTERN_WHITE_SPACE + }
See Special terminals for the definition of
PATTERN_WHITE_SPACE.
Attributes
(none)
Rejection
No matches are rejected.
Line comment
Grammar
Line_comment = { "//" ~ LINE_COMMENT_CONTENT }
LINE_COMMENT_CONTENT = { ( !"\n" ~ ANY )* }
Attributes
The token's style and body are determined from LINE_COMMENT_CONTENT as follows:
-
if LINE_COMMENT_CONTENT begins with //:
- style is non-doc
- body is empty
-
otherwise, if LINE_COMMENT_CONTENT begins with /,
- style is outer doc
- body is the characters from LINE_COMMENT_CONTENT after that /
-
otherwise, if LINE_COMMENT_CONTENT begins with !,
- style is inner doc
- body is the characters from LINE_COMMENT_CONTENT after that !
-
otherwise
- style is non-doc
- body is empty
Note: The body of a non-doc comment is ignored by the rest of the compilation process
Rejection
The match is rejected if the token's body would include a CR character.
Block comment
Grammar
Block_comment = { BLOCK_COMMENT }
BLOCK_COMMENT = { "/*" ~ BLOCK_COMMENT_CONTENT ~ "*/" }
BLOCK_COMMENT_CONTENT = { ( BLOCK_COMMENT | !"*/" ~ !"/*" ~ ANY ) * }
Note: See Nested block comments for discussion of the
!"/*"subexpression.
Attributes
The comment content is the sequence of characters consumed by the first (and so the outermost) instance of BLOCK_COMMENT_CONTENT which participated in the match.
The token's style and body are determined from the block comment content as follows:
-
if the comment content begins with
**:- style is non-doc
- body is empty
-
otherwise, if the comment content begins with
*and contains at least one further character,- style is outer doc
- body is the characters from the comment content after that
*
-
otherwise, if the comment content begins with
!,- style is inner doc
- body is the characters from the comment content after that
!
-
otherwise
- style is non-doc
- body is empty
Note: It follows that
/**/and/***/are not doc-comments
Note: The body of a non-doc comment is ignored by the rest of the compilation process
Rejection
The match is rejected if the token's body would include a CR character.
Unterminated block comment
Grammar
Unterminated_block_comment = { "/*" }
Rejection
All matches are rejected.
Note: This definition makes sure that an unterminated block comment isn't accepted as punctuation (* followed by /).