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

Add regex literal support #452

Merged
merged 6 commits into from
Sep 27, 2021
Merged

Add regex literal support #452

merged 6 commits into from
Sep 27, 2021

Conversation

TwitchBronBron
Copy link
Member

@TwitchBronBron TwitchBronBron commented Sep 24, 2021

Adds the ability to declare regular expression literals rather than dealing with strings. Example:

regexp = /[a-z]+/i

transpiles to

regexp = CreateObject("roRegex", "[a-z]+", "i")

Tasks:

  • Lexer functionality for capturing regex literals as a single token
  • parser functionality
  • handle escape characters e.g. /capture parens \( \)/
  • transpile functionality
  • user docs

@TwitchBronBron TwitchBronBron self-assigned this Sep 24, 2021
@TwitchBronBron TwitchBronBron linked an issue Sep 24, 2021 that may be closed by this pull request
@TwitchBronBron TwitchBronBron force-pushed the regex-literal branch 2 times, most recently from 1e5090a to 3a0da6f Compare September 24, 2021 14:34
@TwitchBronBron TwitchBronBron marked this pull request as ready for review September 24, 2021 14:53
@chrisdp
Copy link
Contributor

chrisdp commented Sep 24, 2021

Question. Should we support running the different functions inline?

https://developer.roku.com/en-ca/docs/references/brightscript/interfaces/ifregex.md#

So for example:

result = /[a-z]+/i.match(myString)

This could always be something we maybe support later but it just popped into my head.

@TwitchBronBron
Copy link
Member Author

Question. Should we support running the different functions inline?

https://developer.roku.com/en-ca/docs/references/brightscript/interfaces/ifregex.md#

So for example:

result = /[a-z]+/i.match(myString)

This could always be something we maybe support later but it just popped into my head.

This SHOULD work already since it's an expression. If you can do CreateObject("roRegex", "whatever").match(my string) then this new regex literal will also support that.

@TwitchBronBron TwitchBronBron merged commit 22c8a30 into master Sep 27, 2021
@TwitchBronBron TwitchBronBron deleted the regex-literal branch September 27, 2021 11:35
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.

Regular expression literal
3 participants