Skip to content

Commit

Permalink
put bitwise macro inside build_expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Maiori44 committed Jan 29, 2024
1 parent 21098de commit 33cad4f
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions core/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ macro_rules! vec_deque {
};
}

macro_rules! bitwise {
($self:expr, $t:expr, $expr:expr, $fname:literal, $end:expr, $notable:expr) => {{
if $self.build_bitwise_op(&$t, &mut $expr, $fname, $end, $notable)? {
break $t;
}
}};
}

/// A list of [`ComplexToken`]s, which is the AST.
pub type Expression = VecDeque<ComplexToken>;

Expand Down Expand Up @@ -824,6 +816,15 @@ impl<'a> ParserInfo<'a> {
let start = self.current;
let last = loop {
let t = self.advance();

macro_rules! bitwise {
($fname:literal) => {{
if self.build_bitwise_op(&t, &mut expr, $fname, end, notable)? {
break t;
}
}};
}

match t.kind() {
IDENTIFIER => {
let fname = self.build_identifier()?;
Expand Down Expand Up @@ -868,8 +869,8 @@ impl<'a> ParserInfo<'a> {
expr.push_back(CALL(vec![division]));
self.current -= 1;
}
BIT_AND => bitwise!(self, t, expr, "band", end, notable),
BIT_OR => bitwise!(self, t, expr, "bor", end, notable),
BIT_AND => bitwise!("band"),
BIT_OR => bitwise!("bor"),
BIT_XOR => {
//SAFETY: the token goes out of scope after BorrowedToken is used, so it stays valid
let t2 = if self.options.env_bitwise == BitwiseMode::Vanilla {
Expand All @@ -895,8 +896,8 @@ impl<'a> ParserInfo<'a> {
expr.push_back(SYMBOL(t.lexeme()))
}
}
LEFT_SHIFT => bitwise!(self, t, expr, "lshift", end, notable),
RIGHT_SHIFT => bitwise!(self, t, expr, "rshift", end, notable),
LEFT_SHIFT => bitwise!("lshift"),
RIGHT_SHIFT => bitwise!("rshift"),
NOT_EQUAL => {
self.check_operator(&t, notable, Some(&expr))?;
expr.push_back(SYMBOL(String::from("~=")))
Expand Down

0 comments on commit 33cad4f

Please sign in to comment.