Conlang: Add range operators
TODO: Limit range operators to at most 2 operands
This commit is contained in:
parent
b5abd2bff1
commit
ccfddcc09a
@ -17,7 +17,8 @@ Primary = Item | Identifier | Literal
|
||||
(* expression::math *)
|
||||
Ignore = Assign (IgnoreOp Assign )* ;
|
||||
Assign = Compare (AssignOp Compare)* ;
|
||||
Compare = Logic (CompareOp Logic )* ;
|
||||
Compare = Range (CompareOp Range )* ;
|
||||
Range = Logic (RangeOp Logic )* ;
|
||||
Logic = Bitwise (LogicOp Bitwise)* ;
|
||||
Bitwise = Shift (BitwiseOp Shift )* ;
|
||||
Shift = Term (ShiftOp Term )* ;
|
||||
|
@ -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 => "==",
|
||||
|
Loading…
Reference in New Issue
Block a user