Trivia

Trivia represents white space and comments.

There 2 kinds of white space:

There are 3 kinds of comments:

Trivia

In most cases, syntax rules are not sensible to the presence or not of LineTerminator in their white space and comments. The Trivia node represents trivia for these cases.

Syntax
Trivia :
   {
         MultilineTrivia
      | UnilineTrivia
   }

Multiline⁠Trivia

The MultilineTrivia represents trivia containing a LineTerminator.

Syntax
MultiLineTrivia :
   {
         LineTerminator
      | TrailingComment
      | MultilineComment
   }

Uniline⁠Trivia

The UnilineTrivia node represents trivia that can't contain a LineTerminator. This is used for some syntax rules such as the one for return statements.

Syntax
UnilineTrivia :
   {
         SpaceSeparator
      | InlineComment
   }

Space Separator

Space separators represents uniline white space.

TODO: Include all legal space separators.

Code PointName
U+0009CHARACTER TABULATION
U+0020SPACE

Syntax
LineTerminator :
   {
         U+0009
      | U+0020
   }

Line Terminator

A line terminator represents a newline sequence or the end of the file.

Trivia syntax node are classified based on if they contain a line terminator or not: as uniline trivia or multiline trivia.

TODO: Include all legal line terminators.

Code PointName
U+000ALINE FEED

Syntax
LineTerminator :
   {
         U+000A
      | END_OF_FILE
   }

Comments

Trailing⁠Comment

Trailing comments represent comments after //.

Syntax
TrailingComment :
   // trailingCommentChar* LineTerminator

trailingCommentChar :
   any Unicode code point but not LineTerminator

Multiline⁠Comment

Multiline comments represent comments between /* and */. They must contain at least one line terminator. They can't contain */. InlineComment corresponds to the version without line terminators.

Syntax
MultilineComment :
   /* MultilineCommentChars? LineTerminator MultilineCommentChars? */

MultilineCommentChars :
   {
         MultilineCommentCharNoAsterisk MultilineCommentChars?
      | * PostAsteriskMultilineCommentChars
   }

PostAsteriskMultilineCommentChars :
   {
         MultilineCommentCharNoAsteriskNoSlash MultilineCommentChars?
      | * PostAsteriskMultilineCommentChars
   }

MultilineCommentCharNoAsterisk :
   any Unicode code point but not *

MultilineCommentCharNoAsteriskNoSlash :
   any Unicode code point but not one of * or /

Inline⁠Comment

Inline comments represent comments between /* and */. They can't contain */ or a line terminator. MultilineComment corresponds to the version with line terminators.

Syntax
InlineComment :
   /* InlineCommentChars? */

InlineCommentChars :
   {
         InlineCommentCharNoAsterisk InlineCommentChars?
      | * PostAsteriskInlineCommentChars
   }

PostAsteriskInlineCommentChars :
   {
         InlineCommentCharsNoAsteriskNoSlash InlineCommentChars?
      | * PostAsteriskInlineCommentChars
   }

InlineCommentCharNoAsterisk :
   any Unicode code point but not * or LineTerminator

InlineCommentCharsNoAsteriskNoSlash :
   any Unicode code point but not one of *, / or LineTerminator