manually resolve some formatting issues
This commit is contained in:
parent
5255c7d829
commit
de78c1147a
@ -53,12 +53,16 @@ macro_rules! opt_hsl {
|
||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
f.insert("change-color".to_owned(), Builtin::new(|mut args, scope, super_selector| {
|
||||
if args.get_positional(1, scope, super_selector).is_some() {
|
||||
return Err(("Only one positional argument is allowed. All other arguments must be passed by name.", args.span()).into());
|
||||
return Err(
|
||||
("Only one positional argument is allowed. All other arguments must be passed by name.", args.span()
|
||||
).into());
|
||||
}
|
||||
|
||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||
Value::Color(c) => c,
|
||||
v => return Err((format!("$color: {} is not a color.", v.to_css_string(args.span())?), args.span()).into()),
|
||||
v => return Err(
|
||||
(format!("$color: {} is not a color.", v.to_css_string(args.span())?), args.span()
|
||||
).into()),
|
||||
};
|
||||
|
||||
opt_rgba!(args, alpha, "alpha", 0, 1, scope, super_selector);
|
||||
@ -73,7 +77,9 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
let hue = match named_arg!(args, scope, super_selector, "hue"=Value::Null) {
|
||||
Value::Dimension(n, _) => Some(n),
|
||||
Value::Null => None,
|
||||
v => return Err((format!("$hue: {} is not a number.", v.to_css_string(args.span())?), args.span()).into()),
|
||||
v => return Err(
|
||||
(format!("$hue: {} is not a number.", v.to_css_string(args.span())?), args.span()
|
||||
).into()),
|
||||
};
|
||||
|
||||
opt_hsl!(args, saturation, "saturation", 0, 100, scope, super_selector);
|
||||
@ -172,9 +178,12 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
f.insert(
|
||||
"scale-color".to_owned(),
|
||||
Builtin::new(|mut args, scope, super_selector| {
|
||||
let span = args.span();
|
||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||
Value::Color(c) => c,
|
||||
v => return Err((format!("$color: {} is not a color.", v.to_css_string(args.span())?), args.span()).into()),
|
||||
v => return Err(
|
||||
(format!("$color: {} is not a color.", v.to_css_string(span)?), span
|
||||
).into()),
|
||||
};
|
||||
|
||||
macro_rules! opt_scale_arg {
|
||||
@ -190,7 +199,9 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
)
|
||||
}
|
||||
Value::Null => None,
|
||||
v => return Err((format!("${}: {} is not a number.", $arg, v.to_css_string($args.span())?), $args.span()).into()),
|
||||
v => return Err(
|
||||
(format!("${}: {} is not a number.", $arg, v.to_css_string($args.span())?), $args.span()
|
||||
).into()),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -162,7 +162,6 @@ pub(crate) enum ColorName {
|
||||
impl Display for ColorName {
|
||||
#[allow(clippy::match_same_arms, clippy::many_single_char_names)]
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// I want them all to be on separate lines so doing things with regex or multiple cursors is easier
|
||||
match self {
|
||||
Self::AliceBlue => write!(f, "aliceblue"),
|
||||
Self::AntiqueWhite => write!(f, "antiquewhite"),
|
||||
|
21
src/lib.rs
21
src/lib.rs
@ -355,7 +355,13 @@ impl<'a> StyleSheetParser<'a> {
|
||||
.kind
|
||||
{
|
||||
q @ '"' | q @ '\'' => {
|
||||
file_name.push_str(&parse_quoted_string(&mut self.lexer, &Scope::new(), q, &Selector::new())?.node.unquote().to_css_string(span)?);
|
||||
file_name.push_str(
|
||||
&parse_quoted_string(
|
||||
&mut self.lexer,
|
||||
&Scope::new(),
|
||||
q,
|
||||
&Selector::new())?
|
||||
.node.unquote().to_css_string(span)?);
|
||||
}
|
||||
_ => todo!("expected ' or \" after @import"),
|
||||
}
|
||||
@ -383,10 +389,17 @@ impl<'a> StyleSheetParser<'a> {
|
||||
AtRule::Warn(message) => self.warn(rule.span, &message),
|
||||
AtRule::Debug(message) => self.debug(rule.span, &message),
|
||||
AtRule::Return(_) => {
|
||||
return Err(("This at-rule is not allowed here.", rule.span).into())
|
||||
return Err(
|
||||
("This at-rule is not allowed here.", rule.span).into()
|
||||
)
|
||||
}
|
||||
AtRule::Include(s) | AtRule::While(s) | AtRule::Each(s) | AtRule::For(s) => rules.extend(s),
|
||||
AtRule::Content => return Err(("@content is only allowed within mixin declarations.", rule.span).into()),
|
||||
AtRule::Include(s)
|
||||
| AtRule::While(s)
|
||||
| AtRule::Each(s)
|
||||
| AtRule::For(s) => rules.extend(s),
|
||||
AtRule::Content => return Err(
|
||||
("@content is only allowed within mixin declarations.", rule.span
|
||||
).into()),
|
||||
AtRule::If(i) => {
|
||||
rules.extend(i.eval(&mut Scope::new(), &Selector::new())?);
|
||||
}
|
||||
|
@ -33,11 +33,13 @@ pub(crate) enum Unit {
|
||||
Ex,
|
||||
/// The advance measure (width) of the glyph "0" of the element's font
|
||||
Ch,
|
||||
/// Represents the "cap height" (nominal height of capital letters) of the element’s font
|
||||
/// Represents the "cap height" (nominal height of capital letters) of the element's font
|
||||
Cap,
|
||||
/// Equal to the used advance measure of the "水" (CJK water ideograph, U+6C34) glyph found in the font used to render it
|
||||
/// Equal to the used advance measure of the "水" (CJK water ideograph, U+6C34) glyph
|
||||
/// found in the font used to render it
|
||||
Ic,
|
||||
/// Equal to the computed value of the line-height property on the root element (typically <html>), converted to an absolute length
|
||||
/// Equal to the computed value of the line-height property on the root element
|
||||
/// (typically <html>), converted to an absolute length
|
||||
Rlh,
|
||||
|
||||
// Viewport relative units
|
||||
@ -49,9 +51,11 @@ pub(crate) enum Unit {
|
||||
Vmin,
|
||||
/// 1% of the viewport's larger dimension
|
||||
Vmax,
|
||||
/// Equal to 1% of the size of the initial containing block, in the direction of the root element’s inline axis
|
||||
/// Equal to 1% of the size of the initial containing block, in the direction of the root
|
||||
/// element's inline axis
|
||||
Vi,
|
||||
/// Equal to 1% of the size of the initial containing block, in the direction of the root element’s block axis
|
||||
/// Equal to 1% of the size of the initial containing block, in the direction of the root
|
||||
/// element's block axis
|
||||
Vb,
|
||||
|
||||
// Angle units
|
||||
@ -59,7 +63,7 @@ pub(crate) enum Unit {
|
||||
Deg,
|
||||
/// Represents an angle in gradians. One full circle is 400grad
|
||||
Grad,
|
||||
/// Represents an angle in radians. One full circle is 2π radians which approximates to 6.2832rad
|
||||
/// Represents an angle in radians. One full circle is 2π radians which approximates to 6.283rad
|
||||
Rad,
|
||||
/// Represents an angle in a number of turns. One full circle is 1turn
|
||||
Turn,
|
||||
|
@ -7,7 +7,6 @@ test!(
|
||||
different_function_same_body_not_equal,
|
||||
"@function user-defined() {@return null}
|
||||
$first-reference: get-function(user-defined);
|
||||
|
||||
@function user-defined() {@return null}
|
||||
$second-reference: get-function(user-defined);
|
||||
a {b: $first-reference == $second-reference}",
|
||||
|
@ -47,7 +47,12 @@ macro_rules! error {
|
||||
fn $func() {
|
||||
match grass::StyleSheet::new($input.to_string()) {
|
||||
Ok(..) => panic!("did not fail"),
|
||||
Err(e) => assert_eq!($err, e.to_string().chars().take_while(|c| *c != '\n').collect::<String>().as_str()),
|
||||
Err(e) => assert_eq!($err, e.to_string()
|
||||
.chars()
|
||||
.take_while(|c| *c != '\n')
|
||||
.collect::<String>()
|
||||
.as_str()
|
||||
),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user