]> git.proxmox.com Git - rustc.git/blame - src/vendor/cssparser/src/lib.rs
New upstream version 1.25.0+dfsg1
[rustc.git] / src / vendor / cssparser / src / lib.rs
CommitLineData
ea8adc8c
XL
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#![crate_name = "cssparser"]
6#![crate_type = "rlib"]
7
8#![cfg_attr(feature = "bench", feature(test))]
9#![deny(missing_docs)]
10
11/*!
12
13Implementation of [CSS Syntax Module Level 3](https://drafts.csswg.org/css-syntax/) for Rust.
14
15# Input
16
17Everything is based on `Parser` objects, which borrow a `&str` input.
18If you have bytes (from a file, the network, or something)
19and want to support character encodings other than UTF-8,
20see the `stylesheet_encoding` function,
21which can be used together with rust-encoding or encoding-rs.
22
23# Conventions for parsing functions
24
25* Take (at least) a `input: &mut cssparser::Parser` parameter
26* Return `Result<_, ()>`
27* When returning `Ok(_)`,
28 the function must have consumed exactly the amount of input that represents the parsed value.
29* When returning `Err(())`, any amount of input may have been consumed.
30
31As a consequence, when calling another parsing function, either:
32
33* Any `Err(())` return value must be propagated.
34 This happens by definition for tail calls,
35 and can otherwise be done with the `try!` macro.
36* Or the call must be wrapped in a `Parser::try` call.
37 `try` takes a closure that takes a `Parser` and returns a `Result`,
38 calls it once,
39 and returns itself that same result.
40 If the result is `Err`,
41 it restores the position inside the input to the one saved before calling the closure.
42
43Examples:
44
45```{rust,ignore}
46// 'none' | <image>
47fn parse_background_image(context: &ParserContext, input: &mut Parser)
48 -> Result<Option<Image>, ()> {
49 if input.try(|input| input.expect_ident_matching("none")).is_ok() {
50 Ok(None)
51 } else {
52 Image::parse(context, input).map(Some) // tail call
53 }
54}
55```
56
57```{rust,ignore}
58// [ <length> | <percentage> ] [ <length> | <percentage> ]?
59fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
60 -> Result<(LengthOrPercentage, LengthOrPercentage), ()> {
61 let first = try!(LengthOrPercentage::parse);
62 let second = input.try(LengthOrPercentage::parse).unwrap_or(first);
63 (first, second)
64}
65```
66
67*/
68
69#![recursion_limit="200"] // For color::parse_color_keyword
70
71#[macro_use] extern crate cssparser_macros;
72#[macro_use] extern crate matches;
73#[macro_use] extern crate procedural_masquerade;
74#[doc(hidden)] pub extern crate phf as _internal__phf;
75#[cfg(test)] extern crate encoding_rs;
76#[cfg(test)] extern crate difference;
77#[cfg(test)] extern crate rustc_serialize;
78#[cfg(feature = "serde")] extern crate serde;
79#[cfg(feature = "heapsize")] #[macro_use] extern crate heapsize;
80
81pub use cssparser_macros::*;
82
83pub use tokenizer::{Token, NumericValue, PercentageValue, SourceLocation};
84pub use rules_and_declarations::{parse_important};
85pub use rules_and_declarations::{DeclarationParser, DeclarationListParser, parse_one_declaration};
86pub use rules_and_declarations::{RuleListParser, parse_one_rule};
87pub use rules_and_declarations::{AtRuleType, QualifiedRuleParser, AtRuleParser};
88pub use from_bytes::{stylesheet_encoding, EncodingSupport};
89pub use color::{RGBA, Color, parse_color_keyword};
90pub use nth::parse_nth;
91pub use serializer::{ToCss, CssStringWriter, serialize_identifier, serialize_string, TokenSerializationType};
92pub use parser::{Parser, Delimiter, Delimiters, SourcePosition};
93pub use unicode_range::UnicodeRange;
94
95// For macros
96#[doc(hidden)] pub use macros::_internal__to_lowercase;
97
98// For macros when used in this crate. Unsure how $crate works with procedural-masquerade.
99mod cssparser { pub use _internal__phf; }
100
101#[macro_use]
102mod macros;
103
104mod rules_and_declarations;
105
106#[cfg(feature = "dummy_match_byte")]
107mod tokenizer;
108
109#[cfg(not(feature = "dummy_match_byte"))]
110mod tokenizer {
111 include!(concat!(env!("OUT_DIR"), "/tokenizer.rs"));
112}
113mod parser;
114mod from_bytes;
115mod color;
116mod nth;
117mod serializer;
118mod unicode_range;
119
120#[cfg(test)]
121mod tests;