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

"a".[0] syntax is not working #124

Closed
cometkim opened this issue Nov 29, 2020 · 3 comments
Closed

"a".[0] syntax is not working #124

cometkim opened this issue Nov 29, 2020 · 3 comments

Comments

@cometkim
Copy link
Contributor

According to the ReScript manual, a string "a" can be converted to char 'a' by .[0]

To convert a String to a Char, use "a".[0]. To convert a Char to a String, use String.make(1, 'a').

but the syntax is not working in ReScript.

>>>> Start compiling
bsb: [1/5] src/Test.ast
FAILED: src/Test.ast

  Syntax error!
  /home/cometkim/Workspace/tmp/rescript-template-test-8/src/Test.res:1:13

  1 │ let a = "a".[0]
  2 │

  I'm not sure what to parse here when looking at "[".


  Syntax error!
  /home/cometkim/Workspace/tmp/rescript-template-test-8/src/Test.res:1:14

  1 │ let a = "a".[0]
  2 │

  consecutive statements on a line must be separated by ';' or a newline

bsb: [2/5] src/App-MyRescriptApp.cmj
FAILED: src/App-MyRescriptApp.cmj

I'm not sure it's a compiler bug or It is just a mistake. I'd like to update the docs to use String.unsafe_get instead.

@cometkim
Copy link
Contributor Author

It's working on .re. I think it's a mistake while migrating docs from Reason. Is there a plan to support that syntax in the compiler? If so, Is it better to comment on it?

@IwanKaramazow
Copy link
Collaborator

@cometkim Thanks for the report! This fell under the radar, will be taken care of.

@chenglou
Copy link
Collaborator

chenglou commented Feb 7, 2021

Sorry forgot about this. Fixed the docs now. We won't be exposing a dedicated sugar for Char, especially since it's a disrecommended type (no unicode/utf-8, doesn't make sense in JS, etc.). Thanks for the report!

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

No branches or pull requests

3 participants