Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Invalid operation Precedence #367

Merged
merged 29 commits into from
Aug 8, 2024

Conversation

Ph0enixKM
Copy link
Member

@Ph0enixKM Ph0enixKM commented Jul 28, 2024

This will be a hefty one since it requires overhaul of an Expr syntax module and all operators.

What has changed:

  • The operators are now parsed with the following precedence:
Level Direction Precedence Group
N/A Unary operators: !, -, nameof
Left to Right Parentheses group: (x)
1 N/A Literals: Bool, Number, Text, Array, Null, Status
Left to Right Callables: FunctionInvocation, Command
N/A Variable access
2 Left to Right Advanced: is, as
3 Left to Right Multiplicative: *, /
Left to Right Modulo: %
4 Left to Right Additive: +, -
5 Left to Right Relational: >, <, >=, <=
6 Left to Right Equality: ==, !=
7 Left to Right Logical and
8 Left to Right Logical or
9 Left to Right Range: .., ..=
10 Right to Left Ternary then..else

Previously everything was parsed from right to left in the same precedence.
We should add this information to the documentation btw.

  • The error messages related to expressions now highlight the entire expressions they're related to.

The whole parsing couldn't be done in the Heraclitus way to parse everything contained in it's syntax module. This however could influence the development of Heraclitus to create some macro rules that would create an easy way to define precedence. For now as this is a rather important fix - I want to merge what I came up with so far.

@Ph0enixKM Ph0enixKM self-assigned this Jul 28, 2024
@Ph0enixKM Ph0enixKM linked an issue Jul 28, 2024 that may be closed by this pull request
@Ph0enixKM Ph0enixKM changed the title feat(expr): overhaul of expression syntax module [BUG] Invalid operation Precedence Jul 28, 2024
@Mte90
Copy link
Member

Mte90 commented Jul 29, 2024

The CI fails ;-)

@Ph0enixKM Ph0enixKM marked this pull request as ready for review July 29, 2024 14:46
@Ph0enixKM

This comment was marked as outdated.

@Ph0enixKM Ph0enixKM marked this pull request as draft July 29, 2024 15:31
@KrosFire
Copy link
Member

Equality shouldn't have the same precedence as inequality?

@Ph0enixKM
Copy link
Member Author

The CI fails because I haven't handled the unary operators yet. Hold on :)

Copy link
Member

@KrosFire KrosFire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add AlreadyParsedExpr and AlreadyParsedType? I don't see that we check them anywhere. Expression is an expression - it's parsed by definition, as it is not a token. It's part of the parsing result.

src/modules/expression/precedence.rs Outdated Show resolved Hide resolved
src/modules/expression/binop/add.rs Outdated Show resolved Hide resolved
@Ph0enixKM

This comment was marked as outdated.

@Ph0enixKM

This comment was marked as outdated.

@KrosFire

This comment was marked as outdated.

@KrosFire

This comment was marked as outdated.

@Ph0enixKM
Copy link
Member Author

Ph0enixKM commented Aug 1, 2024

Todo:

  • handle_binop to handle error messages as well.
  • Document the work (only once the current state of PR is approved)

@Ph0enixKM
Copy link
Member Author

Ph0enixKM commented Aug 1, 2024

I reverted the format commit because too much conflicts showed up. I'll do the format when we can merge this

@Ph0enixKM Ph0enixKM marked this pull request as ready for review August 1, 2024 22:44
@Ph0enixKM
Copy link
Member Author

Everyone is welcome to review this PR. The main changes:

  • expr/macro.rs now holds all of the repeating mechanism that expr/precedence.rs used to hold.
  • Some traits created such as BinOp, TernOp, UnOp and TypeOp to help me create special types of precedence groups for the macros.

Here is the usage of the new macro:
image

It reads like this:
A list of groups that are defined like this:

<group_name> @ <group_type> => [ ...<group_modules> ]

If you need any questions, ask me. If you approve this PR, let me know (or just approve). I'll write some guide to aid these changes.

@Mte90 Mte90 requested a review from mks-h August 2, 2024 10:53
@Ph0enixKM
Copy link
Member Author

Ph0enixKM commented Aug 5, 2024

@KrosFire This PR is now ready for final look.

The wiki has been added: https://github.com/amber-lang/amber/wiki
It's pretty simple, but we can iterate on it as we go

@Mte90 Mte90 requested a review from KrosFire August 5, 2024 15:11
Copy link
Member

@KrosFire KrosFire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks beautiful

src/modules/expression/binop/eq.rs Outdated Show resolved Hide resolved
src/modules/expression/binop/neq.rs Outdated Show resolved Hide resolved
src/modules/expression/binop/or.rs Outdated Show resolved Hide resolved
src/modules/expression/binop/sub.rs Outdated Show resolved Hide resolved
src/modules/expression/binop/and.rs Outdated Show resolved Hide resolved
src/modules/expression/unop/not.rs Outdated Show resolved Hide resolved
src/modules/shorthand/mul.rs Outdated Show resolved Hide resolved
@mks-h mks-h removed their request for review August 5, 2024 22:10
@Mte90 Mte90 requested a review from mks-h August 6, 2024 09:06
@Ph0enixKM
Copy link
Member Author

@KrosFire can you reiterate on the changes?

Copy link
Member

@KrosFire KrosFire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just small stuff. Looks good overall. Does someone have exp in macros? I've reached my limits XD

src/modules/expression/binop/and.rs Outdated Show resolved Hide resolved
src/modules/expression/binop/range.rs Outdated Show resolved Hide resolved
src/modules/expression/binop/range.rs Outdated Show resolved Hide resolved
src/modules/expression/ternop/ternary.rs Outdated Show resolved Hide resolved
src/modules/expression/ternop/ternary.rs Outdated Show resolved Hide resolved
Copy link
Member

@KrosFire KrosFire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Mte90 Mte90 merged commit 2851990 into master Aug 8, 2024
1 check passed
@Mte90 Mte90 deleted the 364-bug-invalid-operation-precedence branch August 8, 2024 10:06
Mte90 pushed a commit to Mte90/Amber that referenced this pull request Sep 19, 2024
* feat(expr): overhaul of expression syntax module

* feat: adapt binary operator modules to the new structure

* merge(precedence): resolve path to command

* fix(refactor): Added macros to make writing operator precedence much easier

* fix(expr): Attach operators to work with precedence macro

* feat(precedence): remove precedence file

* fix(format): Cargo clippy and fmt

* revert(format): Cargo clippy and fmt

This reverts commit 88fc6b0.

* fix(lint): resolve clippy errors

* Update src/modules/expression/macros.rs

Co-authored-by: Hubert Jabłoński <[email protected]>

* feat(tests): add validity tests

* fix(macro): improved handle binop macro

* fix(expr): remove pub from fields

* feat(macro): change prev to next

* feat(macro): add edge case for one group

* Update src/modules/expression/binop/sub.rs

Co-authored-by: Hubert Jabłoński <[email protected]>

* Update src/modules/expression/binop/eq.rs

Co-authored-by: Hubert Jabłoński <[email protected]>

* Update src/modules/expression/binop/neq.rs

Co-authored-by: Hubert Jabłoński <[email protected]>

* Update src/modules/expression/binop/or.rs

* Update src/modules/expression/binop/and.rs

* feat(error-macro): simplify code in a macro to keep DRY principle

* feat(test): Add test for multiple cast

* fix(and): remove comment

* fix(range): Fix range and remove import from code eval (the stdlib looks diffrent now)

* Update src/modules/expression/ternop/ternary.rs

Co-authored-by: Hubert Jabłoński <[email protected]>

* Update src/modules/expression/ternop/ternary.rs

Co-authored-by: Hubert Jabłoński <[email protected]>

---------

Co-authored-by: Hubert Jabłoński <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Invalid operation Precedence
3 participants