Skip to content

Regex literal syntax#6776

Merged
cknitt merged 7 commits intorescript-lang:masterfrom
glennsl:feat/syntax/regex-literals
Jul 13, 2024
Merged

Regex literal syntax#6776
cknitt merged 7 commits intorescript-lang:masterfrom
glennsl:feat/syntax/regex-literals

Conversation

@glennsl
Copy link
Copy Markdown
Contributor

@glennsl glennsl commented May 25, 2024

This adds syntax for regex literals equivalent to the literal syntax in JavaScript. It is effectively just syntax sugar for the %re syntax extension, but opens up the additional possibility of checking the regex syntax during compilation.

The syntax looks like:

let re = /a.*c/mg

which is equivalent to:

let re = %re(`/a.*c/mg`)

and compiles to:

var re = /a.*c/mg;

Closes #6287

@bloodyowl
Copy link
Copy Markdown
Collaborator

I think it might be worth adding an attribute to the expression not to incorrectly print escaped regexp as an unescaped one

@glennsl
Copy link
Copy Markdown
Contributor Author

glennsl commented May 26, 2024

I think it might be worth adding an attribute to the expression not to incorrectly print escaped regexp as an unescaped one

I`m not sure I follow. Can you give an example?

@glennsl
Copy link
Copy Markdown
Contributor Author

glennsl commented May 26, 2024

Tests passing! 🥳

I'm sure the code quality could be improved, and we could add validation of the internal regex syntax either before or after merging this.

@cknitt
Copy link
Copy Markdown
Member

cknitt commented May 26, 2024

@glennsl Could you add a CHANGELOG entry?

@IwanKaramazow Good to go?

@IwanKaramazow
Copy link
Copy Markdown

@cknitt I'll do one last pass over the next few days to see if there aren't any edge cases.

@cknitt
Copy link
Copy Markdown
Member

cknitt commented Jun 14, 2024

@cknitt I'll do one last pass over the next few days to see if there aren't any edge cases.

Ping @IwanKaramazow 🙂

@IwanKaramazow
Copy link
Copy Markdown

Ah, yes, will do a review this weekend!

@cknitt
Copy link
Copy Markdown
Member

cknitt commented Jun 27, 2024

@IwanKaramazow Ping again. 🙂
Would be great to get this merged!

@IwanKaramazow
Copy link
Copy Markdown

Yes, sorry, I have some time off next week. Will get to this.

@glennsl
Copy link
Copy Markdown
Contributor Author

glennsl commented Jul 7, 2024

Rebased and added changelog

@cknitt
Copy link
Copy Markdown
Member

cknitt commented Jul 12, 2024

@glennsl As @IwanKaramazow does not seem to be available for review: Good to go from your point of view?

Then I'll merge and we can always refine things in follow-up PRs if necessary.

@IwanKaramazow
Copy link
Copy Markdown

Yea, sorry about this. The work looks good in general 👍

@cknitt cknitt merged commit 18a727a into rescript-lang:master Jul 13, 2024
@glennsl glennsl deleted the feat/syntax/regex-literals branch July 13, 2024 07:55
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.

Syntax for RegExp literals

4 participants