Skip to content

Conversation

ota-meshi
Copy link
Member

@ota-meshi ota-meshi commented Apr 27, 2023

I was working on an experimental implementation of the RegExp Modifiers. I'm not sure yet if this implementation can be merged as-is, but I'm opening a PR to share my AST ideas as well.

https://github.com/tc39/proposal-regexp-modifiers

@RunDevelopment
Copy link

A bit of feedback from my first impression of the AST (I haven't looked at the parser implementation yet):

  1. Group#modifiers: Modifiers | null: When is modifiers null? Is it null when modifiers are impossible (legacy regexes) or when there are no modifiers (e.g. /(?:foo)/u)? What about /(?-:foo)/u?
  2. Modifiers#add and Modifiers#remove: What does null mean for them? Can both be null? If null means "no flags", then why not have a ModifierFlags with all flags set to false?
@ota-meshi
Copy link
Member Author

ota-meshi commented Oct 25, 2023

Thank you for your comment!

Group#modifiers: Modifiers | null: When is modifiers null? Is it null when modifiers are impossible (legacy regexes) or when there are no modifiers (e.g. /(?:foo)/u)? What about /(?-:foo)/u?

Regexps without modifiers will be null. For example, modifiers of (?:x) is null. (?-:x) will result in a parsing error.

Modifiers#add and Modifiers#remove: What does null mean for them? Can both be null? If null means "no flags", then why not have a ModifierFlags with all flags set to false?

I thought that nodes with no width should be avoided, but after re-checking it, it seems that nodes with no width already exist the nodes generated by regexpp. For example, a Flags node without flags has no width.
For consistency, it seems necessary to set a ModifierFlags node that sets all flags to false, as you say. I will make that change later.

@RunDevelopment
Copy link

Regexps without modifiers will be null. For example, modifiers of (?:x) is null.

I see, makes sense.

(?-:x) will result in a parsing error.

Ah, my bad. I only looked at the grammar itself and not its early errors.

@ota-meshi ota-meshi marked this pull request as ready for review October 11, 2024 01:20
@ota-meshi ota-meshi linked an issue Oct 11, 2024 that may be closed by this pull request
@MichaelDeBoey MichaelDeBoey added the enhancement New feature or request label Oct 11, 2024
@ota-meshi
Copy link
Member Author

Thank you for reviewing this PR.
The PR I opened for Acorn was also merged, so this one should be fine too. I will merge this PR.

@ota-meshi ota-meshi merged commit 347b151 into main Oct 27, 2024
16 checks passed
@ota-meshi ota-meshi deleted the modifiers branch October 27, 2024 11:39
@ota-meshi ota-meshi restored the modifiers branch October 27, 2024 11:39
@ota-meshi ota-meshi deleted the modifiers branch October 27, 2024 11:39
Copy link

🎉 This PR is included in version 4.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

3 participants