-
Notifications
You must be signed in to change notification settings - Fork 428
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
Reason V4 [Stack 2/n #2599] [String Template Literals] #2599
base: master
Are you sure you want to change the base?
Conversation
16f84f2
to
41aa316
Compare
This feature allows directly embedding let expressions inside of interpolations such as: let commentInLetSequence2 = `
Okay, the following can accept not just an expression
but also a "let sequence":
${
let x = 200 + 49;
string_of_int(x);
}
Now wasn't that cool?
`; |
dc5f5a3
to
eed209d
Compare
8ef625d
to
a236e7f
Compare
Force pushed on top of the version angle braces and the feature that records a version inside of the file this PR |
a236e7f
to
ce9fac6
Compare
Summary:This diff implements string template literals. Test Plan: Reviewers: CC:
ce9fac6
to
5ee062e
Compare
Summary:This diff implements string template literals. Test Plan: Reviewers: CC:
Summary:This diff implements string template literals. Test Plan: Reviewers: CC:
5ee062e
to
2372580
Compare
Summary:This diff implements string template literals. Test Plan: Reviewers: CC:
2372580
to
5ea5843
Compare
Summary:This allows multiple versions of Reason in a single project by inferring and recording the version of syntax used into the file in an attribute. The attribute allows us to switch the parser and lexer on the fly. This attribute is not the only way we can infer the version, and we can allow project level configuration, but this is the approach that is guaranteed to work with any build system or tooling. Test Plan: Reviewers: CC:
Summary:This diff implements string template literals. Test Plan: Reviewers: CC:
5ea5843
to
9c9842a
Compare
I did some more thinking. I actually think using I also think we should parse/format it like this: let multiLineString = """
I am a multiline string
""""
/* ^ the string separators clearly indicate the beginning of the indentation. */ This is also exactly how multiline strings look like in Python, Swift, and Elixir, so recognizable for a lot of people. |
I'm not sure that's the proper place to ask, but is there any plan to have the template strings working with unicode characters? As per the doc file here, it seems the template strings are currently converted to "simple" strings, using the double quotes. We could have a modifier for this maybe, to make it opt-in, and to use the parsing rules, something like: let simple = `Created: ${string_of_int(42)}`;
// "Created: " ++ string_of_int(42)}
let unicode = u`Créée: ${string_of_int(42)}`;
// {j|Créée: |j} ++ string_of_int(42)} |
Reason Syntax String Template Literals
This feature implements a planned v4 feature, but in a way that is totally non-breaking and incremental.
String template literals (multiline-form):
I was able to make the multiline form of string templates completely non-breaking. It would be a minor version bump, not major. This doesn't implement the final v4 single line version of string templates, which may be a breaking change.
This does not conflict with polymorphic variants, because polymorphic variants do not have a newline break after the first backtick.
String templates automatically extract the indentation, and normalize it so that you don't have to align text to the zero column (as JS requires you do).
Bonus feature:
Non-multiline version of string templates in a non-breaking change.
Okay, this diff actually does implement single line string templates as well. It is not the final v4 form, but it currently works. It turns out that you can use any initial white space after the opening backtick and before the closing backtick - such as a space, and it will be treated the same.
In the first breaking change (v4), the leading/final space will not be required, and I would not recommend heavily advertising the single-line version in the mean time, but it was easy to support and did not present any syntactic conflict so I included it.
vim-reasonml plugin updated with support: