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

Change char payload #5759

Merged

Conversation

butterunderflow
Copy link
Contributor

@butterunderflow butterunderflow commented Oct 28, 2022

This PR changes the payload of Pconst_char. Related context: #5750 #5749

As I understand, the payload of char-related types uses magic starting from parsing to JavaScript dumping.
So lots of files were changed.

There are some things I don't quite understand:
The syntax repository and the compiler repository have some modules that are not exactly the same. Which one should we use for synchronization?
Because I modified the payload of Pconst_char, I had to modify parser.mly in the compiler repository, but I'm not sure if I'm safe to do that.

If my practice is on the right track, I will open another PR to submit the remaining part of syntax repo.

@butterunderflow butterunderflow marked this pull request as ready for review October 28, 2022 03:49
@butterunderflow butterunderflow changed the title Fix char pattern Change char payload Oct 28, 2022
@@ -21,7 +21,7 @@ open Lambda

let rec struct_const ppf = function
| Const_base(Const_int n) -> fprintf ppf "%i" n
| Const_base(Const_char c) -> fprintf ppf "%C" c
| Const_base(Const_char i) -> fprintf ppf "%C" (Char.unsafe_chr i)
| Const_base(Const_string (s, _)) -> fprintf ppf "%S" s
Copy link
Member

Choose a reason for hiding this comment

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

this should be adapted, '%C' may not apply any more

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I'm fixing this.

@butterunderflow butterunderflow marked this pull request as draft October 28, 2022 09:53
@@ -379,7 +379,7 @@ let is_cons = function

let pretty_const c = match c with
| Const_int i -> Printf.sprintf "%d" i
| Const_char c -> Printf.sprintf "%C" c
| Const_char i -> Printf.sprintf "%s" (Pprintast.string_of_int_as_char i)
| Const_string (s, _) -> Printf.sprintf "%S" s
Copy link
Member

Choose a reason for hiding this comment

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

Printast.string_of_int_as_char vs Ext_util.string_of_int_as_char?

Copy link
Member

Choose a reason for hiding this comment

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

It seems they are the same but shared across two repos

@bobzhang
Copy link
Member

LGTM, this also fixes #5753, you may add a changelog after it landed

@butterunderflow butterunderflow marked this pull request as ready for review October 31, 2022 02:52
@bobzhang bobzhang merged commit 6adc517 into rescript-lang:fix_char_pattern Oct 31, 2022
@bobzhang
Copy link
Member

I landed changes in syntax repo, you also need update the submodule in later commits

bobzhang pushed a commit that referenced this pull request Oct 31, 2022
* change Pconst_char payload (WIP)

* tweak

* tweak

* representation of char for lambda

* lib

* bugfix: replace wrong pp

* libs

* bugfix: replace wrong print

* use unsafe_chr to handle possible overflow char

* safe print int as char

* reduce duplication

* (re)use encodeCodepoint to support string_of_int_as_char

* some refactor

* libs

* changelog
bobzhang pushed a commit that referenced this pull request Oct 31, 2022
* change Pconst_char payload (WIP)

* tweak

* tweak

* representation of char for lambda

* lib

* bugfix: replace wrong pp

* libs

* bugfix: replace wrong print

* use unsafe_chr to handle possible overflow char

* safe print int as char

* reduce duplication

* (re)use encodeCodepoint to support string_of_int_as_char

* some refactor

* libs

* changelog
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.

2 participants