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

Multi line chained operator syntax #8415

Merged
merged 5 commits into from
Dec 1, 2023

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Nov 29, 2023

Pull Request Description

Fixes #7904.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Java,
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.

@JaroslavTulach JaroslavTulach added the CI: No changelog needed Do not require a changelog entry for this PR. label Nov 29, 2023
@JaroslavTulach JaroslavTulach requested a review from kazcw November 29, 2023 05:44
@JaroslavTulach JaroslavTulach self-assigned this Nov 29, 2023
@JaroslavTulach
Copy link
Member Author

@kazcw, is there a documentation or tests of the chained operator syntax other than this single paragraph?

What happens when the operator isn't ., but something else? Is it an error (just like in my PR)?

@somebody1234
Copy link
Contributor

somebody1234 commented Nov 29, 2023

there seem to be more tests here:

#[test]
fn code_block_operator() {
let code = ["value = nums", " * each random", " + constant"];
let expect = block![
(Assignment (Ident value) "="
(OperatorBlockApplication (Ident nums)
#(((Ok "*") (App (Ident each) (Ident random)))
((Ok "+") (Ident constant)))
#()))
];
test(&code.join("\n"), expect);
}
#[test]
fn dot_operator_blocks() {
let code = ["rect1", " . width = 7", " . center", " + x"];
#[rustfmt::skip]
let expected = block![
(OperatorBlockApplication (Ident rect1)
#(((Ok ".") (OprApp (Ident width) (Ok "=") (Number () "7" ())))
((Ok ".") (OperatorBlockApplication (Ident center)
#(((Ok "+") (Ident x))) #()))) #())];
test(&code.join("\n"), expected);
}

the first case contains other operators:

value = nums
    * each random
    + constant

the second case contains a nested OperatorBlockApplication:

rect1
    . width = 7
    . center
        + x

note that as per the design, it should be semantically equivalent to (((rect1) . width = 7) . center + x)

but at the very least, it means that the parser supports both these cases - i guess it's not explicitly part of the design, however the design does always say "an operator" rather than "the dot operator"

value = nums
+ each random
* constant
""");
Copy link
Member Author

Choose a reason for hiding this comment

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

According to @somebody1234's comment this is the desired behavior.

@JaroslavTulach JaroslavTulach added the CI: Keep up to date Automatically update this PR to the latest develop. label Dec 1, 2023
@JaroslavTulach
Copy link
Member Author

@somebody1234, @kazcw I am not sure what to think about

the second case contains a nested OperatorBlockApplication:

rect1
    . width = 7
    . center
        + x

note that as per the design, it should be semantically equivalent to (((rect1) . width = 7) . center + x)

I believe it is not a valid syntax: what should it mean rect1.width = 7? Assignment to a field width? There are no assignments to fields in Enso.

@somebody1234
Copy link
Contributor

@JaroslavTulach yeah... i'd assume that one is just a parser test. ((rect1) . width = 7).center makes even less sense, i think

@JaroslavTulach
Copy link
Member Author

The other inquiry I have is with nested blocks

rect1
    . width
    . center
        + x

what's the difference between the above and no-nesting block?

rect1
     . width
     . center
     + x

the latter one is clearly ((rect1 . width) . center) + x according to the short spec, but the first one? Does it have the same meaning (why do we have double syntax meaning the same)? Or should it first evaluate the nested block - e.g. (center + x).

@JaroslavTulach JaroslavTulach removed the CI: Keep up to date Automatically update this PR to the latest develop. label Dec 1, 2023
@JaroslavTulach
Copy link
Member Author

The behavior probably isn't fully correct, but the specification is so fuzzy that it's not clear what is correct anyway. Let's integrate at current state and solve the rest as bugs.

@JaroslavTulach JaroslavTulach merged commit b1be8c0 into develop Dec 1, 2023
35 checks passed
@JaroslavTulach JaroslavTulach deleted the wip/jtulach/ChainedOperator_7904 branch December 1, 2023 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chained operator block syntax
4 participants