pub struct Tokenizer {Show 14 fields
pub typ: Option<u8>,
pub kin: Option<u8>,
pub num: f64,
pub field: TokenValueField,
pub value_kind: TokenValueKind,
pub value_start: usize,
pub value_end: usize,
pub src_id: Option<u32>,
pub sta: Option<usize>,
pub end: Option<usize>,
pub bytes_in: Option<usize>,
pub slice: Option<usize>,
pub parse_info: ParseInfo,
pub waiting: bool,
/* private fields */
}Expand description
tokenizer
Fields§
§typ: Option<u8>§kin: Option<u8>§num: f64§field: TokenValueField§value_kind: TokenValueKind§value_start: usize§value_end: usize§src_id: Option<u32>§sta: Option<usize>§end: Option<usize>§bytes_in: Option<usize>§slice: Option<usize>§parse_info: ParseInfo§waiting: boolthe last call of Tokenizer::next reached the end of the code units read from the stream: the token may
continue in the next chunk. no token is returned, a chunk must be appended before next() is called again
Implementations§
Source§impl Tokenizer
impl Tokenizer
pub fn new(parse_info: ParseInfo) -> Self
Sourcepub fn streaming(parse_info: ParseInfo, size: usize) -> Self
pub fn streaming(parse_info: ParseInfo, size: usize) -> Self
tokenizer of a stream: the chunks are appended with Tokenizer::append when the tokenizer is waiting.
size: the size of the css in bytes when it is known, 0 otherwise. the code units are allocated once: the size
in bytes is not less than the number of utf-16 code units
Sourcepub fn expected_length(&self) -> usize
pub fn expected_length(&self) -> usize
the size of the css of a stream, in bytes, when it is known. 0: not known, or not a stream
Sourcepub fn is_streaming(&self) -> bool
pub fn is_streaming(&self) -> bool
true while the input is a stream that is not read to its end
Sourcepub fn append(&mut self, chunk: Option<StreamChunk>)
pub fn append(&mut self, chunk: Option<StreamChunk>)
append a chunk of the stream: utf-8 bytes or text. None ends the stream. the code units stay bytes while the
css is ascii, they are utf-16 code units otherwise. the buffer of the code units doubles when it is full: the
code units read so far are not copied for each chunk. the buffer is written in place when the tokenizer holds
the only reference to it: the caller drops its other references first (the source text of the arena)
Sourcepub fn from_input(input: &CssInput) -> Self
pub fn from_input(input: &CssInput) -> Self
tokenizer of a css input with a new anonymous source
Sourcepub fn load(parse_info: &mut ParseInfo, input: Option<&CssInput>)
pub fn load(parse_info: &mut ParseInfo, input: Option<&CssInput>)
set the css read by the tokenizer. the text of the css is the content of the source file
Sourcepub fn stream_length(&self) -> usize
pub fn stream_length(&self) -> usize
length of the css input, in code units
Sourcepub fn source(&self) -> Rc<SourceFile>
pub fn source(&self) -> Rc<SourceFile>
the source file
Sourcepub fn make_token(
&mut self,
hint: Option<u8>,
slice: Option<usize>,
decode_segments: bool,
) -> &mut Self
pub fn make_token( &mut self, hint: Option<u8>, slice: Option<usize>, decode_segments: bool, ) -> &mut Self
set the current token: its type, its numeric value and the range of its string value. no string is created
Sourcepub fn intern_value(&mut self, arena: &AstArena, source_index: i32) -> u32
pub fn intern_value(&mut self, arena: &AstArena, source_index: i32) -> u32
id of the string value of the current token in the arena. no string is created
Sourcepub fn value_string(&mut self) -> String
pub fn value_string(&mut self) -> String
the string value of the current token (decoded)
pub fn done(&self) -> bool
Sourcepub fn next(&mut self) -> &mut Self
pub fn next(&mut self) -> &mut Self
read the next token
read the next token. when the input is a stream that is not read to its end, a token that ends near the end of
the code units read so far may continue in the next chunk (an identifier, a number, a string, a comment, …):
the token is not returned, Tokenizer::waiting is true and a chunk must be appended before the next call