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

Enable literal syntax for RegExp objects just like List and Map #10519

Closed
DartBot opened this issue May 8, 2013 · 5 comments
Closed

Enable literal syntax for RegExp objects just like List and Map #10519

DartBot opened this issue May 8, 2013 · 5 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented May 8, 2013

This issue was originally filed by azn...@gmail.com


In Javascript, just like [] and {} do for arrays and objects, Dart features LIst and Map shorthand create syntax.

But for some reason, for Regular Expression objects, this syntax (in Javascript, Perl, Ruby - use of the '//' delimiters) is not enabled.

So instead of:

new RegExp(r'^(_+)(._)$')

would like to write;

/^(_+)(._)$/

@madsager
Copy link
Contributor

madsager commented May 8, 2013

Added Area-Language, Triaged labels.

@lrhn
Copy link
Member

lrhn commented May 8, 2013

It's less important to have syntax for RegExps in Dart than in JavaScript due to Dart's raw strings.
The corresponding JavaScript constructor would be RegExp("^(*+)(.*)$"). Notice the extra backslash. Having explicit syntax means you can avoid duplicating the backslashes which are escapes in both string literals and regexp syntax.
In Dart, you can just do new RegExp(r"^(_+)(._)$") and keep the original regexp syntax.

From a parser writer's perspective, I can tell you that the JS RegExp syntax is ... special - it means that you can't separate tokenization from parsing, because you can't tell what, e.g., "/x/g" means without parsing. Is it a regexp literal, or are you writing "y/x/g" to divide by both x and g?


Removed Type-Defect label.
Added Type-Enhancement label.

@DartBot
Copy link
Author

DartBot commented May 8, 2013

This comment was originally written by ladicek@gmail.com


Isn't this a dupe of issue #289?

@DartBot
Copy link
Author

DartBot commented May 8, 2013

This comment was originally written by azn...@gmail.com


So what you're saying is that while the Dart parser can distinguish braces for Maps v. braces for code blocks, but is unable to perform like Javascript in distinguishing a literal regular expression v. math expression?

It's a code smell and a step backwards. Sorry, new RegExp(r'^(\\*+)(.\*)$'); is not as concise and clear as /^(_+)(._)$/.

@gbracha
Copy link
Contributor

gbracha commented Aug 25, 2014

Added Duplicate label.
Marked as being merged into #289.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report labels Aug 25, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants