rename OpEquals to OpAssign, as all of them are compound assignment operators
This commit is contained in:
parent
5edcfc2156
commit
b318ec24a9
110
src/parser.rs
110
src/parser.rs
@ -156,22 +156,22 @@ pub enum Token {
|
|||||||
Fn,
|
Fn,
|
||||||
Break,
|
Break,
|
||||||
Return,
|
Return,
|
||||||
PlusEquals,
|
PlusAssign,
|
||||||
MinusEquals,
|
MinusAssign,
|
||||||
MultiplyEquals,
|
MultiplyAssign,
|
||||||
DivideEquals,
|
DivideAssign,
|
||||||
LeftShiftEquals,
|
LeftShiftAssign,
|
||||||
RightShiftEquals,
|
RightShiftAssign,
|
||||||
AndEquals,
|
AndAssign,
|
||||||
OrEquals,
|
OrAssign,
|
||||||
XOrEquals,
|
XOrAssign,
|
||||||
LeftShift,
|
LeftShift,
|
||||||
RightShift,
|
RightShift,
|
||||||
XOr,
|
XOr,
|
||||||
Modulo,
|
Modulo,
|
||||||
ModuloEquals,
|
ModuloAssign,
|
||||||
PowerOf,
|
PowerOf,
|
||||||
PowerOfEquals,
|
PowerOfAssign,
|
||||||
LexErr(LexError),
|
LexErr(LexError),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,23 +211,23 @@ impl Token {
|
|||||||
And |
|
And |
|
||||||
If |
|
If |
|
||||||
While |
|
While |
|
||||||
PlusEquals |
|
PlusAssign |
|
||||||
MinusEquals |
|
MinusAssign |
|
||||||
MultiplyEquals |
|
MultiplyAssign |
|
||||||
DivideEquals |
|
DivideAssign |
|
||||||
LeftShiftEquals |
|
LeftShiftAssign |
|
||||||
RightShiftEquals |
|
RightShiftAssign |
|
||||||
AndEquals |
|
AndAssign |
|
||||||
OrEquals |
|
OrAssign |
|
||||||
XOrEquals |
|
XOrAssign |
|
||||||
LeftShift |
|
LeftShift |
|
||||||
RightShift |
|
RightShift |
|
||||||
XOr |
|
XOr |
|
||||||
Modulo |
|
Modulo |
|
||||||
ModuloEquals |
|
ModuloAssign |
|
||||||
Return |
|
Return |
|
||||||
PowerOf |
|
PowerOf |
|
||||||
PowerOfEquals => true,
|
PowerOfAssign => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -538,7 +538,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
return match self.char_stream.peek() {
|
return match self.char_stream.peek() {
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
Some(Token::PlusEquals)
|
Some(Token::PlusAssign)
|
||||||
},
|
},
|
||||||
_ if self.last.is_next_unary() => Some(Token::UnaryPlus),
|
_ if self.last.is_next_unary() => Some(Token::UnaryPlus),
|
||||||
_ => Some(Token::Plus),
|
_ => Some(Token::Plus),
|
||||||
@ -548,7 +548,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
return match self.char_stream.peek() {
|
return match self.char_stream.peek() {
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
Some(Token::MinusEquals)
|
Some(Token::MinusAssign)
|
||||||
},
|
},
|
||||||
_ if self.last.is_next_unary() => Some(Token::UnaryMinus),
|
_ if self.last.is_next_unary() => Some(Token::UnaryMinus),
|
||||||
_ => Some(Token::Minus),
|
_ => Some(Token::Minus),
|
||||||
@ -558,7 +558,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
return match self.char_stream.peek() {
|
return match self.char_stream.peek() {
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
Some(Token::MultiplyEquals)
|
Some(Token::MultiplyAssign)
|
||||||
},
|
},
|
||||||
_ => Some(Token::Multiply)
|
_ => Some(Token::Multiply)
|
||||||
}
|
}
|
||||||
@ -592,7 +592,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
}
|
}
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
return Some(Token::DivideEquals);
|
return Some(Token::DivideAssign);
|
||||||
}
|
}
|
||||||
_ => return Some(Token::Divide),
|
_ => return Some(Token::Divide),
|
||||||
}
|
}
|
||||||
@ -621,7 +621,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
return match self.char_stream.peek() {
|
return match self.char_stream.peek() {
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
Some(Token::LeftShiftEquals)
|
Some(Token::LeftShiftAssign)
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
@ -643,7 +643,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
return match self.char_stream.peek() {
|
return match self.char_stream.peek() {
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
Some(Token::RightShiftEquals)
|
Some(Token::RightShiftAssign)
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
@ -671,7 +671,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
}
|
}
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
return Some(Token::OrEquals);
|
return Some(Token::OrAssign);
|
||||||
}
|
}
|
||||||
_ => return Some(Token::Pipe),
|
_ => return Some(Token::Pipe),
|
||||||
}
|
}
|
||||||
@ -684,7 +684,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
}
|
}
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
return Some(Token::AndEquals);
|
return Some(Token::AndAssign);
|
||||||
}
|
}
|
||||||
_ => return Some(Token::Ampersand),
|
_ => return Some(Token::Ampersand),
|
||||||
}
|
}
|
||||||
@ -693,7 +693,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
match self.char_stream.peek() {
|
match self.char_stream.peek() {
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
return Some(Token::XOrEquals);
|
return Some(Token::XOrAssign);
|
||||||
}
|
}
|
||||||
_ => return Some(Token::XOr)
|
_ => return Some(Token::XOr)
|
||||||
}
|
}
|
||||||
@ -702,7 +702,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
match self.char_stream.peek() {
|
match self.char_stream.peek() {
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
return Some(Token::ModuloEquals);
|
return Some(Token::ModuloAssign);
|
||||||
}
|
}
|
||||||
_ => return Some(Token::Modulo)
|
_ => return Some(Token::Modulo)
|
||||||
}
|
}
|
||||||
@ -711,7 +711,7 @@ impl<'a> TokenIterator<'a> {
|
|||||||
match self.char_stream.peek() {
|
match self.char_stream.peek() {
|
||||||
Some(&'=') => {
|
Some(&'=') => {
|
||||||
self.char_stream.next();
|
self.char_stream.next();
|
||||||
return Some(Token::PowerOfEquals);
|
return Some(Token::PowerOfAssign);
|
||||||
}
|
}
|
||||||
_ => return Some(Token::PowerOf)
|
_ => return Some(Token::PowerOf)
|
||||||
}
|
}
|
||||||
@ -745,17 +745,17 @@ pub fn lex(input: &str) -> TokenIterator {
|
|||||||
fn get_precedence(token: &Token) -> i32 {
|
fn get_precedence(token: &Token) -> i32 {
|
||||||
match *token {
|
match *token {
|
||||||
Token::Equals
|
Token::Equals
|
||||||
| Token::PlusEquals
|
| Token::PlusAssign
|
||||||
| Token::MinusEquals
|
| Token::MinusAssign
|
||||||
| Token::MultiplyEquals
|
| Token::MultiplyAssign
|
||||||
| Token::DivideEquals
|
| Token::DivideAssign
|
||||||
| Token::LeftShiftEquals
|
| Token::LeftShiftAssign
|
||||||
| Token::RightShiftEquals
|
| Token::RightShiftAssign
|
||||||
| Token::AndEquals
|
| Token::AndAssign
|
||||||
| Token::OrEquals
|
| Token::OrAssign
|
||||||
| Token::XOrEquals
|
| Token::XOrAssign
|
||||||
| Token::ModuloEquals
|
| Token::ModuloAssign
|
||||||
| Token::PowerOfEquals => 10,
|
| Token::PowerOfAssign => 10,
|
||||||
Token::Or
|
Token::Or
|
||||||
| Token::XOr
|
| Token::XOr
|
||||||
| Token::Pipe => 11,
|
| Token::Pipe => 11,
|
||||||
@ -959,14 +959,14 @@ fn parse_binop<'a>(input: &mut Peekable<TokenIterator<'a>>,
|
|||||||
Token::Multiply => Expr::FnCall("*".to_string(), vec![lhs_curr, rhs]),
|
Token::Multiply => Expr::FnCall("*".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::Divide => Expr::FnCall("/".to_string(), vec![lhs_curr, rhs]),
|
Token::Divide => Expr::FnCall("/".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::Equals => Expr::Assignment(Box::new(lhs_curr), Box::new(rhs)),
|
Token::Equals => Expr::Assignment(Box::new(lhs_curr), Box::new(rhs)),
|
||||||
Token::PlusEquals => {
|
Token::PlusAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
Box::new(Expr::FnCall("+".to_string(), vec![lhs_copy, rhs]))
|
Box::new(Expr::FnCall("+".to_string(), vec![lhs_copy, rhs]))
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
Token::MinusEquals => {
|
Token::MinusAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
@ -987,35 +987,35 @@ fn parse_binop<'a>(input: &mut Peekable<TokenIterator<'a>>,
|
|||||||
Token::Or => Expr::FnCall("||".to_string(), vec![lhs_curr, rhs]),
|
Token::Or => Expr::FnCall("||".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::And => Expr::FnCall("&&".to_string(), vec![lhs_curr, rhs]),
|
Token::And => Expr::FnCall("&&".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::XOr => Expr::FnCall("^".to_string(), vec![lhs_curr, rhs]),
|
Token::XOr => Expr::FnCall("^".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::OrEquals => {
|
Token::OrAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
Box::new(Expr::FnCall("|".to_string(), vec![lhs_copy, rhs]))
|
Box::new(Expr::FnCall("|".to_string(), vec![lhs_copy, rhs]))
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
Token::AndEquals => {
|
Token::AndAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
Box::new(Expr::FnCall("&".to_string(), vec![lhs_copy, rhs]))
|
Box::new(Expr::FnCall("&".to_string(), vec![lhs_copy, rhs]))
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
Token::XOrEquals => {
|
Token::XOrAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
Box::new(Expr::FnCall("^".to_string(), vec![lhs_copy, rhs]))
|
Box::new(Expr::FnCall("^".to_string(), vec![lhs_copy, rhs]))
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
Token::MultiplyEquals => {
|
Token::MultiplyAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
Box::new(Expr::FnCall("*".to_string(), vec![lhs_copy, rhs]))
|
Box::new(Expr::FnCall("*".to_string(), vec![lhs_copy, rhs]))
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
Token::DivideEquals => {
|
Token::DivideAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
@ -1027,14 +1027,14 @@ fn parse_binop<'a>(input: &mut Peekable<TokenIterator<'a>>,
|
|||||||
},
|
},
|
||||||
Token::LeftShift => Expr::FnCall("<<".to_string(), vec![lhs_curr, rhs]),
|
Token::LeftShift => Expr::FnCall("<<".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::RightShift => Expr::FnCall(">>".to_string(), vec![lhs_curr, rhs]),
|
Token::RightShift => Expr::FnCall(">>".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::LeftShiftEquals => {
|
Token::LeftShiftAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
Box::new(Expr::FnCall("<<".to_string(), vec![lhs_copy, rhs]))
|
Box::new(Expr::FnCall("<<".to_string(), vec![lhs_copy, rhs]))
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
Token::RightShiftEquals => {
|
Token::RightShiftAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
@ -1043,7 +1043,7 @@ fn parse_binop<'a>(input: &mut Peekable<TokenIterator<'a>>,
|
|||||||
},
|
},
|
||||||
Token::Ampersand => Expr::FnCall("&".to_string(), vec![lhs_curr, rhs]),
|
Token::Ampersand => Expr::FnCall("&".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::Modulo => Expr::FnCall("%".to_string(), vec![lhs_curr, rhs]),
|
Token::Modulo => Expr::FnCall("%".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::ModuloEquals => {
|
Token::ModuloAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
@ -1051,7 +1051,7 @@ fn parse_binop<'a>(input: &mut Peekable<TokenIterator<'a>>,
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
Token::PowerOf => Expr::FnCall("~".to_string(), vec![lhs_curr, rhs]),
|
Token::PowerOf => Expr::FnCall("~".to_string(), vec![lhs_curr, rhs]),
|
||||||
Token::PowerOfEquals => {
|
Token::PowerOfAssign => {
|
||||||
let lhs_copy = lhs_curr.clone();
|
let lhs_copy = lhs_curr.clone();
|
||||||
Expr::Assignment(
|
Expr::Assignment(
|
||||||
Box::new(lhs_curr),
|
Box::new(lhs_curr),
|
||||||
|
Loading…
Reference in New Issue
Block a user