Conlang: Add range operators
TODO: Limit range operators to at most 2 operands
This commit is contained in:
@@ -603,6 +603,12 @@ pub mod expression {
|
||||
/// `^^`: **Non-short-circuiting** logical XOR
|
||||
LogXor,
|
||||
|
||||
// Range operators
|
||||
/// `..`: Exclusive range
|
||||
RangeExc,
|
||||
/// `..=`: Inclusive range
|
||||
RangeInc,
|
||||
|
||||
// Comparison operators
|
||||
/// `<`: Less-than Comparison
|
||||
Less,
|
||||
|
||||
@@ -388,7 +388,8 @@ impl Parser {
|
||||
//name operands operators
|
||||
ignore = assign, ignore_op;
|
||||
assign = compare, assign_op;
|
||||
compare = logic, compare_op;
|
||||
compare = range, compare_op;
|
||||
range = logic, range_op;
|
||||
logic = bitwise, logic_op;
|
||||
bitwise = shift, bitwise_op;
|
||||
shift = term, shift_op;
|
||||
@@ -443,6 +444,10 @@ impl Parser {
|
||||
Type::BarBar => LogOr,
|
||||
Type::XorXor => LogXor,
|
||||
}
|
||||
range_op: {
|
||||
Type::DotDot => RangeExc,
|
||||
Type::DotDotEq => RangeInc,
|
||||
}
|
||||
compare_op: {
|
||||
Type::Lt => Less,
|
||||
Type::LtEq => LessEq,
|
||||
|
||||
@@ -98,6 +98,8 @@ impl<W: Write> Visitor<IOResult<()>> for Printer<W> {
|
||||
Binary::LogAnd => "&&",
|
||||
Binary::LogOr => "||",
|
||||
Binary::LogXor => "^^",
|
||||
Binary::RangeExc => "..",
|
||||
Binary::RangeInc => "..=",
|
||||
Binary::Less => "<",
|
||||
Binary::LessEq => "<=",
|
||||
Binary::Equal => "==",
|
||||
|
||||
Reference in New Issue
Block a user