Trivia represents white space and comments.
There 2 kinds of white space:
There are 3 kinds of comments:
//
./*
and */
containing a line terminator./*
and */
without a line terminator.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
}
The MultilineTrivia
represents trivia containing a LineTerminator.
Syntax
MultiLineTrivia :
{
LineTerminator
| TrailingComment
| MultilineComment
}
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 separators represents uniline white space.
TODO: Include all legal space separators.
Code Point | Name |
---|---|
U+0009 | CHARACTER TABULATION |
U+0020 | SPACE |
Syntax
LineTerminator :
{
U+0009
| U+0020
}
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 Point | Name |
---|---|
U+000A | LINE FEED |
Syntax
LineTerminator :
{
U+000A
| END_OF_FILE
}
Trailing comments represent comments after //
.
Syntax
TrailingComment :
//
trailingCommentChar* LineTerminatortrailingCommentChar :
any Unicode code point but not LineTerminator
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 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 LineTerminatorInlineCommentCharsNoAsteriskNoSlash :
any Unicode code point but not one of*
,/
or LineTerminator