Skip to content

Commit

Permalink
Move precedence back to unary
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscerie committed Jun 1, 2024
1 parent 54278a0 commit abe5dbf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Punctuated<T>` now implements `Default` for all `T`, rather than if `T: Default`.

### Removed
- Removed `UnOp::precedence`, as unary operators do not traditionally use precedence in the same way binary operators do.
- Removed `TokenizerErrorType::UnexpectedShebang`.
- Removed `stacker` feature flag, as rewrites to the parser should make it unnecessary.

Expand Down
14 changes: 8 additions & 6 deletions full-moon/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,8 @@ macro_rules! make_bin_op {
}

impl BinOp {
/// The precedence of non-unary operator, from a scale of 1 to 10. The larger the number, the higher the precedence.
/// The precedence of non-unary operator. The larger the number, the higher the precedence.
/// Shares the same precedence table as unary operators.
pub fn precedence_of_token(token: &TokenReference) -> Option<u8> {
match token.token_type() {
TokenType::Symbol { symbol } => match symbol {
Expand All @@ -2074,11 +2075,6 @@ macro_rules! make_bin_op {
}
}

/// The precedence of unary operators
pub fn precedence_of_unary() -> u8 {
11
}

/// The token associated with this operator
pub fn token(&self) -> &TokenReference {
match self {
Expand Down Expand Up @@ -2208,6 +2204,12 @@ impl UnOp {
UnOp::Tilde(token) => token,
}
}

/// The precedence of unary operator. The larger the number, the higher the precedence.
/// Shares the same precedence table as binary operators.
pub fn precedence() -> u8 {
11
}
}

/// An error that occurs when creating the AST.
Expand Down
2 changes: 1 addition & 1 deletion full-moon/src/ast/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ fn parse_unary_expression(
let expression = match parse_expression_with_precedence(
state,
primary_expression,
ast::BinOp::precedence_of_unary(),
ast::UnOp::precedence(),
) {
ParserResult::Value(expression) => expression,
ParserResult::LexerMoved => return ParserResult::LexerMoved,
Expand Down

0 comments on commit abe5dbf

Please sign in to comment.