Skip to content

Commit 6adba1b

Browse files
committed
tokenizer: Look for both env() and var() functions.
Differential Revision: https://phabricator.services.mozilla.com/D9609
1 parent 394b781 commit 6adba1b

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cssparser"
3-
version = "0.24.1"
3+
version = "0.25.0"
44
authors = [ "Simon Sapin <[email protected]>" ]
55

66
description = "Rust implementation of CSS Syntax Level 3"

src/parser.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,17 +470,19 @@ impl<'i: 't, 't> Parser<'i, 't> {
470470
self.at_start_of = state.at_start_of;
471471
}
472472

473-
/// Start looking for `var()` functions. (See the `.seen_var_functions()` method.)
473+
/// Start looking for `var()` / `env()` functions. (See the
474+
/// `.seen_var_or_env_functions()` method.)
474475
#[inline]
475-
pub fn look_for_var_functions(&mut self) {
476-
self.input.tokenizer.look_for_var_functions()
476+
pub fn look_for_var_or_env_functions(&mut self) {
477+
self.input.tokenizer.look_for_var_or_env_functions()
477478
}
478479

479-
/// Return whether a `var()` function has been seen by the tokenizer since
480-
/// either `look_for_var_functions` was called, and stop looking.
480+
/// Return whether a `var()` or `env()` function has been seen by the
481+
/// tokenizer since either `look_for_var_or_env_functions` was called, and
482+
/// stop looking.
481483
#[inline]
482-
pub fn seen_var_functions(&mut self) -> bool {
483-
self.input.tokenizer.seen_var_functions()
484+
pub fn seen_var_or_env_functions(&mut self) -> bool {
485+
self.input.tokenizer.seen_var_or_env_functions()
484486
}
485487

486488
/// Execute the given closure, passing it the parser.

src/tokenizer.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub struct Tokenizer<'a> {
208208
/// of UTF-16 characters.
209209
current_line_start_position: usize,
210210
current_line_number: u32,
211-
var_functions: SeenStatus,
211+
var_or_env_functions: SeenStatus,
212212
source_map_url: Option<&'a str>,
213213
source_url: Option<&'a str>,
214214
}
@@ -234,29 +234,31 @@ impl<'a> Tokenizer<'a> {
234234
position: 0,
235235
current_line_start_position: 0,
236236
current_line_number: first_line_number,
237-
var_functions: SeenStatus::DontCare,
237+
var_or_env_functions: SeenStatus::DontCare,
238238
source_map_url: None,
239239
source_url: None,
240240
}
241241
}
242242

243243
#[inline]
244-
pub fn look_for_var_functions(&mut self) {
245-
self.var_functions = SeenStatus::LookingForThem;
244+
pub fn look_for_var_or_env_functions(&mut self) {
245+
self.var_or_env_functions = SeenStatus::LookingForThem;
246246
}
247247

248248
#[inline]
249-
pub fn seen_var_functions(&mut self) -> bool {
250-
let seen = self.var_functions == SeenStatus::SeenAtLeastOne;
251-
self.var_functions = SeenStatus::DontCare;
249+
pub fn seen_var_or_env_functions(&mut self) -> bool {
250+
let seen = self.var_or_env_functions == SeenStatus::SeenAtLeastOne;
251+
self.var_or_env_functions = SeenStatus::DontCare;
252252
seen
253253
}
254254

255255
#[inline]
256256
pub fn see_function(&mut self, name: &str) {
257-
if self.var_functions == SeenStatus::LookingForThem {
258-
if name.eq_ignore_ascii_case("var") {
259-
self.var_functions = SeenStatus::SeenAtLeastOne;
257+
if self.var_or_env_functions == SeenStatus::LookingForThem {
258+
if name.eq_ignore_ascii_case("var") ||
259+
name.eq_ignore_ascii_case("env")
260+
{
261+
self.var_or_env_functions = SeenStatus::SeenAtLeastOne;
260262
}
261263
}
262264
}

0 commit comments

Comments
 (0)