pub enum CommentStyle {
Block = 0,
BlockStar = 1,
BlockBang = 2,
BlockPound = 3,
BlockHeading = 4,
Single = 5,
SingleStar = 6,
SingleBang = 7,
}Expand description
An enum representing the “Style” the Kind::Comment token represents.
A Token with Kind::Comment will store this data internal to the token. Using Token::comment_style() will return this enum, depending on what characters make up the beginning of the comment token. By default the Lexer will only produce multi-line - aka “Block” - comments, but adding Feature::SeparateWhitespace will allow the Lexer to produce single line comments too.
A basic Block comment style uses the /* leading characters, but sub-styles of the block
style are also computed, for example BlockStar represents a comment using the “double
star” syntax to open the comment, i.e. /**. Determing if these comments are using these alternate style can help a
parser (or writer) determine if it should retain these comments or otherwise treat them differently to regular block
comments.
use css_lexer::*;
let mut lexer = Lexer::new(&EmptyAtomSet::ATOMS, "/* Normal Comment */ /** Double Star Comment */");
{
// This token will be collapsed Whitespace.
let token = lexer.advance();
assert_eq!(token, Kind::Comment);
assert_eq!(token, CommentStyle::Block);
}
assert_eq!(lexer.advance(), Kind::Whitespace);
{
// This token will be collapsed Whitespace.
let token = lexer.advance();
assert_eq!(token, Kind::Comment);
assert_eq!(token, CommentStyle::BlockStar);
}Variants§
Block = 0
A basic block comment which uses /* as the leading style. The third character may be a whitespace, or may
include a character that isn’t !, #, =, -.
BlockStar = 1
A block comment which uses /** as the leading style. The two *s must be adjacent, so this does not count
/* *.
BlockBang = 2
A block comment which uses /*! as the leading style. The * and ! must be adjacent, so this does not count
/* !.
BlockPound = 3
A block comment which uses /*# as the leading style. The * and # must be adjacent, so this does not count
/* #.
BlockHeading = 4
A block comment which uses /*= or /*- as the leading style. The * and - or = must be adjacent, so this
does not count /* #.
Single = 5
A basic single line comment which uses // as the leading style. The third character may be a whitespace, or
may include a character that isn’t *, !. The Lexer can only produce a Token
with this style if Feature::SingleLineComments is enabled.
SingleStar = 6
A single line comment which uses //* as the leading style. The * be adjacent to the //, so this does not
count // *. The Lexer can only produce a Token with this style if
Feature::SingleLineComments is enabled.
SingleBang = 7
A single line comment which uses //! as the leading style. The ! be adjacent to the //, so this does not
count // !. The Lexer can only produce a Token with this style if
Feature::SingleLineComments is enabled.
Implementations§
Trait Implementations§
Source§impl Clone for CommentStyle
impl Clone for CommentStyle
Source§fn clone(&self) -> CommentStyle
fn clone(&self) -> CommentStyle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more