aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/parser.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-01-21 14:27:48 -0700
committerbors-servo <metajack+bors@gmail.com>2015-01-21 14:27:48 -0700
commit59bca2962c19f653eec835fc54caf1a3eadcb906 (patch)
tree084e217ddd0c9ec710f5d77578a80c1ae358ade4 /components/style/parser.rs
parentad328fda65e6b7180de8b47f0964fe2f94c505a9 (diff)
parentd034a6c6bc5a473bad38b2ad00d2a08a0361138c (diff)
downloadservo-59bca2962c19f653eec835fc54caf1a3eadcb906.tar.gz
servo-59bca2962c19f653eec835fc54caf1a3eadcb906.zip
auto merge of #4689 : servo/servo/newnewnewcss, r=larsbergstrom
https://github.com/servo/rust-cssparser/pull/68 r? @larsbergstrom
Diffstat (limited to 'components/style/parser.rs')
-rw-r--r--components/style/parser.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/components/style/parser.rs b/components/style/parser.rs
new file mode 100644
index 00000000000..6619ffd06dd
--- /dev/null
+++ b/components/style/parser.rs
@@ -0,0 +1,42 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+use cssparser::{Parser, SourcePosition};
+use url::{Url, UrlParser};
+use log;
+
+use stylesheets::Origin;
+use namespaces::NamespaceMap;
+
+
+pub struct ParserContext<'a> {
+ pub stylesheet_origin: Origin,
+ pub base_url: &'a Url,
+ pub namespaces: NamespaceMap,
+}
+
+
+impl<'a> ParserContext<'a> {
+ pub fn in_user_agent_stylesheet(&self) -> bool {
+ self.stylesheet_origin == Origin::UserAgent
+ }
+
+ pub fn parse_url(&self, input: &str) -> Url {
+ UrlParser::new().base_url(self.base_url).parse(input)
+ .unwrap_or_else(|_| Url::parse("about:invalid").unwrap())
+ }
+}
+
+
+/// Defaults to a no-op.
+/// Set a `RUST_LOG=style::errors` environment variable
+/// to log CSS parse errors to stderr.
+pub fn log_css_error(input: &mut Parser, position: SourcePosition, message: &str) {
+ if log_enabled!(log::INFO) {
+ let location = input.source_location(position);
+ // TODO eventually this will got into a "web console" or something.
+ info!("{}:{} {}", location.line, location.column, message)
+ }
+}