Struct cssparser::Parser [] [src]

pub struct Parser<'i: 't, 't> { /* fields omitted */ }

A CSS parser that borrows its &str input, yields Tokens, and keeps track of nested blocks and functions.

Methods

impl<'i: 't, 't> Parser<'i, 't>
[src]

Create a new parser

Check whether the input is exhausted. That is, if .next() would return a token.

This ignores whitespace and comments.

Check whether the input is exhausted. That is, if .next() would return a token. Return a Result so that the try! macro can be used: try!(input.expect_exhausted())

This ignores whitespace and comments.

Return the current internal state of the parser (including position within the input).

This state can later be restored with the Parser::reset method.

Restore the internal state of the parser (including position within the input) to what was previously saved by the Parser::position method.

Should only be used with SourcePosition values from the same Parser instance.

Start looking for var() functions. (See the .seen_var_functions() method.)

Return whether a var() function has been seen by the tokenizer since either look_for_var_functions was called, and stop looking.

Start looking for viewport percentage lengths. (See the seen_viewport_percentages method.)

Return whether a vh, vw, vmin, or vmax dimension has been seen by the tokenizer since look_for_viewport_percentages was called, and stop looking.

Execute the given closure, passing it the parser. If the result (returned unchanged) is Err, the internal state of the parser (including position within the input) is restored to what it was before the call.

Return a slice of the CSS input

Return a slice of the CSS input, from the given position to the current one.

Return the line and column number within the input for the current position.

Return the line and column number within the input for the given position.

Return the next token in the input that is neither whitespace or a comment, and advance the position accordingly.

After returning a Function, ParenthesisBlock, CurlyBracketBlock, or SquareBracketBlock token, the next call will skip until after the matching CloseParenthesis, CloseCurlyBracket, or CloseSquareBracket token.

See the Parser::parse_nested_block method to parse the content of functions or blocks.

This only returns a closing token when it is unmatched (and therefore an error).

Same as Parser::next, but does not skip whitespace tokens.

Same as Parser::next, but does not skip whitespace or comment tokens.

Note: This should only be used in contexts like a CSS pre-processor where comments are preserved. When parsing higher-level values, per the CSS Syntax specification, comments should always be ignored between tokens.

Have the given closure parse something, then check the the input is exhausted. The result is overridden to Err(()) if some input remains.

This can help tell e.g. color: green; from color: green 4px;

Parse a list of comma-separated values, all with the same syntax.

The given closure is called repeatedly with a "delimited" parser (see the Parser::parse_until_before method) so that it can over consume the input past a comma at this block/function nesting level.

Successful results are accumulated in a vector.

This method retuns Err(()) the first time that a closure call does, or if a closure call leaves some input before the next comma or the end of the input.

Parse the content of a block or function.

This method panics if the last token yielded by this parser (from one of the next* methods) is not a on that marks the start of a block or function: a Function, ParenthesisBlock, CurlyBracketBlock, or SquareBracketBlock.

The given closure is called with a "delimited" parser that stops at the end of the block or function (at the matching closing token).

The result is overridden to Err(()) if the closure leaves some input before that point.

Limit parsing to until a given delimiter or the end of the input. (E.g. a semicolon for a property value.)

The given closure is called with a "delimited" parser that stops before the first character at this block/function nesting level that matches the given set of delimiters, or at the end of the input.

The result is overridden to Err(()) if the closure leaves some input before that point.

Like parse_until_before, but also consume the delimiter token.

This can be useful when you don’t need to know which delimiter it was (e.g. if these is only one in the given set) or if it was there at all (as opposed to reaching the end of the input).

Parse a and return its value.

Parse a and return the unescaped value.

Parse a whose unescaped value is an ASCII-insensitive match for the given value.

Parse a and return the unescaped value.

Parse either a or a , and return the unescaped value.

Parse a and return the unescaped value.

Parse either a or a , and return the unescaped value.

Parse a and return the integer value.

Parse a that does not have a fractional part, and return the integer value.

Parse a and return the value. 0% and 100% map to 0.0 and 1.0 (not 100.0), respectively.

Parse a : .

Parse a ; .

Parse a , .

Parse a with the given value.

Parse a { /* ... */ } curly brackets block.

If the result is Ok, you can then call the Parser::parse_nested_block method.

Parse a [ /* ... */ ] square brackets block.

If the result is Ok, you can then call the Parser::parse_nested_block method.

Parse a ( /* ... */ ) parenthesis block.

If the result is Ok, you can then call the Parser::parse_nested_block method.

Parse a token and return its name.

If the result is Ok, you can then call the Parser::parse_nested_block method.

Parse a token whose name is an ASCII-insensitive match for the given value.

If the result is Ok, you can then call the Parser::parse_nested_block method.

Parse the input until exhaustion and check that it contains no “error” token.

See Token::is_parse_error. This also checks nested blocks and functions recursively.