rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Regex literal syntax

Open glennsl opened this issue 1 year ago • 9 comments

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

glennsl avatar May 25 '24 12:05 glennsl

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

bloodyowl avatar May 25 '24 18:05 bloodyowl

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 avatar May 26 '24 07:05 glennsl

Tests passing! :partying_face:

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.

glennsl avatar May 26 '24 08:05 glennsl

@glennsl Could you add a CHANGELOG entry?

@IwanKaramazow Good to go?

cknitt avatar May 26 '24 13:05 cknitt

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

IwanKaramazow avatar May 27 '24 04:05 IwanKaramazow

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

Ping @IwanKaramazow 🙂

cknitt avatar Jun 14 '24 14:06 cknitt

Ah, yes, will do a review this weekend!

IwanKaramazow avatar Jun 14 '24 15:06 IwanKaramazow

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

cknitt avatar Jun 27 '24 17:06 cknitt

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

IwanKaramazow avatar Jun 27 '24 17:06 IwanKaramazow

Rebased and added changelog

glennsl avatar Jul 07 '24 15:07 glennsl

@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.

cknitt avatar Jul 12 '24 05:07 cknitt

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

IwanKaramazow avatar Jul 12 '24 06:07 IwanKaramazow