handle operators as part of binops

This commit is contained in:
ConnorSkees 2020-05-21 14:07:46 -04:00
parent 2bd8232a00
commit ff8447fd7e
4 changed files with 75 additions and 1 deletions

View File

@ -378,7 +378,27 @@ fn single_value<I: Iterator<Item = Token>>(
span: next.span.merge(val.span), span: next.span.merge(val.span),
} }
} }
_ => todo!(), Op::And => {
Spanned {
node: Value::Ident(
"and".into(),
QuoteKind::None,
),
span: next.span,
}
}
Op::Or => {
Spanned {
node: Value::Ident(
"or".into(),
QuoteKind::None,
),
span: next.span,
}
}
_ => {
return Err(("Expected expression.", next.span).into());
}
}, },
IntermediateValue::Whitespace => unreachable!(), IntermediateValue::Whitespace => unreachable!(),
IntermediateValue::Comma => return Err(("Expected expression.", span).into()), IntermediateValue::Comma => return Err(("Expected expression.", span).into()),

View File

@ -40,3 +40,14 @@ test!(
"a {\n color: 1 and 2 and 3;\n}\n", "a {\n color: 1 and 2 and 3;\n}\n",
"a {\n color: 3;\n}\n" "a {\n color: 3;\n}\n"
); );
test!(
part_of_binop,
"a {\n color: 1 - and;\n}\n",
"a {\n color: 1-and;\n}\n"
);
test!(
#[ignore = "casing is not preserved for keyword operators"]
part_of_binop_casing,
"a {\n color: 1 - AND;\n}\n",
"a {\n color: 1-AND;\n}\n"
);

View File

@ -130,3 +130,35 @@ error!(
tilde_in_value, tilde_in_value,
"a {color: ~a;}", "Error: Expected expression." "a {color: ~a;}", "Error: Expected expression."
); );
error!(
subtract_rem,
"a {color: 5 - %;}", "Error: Expected expression."
);
error!(
operator_eq,
"a {color: 5 - ==;}", "Error: Expected expression."
);
error!(
operator_ne,
"a {color: 5 - !=;}", "Error: Expected expression."
);
error!(
operator_gt,
"a {color: 5 - >;}", "Error: Expected expression."
);
error!(
operator_lt,
"a {color: 5 - <;}", "Error: Expected expression."
);
error!(
operator_ge,
"a {color: 5 - >=;}", "Error: Expected expression."
);
error!(
operator_le,
"a {color: 5 - <=;}", "Error: Expected expression."
);
error!(
operator_mul,
"a {color: 5 - *;}", "Error: Expected expression."
);

View File

@ -48,3 +48,14 @@ test!(
"a {\n color: 1 or 2 or 3;\n}\n", "a {\n color: 1 or 2 or 3;\n}\n",
"a {\n color: 1;\n}\n" "a {\n color: 1;\n}\n"
); );
test!(
part_of_binop,
"a {\n color: 1 - or;\n}\n",
"a {\n color: 1-or;\n}\n"
);
test!(
#[ignore = "casing is not preserved for keyword operators"]
part_of_binop_casing,
"a {\n color: 1 - OR;\n}\n",
"a {\n color: 1-OR;\n}\n"
);