Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for the bitwise NOT(~) unary operator#7418

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
cometkim merged 5 commits intorescript-lang:masterfromcometkim:op-bnot
May 5, 2025

Conversation

@cometkim
Copy link
Member

Part of the#7172

Allows to use~ in unary expressions, and make it as compiler primitive instead of using runtime library code

There is one syntax ambiguity problem with function arguments as we already use tilde token for the labeled argument syntax, e.g.

call(~a)//   ^ is it for passing labeled argument `a`?//   ^ or is it for passing bitwise NOT of `a` value

So we decided to enforce parens on that case.

call(~a)// is for passing labeled argumentscall((~a))// is for passing bitwise NOT of `a`, formatter will not force unparen for this specific expression.

And also we add parens in binary expressions too:

~a^b// be formatted into(~a)^b

Note: unlike existing+ and-,~n is not being parsed as constant, only expression

@cometkimcometkim requested a review fromcknittMay 4, 2025 13:43
@cometkimcometkim mentioned this pull requestMay 3, 2025
4 tasks
@cometkimcometkim changed the titleAdd support for the bitwise NOT() unary operatorAdd support for the bitwise NOT(~) unary operatorMay 4, 2025
@pkg-pr-new
Copy link

pkg-pr-newbot commentedMay 4, 2025
edited
Loading

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7418

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7418

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7418

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7418

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7418

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7418

commit:7983648

Copy link
Member

@cknittcknitt left a comment

Choose a reason for hiding this comment

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

Nice work! 🎉 Just left some comments.

@cristianoc could you review, too?

letis_es6_arrow_expression~in_ternaryp=
Parser.lookahead p (funstate ->
letasync=
let_async=
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why we didn't get a warning before if this is unused?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It was used for recovery on tilde token, I forgot to rollback the recovery change

Copy link
MemberAuthor

@cometkimcometkimMay 4, 2025
edited
Loading

Choose a reason for hiding this comment

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

Maybe not. we should remove the tilde handling because now we allow to use it somewhere in that context.

@cknittcknitt requested a review fromcristianocMay 4, 2025 15:20
;;call (~ a)
;;call ~a:(a ^ (~ a))
;;call ~a:(~ a)
;;call_partial 3 ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add some simple examples too? E.g.let z = ~y. To illustrate where parens are added, and where they are not.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think it has been added in theunary.res file already?

Copy link
Collaborator

@cristianoccristianoc left a comment

Choose a reason for hiding this comment

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

Looks good to me. Left a minor question.

|EqualGreater ->true
|_ ->false)
|Dot(* uncurried*) ->true
|Tildewhennot async ->true
Copy link
MemberAuthor

@cometkimcometkimMay 4, 2025
edited
Loading

Choose a reason for hiding this comment

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

Here where we use theasync bool value before

@cometkim
Copy link
MemberAuthor

I'm merging this and continuing to work on the|.

Let me know if there's still something that needs to be fixed

@cometkimcometkim merged commitc65c6c0 intorescript-lang:masterMay 5, 2025
21 checks passed
@cometkimcometkim deleted the op-bnot branchMay 5, 2025 00:28
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@cknittcknittcknitt left review comments

@cristianoccristianoccristianoc approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@cometkim@cknitt@cristianoc

[8]ページ先頭

©2009-2025 Movatter.jp