Skip to main content

Tokenizer

Struct Tokenizer 

Source
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: bool

the 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

Source

pub fn new(parse_info: ParseInfo) -> Self

Source

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

Source

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

Source

pub fn is_streaming(&self) -> bool

true while the input is a stream that is not read to its end

Source

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)

Source

pub fn from_input(input: &CssInput) -> Self

tokenizer of a css input with a new anonymous source

Source

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

Source

pub fn source_id(&self) -> u32

id of the source file being tokenized

Source

pub fn stream_length(&self) -> usize

length of the css input, in code units

Source

pub fn source(&self) -> Rc<SourceFile>

the source file

Source

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

Source

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

Source

pub fn value_string(&mut self) -> String

the string value of the current token (decoded)

Source

pub fn content(&self) -> Rc<str>

content of the source being tokenized

Source

pub fn codes(&self) -> &CodeUnits

code units of the source being tokenized

Source

pub fn done(&self) -> bool

Source

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.