-
Notifications
You must be signed in to change notification settings - Fork 2k
Regular expressions can't start with whitespace #3756
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
Comments
@cscott @phadej Yes, this is an undocumented part of the syntax rules (well it has been documented many times in various issues, but I appreciate that not every CS user will go search through them when they encouter this). I suggest we add it to the |
A renamed 'Regular Expressions' section would be good. In that section you might link to http://www-archive.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions (by way of explaining the possible ambiguity with division) and mention the following:
wrt Block Regular Expressions, I noticed that it was missing an example of interpolation. It is probably worth adding and example and explicitly mentioning that the interpolation is a string and not escaped. That is: r1 = /\b/; # matches word boundary
r2 = /// #{r1} ///; # Never matches anything, because it wants a word boundary between two slash characters (!)
r3 = /// #{r1.source} ///; # yes
ext = ".jpg"
r4 = /// filename#{ext} ///; # matches filenameXext, the dot is not escaped (As a feature request, it might be nice to have a "regular expression interpolation" mode which would use |
I think adding something like
will suffice. |
It would be great if the error messages were better: A
or something like that. Does anyone know how to customize Jison to do this? Edit: Never mind, I figured it out. |
#3782 + the section I just added in the Common Gotchas wiki page should be enough in my opinion. No reason to add edge cases to the docs. Regarding my comment about those error messages above: They’re not needed anymore because of #3782. |
This might be bug or an "undocumented feature" -- but it's the latter, it should be better documented.
See also #3182 (regexps can't start with the equals sign either).
Escaping the initial whitespace as
/\ a/
is a workaround.The text was updated successfully, but these errors were encountered: