diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index bf8e1bcb..83bcf4af 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -195,8 +195,10 @@ impl Lexer { '*' => { if self.characters.eat('=') { Has(TokenKind::MultiplyAssign.at(source)) - } else { + } else if self.characters.peek().is_spacing() { Has(TokenKind::Multiply.at(source)) + } else { + Has(TokenKind::Dereference.at(source)) } } '/' => { @@ -240,27 +242,29 @@ impl Lexer { '~' => Has(TokenKind::BitComplement.at(source)), '&' => { if self.characters.eat('=') { - Has(TokenKind::AmpersandAssign.at(source)) + Has(TokenKind::BitAndAssign.at(source)) } else if self.characters.eat('&') { Has(TokenKind::And.at(source)) + } else if self.characters.peek().is_spacing() { + Has(TokenKind::BitAnd.at(source)) } else { - Has(TokenKind::Ampersand.at(source)) + Has(TokenKind::AddressOf.at(source)) } } '|' => { if self.characters.eat('=') { - Has(TokenKind::PipeAssign.at(source)) + Has(TokenKind::BitOrAssign.at(source)) } else if self.characters.eat('|') { Has(TokenKind::Or.at(source)) } else { - Has(TokenKind::Pipe.at(source)) + Has(TokenKind::BitOr.at(source)) } } '^' => { if self.characters.eat('=') { - Has(TokenKind::CaretAssign.at(source)) + Has(TokenKind::BitXorAssign.at(source)) } else { - Has(TokenKind::Caret.at(source)) + Has(TokenKind::BitXor.at(source)) } } ',' => Has(TokenKind::Comma.at(source)), diff --git a/src/parser/parse_expr/primary/operator.rs b/src/parser/parse_expr/primary/operator.rs index 40198043..a0044433 100644 --- a/src/parser/parse_expr/primary/operator.rs +++ b/src/parser/parse_expr/primary/operator.rs @@ -41,9 +41,9 @@ impl<'a, I: Inflow> Parser<'a, I> { TokenKind::LessThanEq => BasicBinaryOperator::LessThanEq.into(), TokenKind::GreaterThan => BasicBinaryOperator::GreaterThan.into(), TokenKind::GreaterThanEq => BasicBinaryOperator::GreaterThanEq.into(), - TokenKind::Ampersand => BasicBinaryOperator::BitwiseAnd.into(), - TokenKind::Pipe => BasicBinaryOperator::BitwiseOr.into(), - TokenKind::Caret => BasicBinaryOperator::BitwiseXor.into(), + TokenKind::BitAnd => BasicBinaryOperator::BitwiseAnd.into(), + TokenKind::BitOr => BasicBinaryOperator::BitwiseOr.into(), + TokenKind::BitXor => BasicBinaryOperator::BitwiseXor.into(), TokenKind::LeftShift => BasicBinaryOperator::LeftShift.into(), TokenKind::LogicalLeftShift => BasicBinaryOperator::LogicalLeftShift.into(), TokenKind::RightShift => BasicBinaryOperator::RightShift.into(), diff --git a/src/parser/parse_stmt/parse_assignment.rs b/src/parser/parse_stmt/parse_assignment.rs index edb9f324..8b19abbe 100644 --- a/src/parser/parse_stmt/parse_assignment.rs +++ b/src/parser/parse_stmt/parse_assignment.rs @@ -16,9 +16,9 @@ impl<'a, I: Inflow> Parser<'a, I> { TokenKind::MultiplyAssign => Some(BasicBinaryOperator::Multiply), TokenKind::DivideAssign => Some(BasicBinaryOperator::Divide), TokenKind::ModulusAssign => Some(BasicBinaryOperator::Modulus), - TokenKind::AmpersandAssign => Some(BasicBinaryOperator::BitwiseAnd), - TokenKind::PipeAssign => Some(BasicBinaryOperator::BitwiseOr), - TokenKind::CaretAssign => Some(BasicBinaryOperator::BitwiseXor), + TokenKind::BitAndAssign => Some(BasicBinaryOperator::BitwiseAnd), + TokenKind::BitOrAssign => Some(BasicBinaryOperator::BitwiseOr), + TokenKind::BitXorAssign => Some(BasicBinaryOperator::BitwiseXor), TokenKind::LeftShiftAssign => Some(BasicBinaryOperator::LeftShift), TokenKind::RightShiftAssign => Some(BasicBinaryOperator::RightShift), TokenKind::LogicalLeftShiftAssign => Some(BasicBinaryOperator::LogicalLeftShift), diff --git a/src/text/character.rs b/src/text/character.rs index 4309c479..3b8873a6 100644 --- a/src/text/character.rs +++ b/src/text/character.rs @@ -61,6 +61,11 @@ impl Character { matches!(self, Character::At('+' | '-', _)) } + #[inline] + pub fn is_spacing(&self) -> bool { + matches!(self, Character::At(' ' | '\n' | '\t', _)) + } + #[inline] pub fn source(&self) -> Source { match self { diff --git a/src/token.rs b/src/token.rs index af98bbbd..9575c833 100644 --- a/src/token.rs +++ b/src/token.rs @@ -96,6 +96,8 @@ pub enum TokenKind { Colon, Hash, Ellipsis, + AddressOf, + Dereference, DeclareAssign, Assign, AddAssign, @@ -103,18 +105,18 @@ pub enum TokenKind { MultiplyAssign, DivideAssign, ModulusAssign, - AmpersandAssign, - PipeAssign, - CaretAssign, + BitAndAssign, + BitOrAssign, + BitXorAssign, LeftShiftAssign, RightShiftAssign, LogicalLeftShiftAssign, LogicalRightShiftAssign, And, Or, - Ampersand, - Pipe, - Caret, + BitAnd, + BitOr, + BitXor, LeftShift, RightShift, LogicalLeftShift, @@ -177,6 +179,8 @@ impl Display for TokenKind { TokenKind::Colon => f.write_str("':'"), TokenKind::Hash => f.write_str("'#'"), TokenKind::Ellipsis => f.write_str("'...'"), + TokenKind::AddressOf => f.write_str("(address of) '&'"), + TokenKind::Dereference => f.write_str("(dereference) '*'"), TokenKind::DeclareAssign => f.write_str("':='"), TokenKind::Assign => f.write_str("'='"), TokenKind::AddAssign => f.write_str("'+='"), @@ -184,18 +188,18 @@ impl Display for TokenKind { TokenKind::MultiplyAssign => f.write_str("'*='"), TokenKind::DivideAssign => f.write_str("'/='"), TokenKind::ModulusAssign => f.write_str("'%='"), - TokenKind::AmpersandAssign => f.write_str("'&='"), - TokenKind::PipeAssign => f.write_str("'|='"), - TokenKind::CaretAssign => f.write_str("'^='"), + TokenKind::BitAndAssign => f.write_str("'&='"), + TokenKind::BitOrAssign => f.write_str("'|='"), + TokenKind::BitXorAssign => f.write_str("'^='"), TokenKind::LeftShiftAssign => f.write_str("'<<='"), TokenKind::RightShiftAssign => f.write_str("'>>='"), TokenKind::LogicalLeftShiftAssign => f.write_str("'<<<='"), TokenKind::LogicalRightShiftAssign => f.write_str("'>>>='"), TokenKind::And => f.write_str("'&&'"), TokenKind::Or => f.write_str("'||'"), - TokenKind::Ampersand => f.write_str("'&'"), - TokenKind::Pipe => f.write_str("'|'"), - TokenKind::Caret => f.write_str("'^'"), + TokenKind::BitAnd => f.write_str("'&'"), + TokenKind::BitOr => f.write_str("'|'"), + TokenKind::BitXor => f.write_str("'^'"), TokenKind::LeftShift => f.write_str("'<<'"), TokenKind::RightShift => f.write_str("'>>'"), TokenKind::LogicalLeftShift => f.write_str("'<<<'"), @@ -234,9 +238,9 @@ impl TokenKind { TokenKind::GreaterThanEq => 9, TokenKind::Equals => 8, TokenKind::NotEquals => 8, - TokenKind::Ampersand => 7, - TokenKind::Caret => 6, - TokenKind::Pipe => 5, + TokenKind::BitAnd => 7, + TokenKind::BitXor => 6, + TokenKind::BitOr => 5, TokenKind::And => 4, TokenKind::Or => 3, TokenKind::DeclareAssign @@ -245,9 +249,9 @@ impl TokenKind { | TokenKind::MultiplyAssign | TokenKind::DivideAssign | TokenKind::ModulusAssign - | TokenKind::AmpersandAssign - | TokenKind::PipeAssign - | TokenKind::CaretAssign + | TokenKind::BitAndAssign + | TokenKind::BitOrAssign + | TokenKind::BitXorAssign | TokenKind::LeftShiftAssign | TokenKind::RightShiftAssign | TokenKind::LogicalLeftShiftAssign @@ -286,6 +290,8 @@ impl TokenKind { | TokenKind::Colon | TokenKind::Hash | TokenKind::Ellipsis + | TokenKind::AddressOf + | TokenKind::Dereference | TokenKind::Namespace | TokenKind::Extend | TokenKind::FatArrow => 0, @@ -300,9 +306,9 @@ impl TokenKind { | Self::MultiplyAssign | Self::DivideAssign | Self::ModulusAssign - | Self::AmpersandAssign - | Self::PipeAssign - | Self::CaretAssign + | Self::BitAndAssign + | Self::BitOrAssign + | Self::BitXorAssign | Self::LeftShiftAssign | Self::RightShiftAssign | Self::LogicalLeftShiftAssign