mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
style: Implement Kleene logic for query feature expressions
Differential Revision: https://phabricator.services.mozilla.com/D163879
This commit is contained in:
parent
134f680503
commit
6c02e9fdaa
2 changed files with 7 additions and 6 deletions
|
@ -331,7 +331,7 @@ impl QueryCondition {
|
||||||
/// <general-enclosed>.
|
/// <general-enclosed>.
|
||||||
pub fn matches(&self, context: &computed::Context) -> KleeneValue {
|
pub fn matches(&self, context: &computed::Context) -> KleeneValue {
|
||||||
match *self {
|
match *self {
|
||||||
QueryCondition::Feature(ref f) => KleeneValue::from(f.matches(context)),
|
QueryCondition::Feature(ref f) => f.matches(context),
|
||||||
QueryCondition::GeneralEnclosed(_) => KleeneValue::Unknown,
|
QueryCondition::GeneralEnclosed(_) => KleeneValue::Unknown,
|
||||||
QueryCondition::InParens(ref c) => c.matches(context),
|
QueryCondition::InParens(ref c) => c.matches(context),
|
||||||
QueryCondition::Not(ref c) => !c.matches(context),
|
QueryCondition::Not(ref c) => !c.matches(context),
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
use super::feature::{Evaluator, QueryFeatureDescription};
|
use super::feature::{Evaluator, QueryFeatureDescription};
|
||||||
use super::feature::{FeatureFlags, KeywordDiscriminant};
|
use super::feature::{FeatureFlags, KeywordDiscriminant};
|
||||||
use crate::parser::{Parse, ParserContext};
|
use crate::parser::{Parse, ParserContext};
|
||||||
|
use crate::queries::condition::KleeneValue;
|
||||||
use crate::str::{starts_with_ignore_ascii_case, string_as_ascii_lowercase};
|
use crate::str::{starts_with_ignore_ascii_case, string_as_ascii_lowercase};
|
||||||
use crate::values::computed::{self, Ratio, ToComputedValue};
|
use crate::values::computed::{self, Ratio, ToComputedValue};
|
||||||
use crate::values::specified::{Integer, Length, Number, Resolution};
|
use crate::values::specified::{Integer, Length, Number, Resolution};
|
||||||
|
@ -575,7 +576,7 @@ impl QueryFeatureExpression {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether this query evaluates to true for the given device.
|
/// Returns whether this query evaluates to true for the given device.
|
||||||
pub fn matches(&self, context: &computed::Context) -> bool {
|
pub fn matches(&self, context: &computed::Context) -> KleeneValue {
|
||||||
macro_rules! expect {
|
macro_rules! expect {
|
||||||
($variant:ident, $v:expr) => {
|
($variant:ident, $v:expr) => {
|
||||||
match *$v {
|
match *$v {
|
||||||
|
@ -585,7 +586,7 @@ impl QueryFeatureExpression {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.feature().evaluator {
|
KleeneValue::from(match self.feature().evaluator {
|
||||||
Evaluator::Length(eval) => {
|
Evaluator::Length(eval) => {
|
||||||
let v = eval(context);
|
let v = eval(context);
|
||||||
self.kind
|
self.kind
|
||||||
|
@ -594,7 +595,7 @@ impl QueryFeatureExpression {
|
||||||
Evaluator::OptionalLength(eval) => {
|
Evaluator::OptionalLength(eval) => {
|
||||||
let v = match eval(context) {
|
let v = match eval(context) {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => return false,
|
None => return KleeneValue::Unknown,
|
||||||
};
|
};
|
||||||
self.kind
|
self.kind
|
||||||
.evaluate(v, |v| expect!(Length, v).to_computed_value(context))
|
.evaluate(v, |v| expect!(Length, v).to_computed_value(context))
|
||||||
|
@ -619,7 +620,7 @@ impl QueryFeatureExpression {
|
||||||
Evaluator::OptionalNumberRatio(eval) => {
|
Evaluator::OptionalNumberRatio(eval) => {
|
||||||
let ratio = match eval(context) {
|
let ratio = match eval(context) {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => return false,
|
None => return KleeneValue::Unknown,
|
||||||
};
|
};
|
||||||
// See above for subtleties here.
|
// See above for subtleties here.
|
||||||
self.kind
|
self.kind
|
||||||
|
@ -646,7 +647,7 @@ impl QueryFeatureExpression {
|
||||||
let boolean = eval(context);
|
let boolean = eval(context);
|
||||||
computed.map_or(boolean, |v| v == boolean)
|
computed.map_or(boolean, |v| v == boolean)
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue