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

Characters following a hash # within a regex treated as a comment #12

Closed
jorgebucaran opened this issue Sep 14, 2018 · 2 comments
Closed

Comments

@jorgebucaran
Copy link

jorgebucaran commented Sep 14, 2018

If a regex contains a hash # the rest of the characters are incorrectly treated as a comment.

Desired Behavior

GitHub Code Block

/^#/ { print (n ? "\n" : "")$0 }

Actual Behavior

Visual Studio Code

untitled

@KyrosKrane
Copy link

The core problem appears to be that the parser isn't treating regular expression literals as literals. In the example above, the slashes in /^#/ should be treated as delimiters, similar to quotes around a string literal "like this."

A similar problem can be observed when putting quotes inside a regular expression literal. Consider the case where the code might want to replace quote marks inside a variable with something else, such as blanks (removing the quotes).

MyVar = "The \"quick brown fox\" jumped over the lazy dogs."
gsub(/"/, "", MyVar)
       ^--> display error here due to parser not understanding the RE literal

In this case, the parser treats the second slash (closing the RE literal) onwards as part of a string, started by the quote inside the RE literal.

@JohnNilsson
Copy link
Owner

Might have already fixed this at some other time. Only issue I could see now was that the enclosing / wasn't both scoped as string.regexp. Just pushed a fix for that at least.
Screenshot 2020-11-29 at 01 13 11

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

No branches or pull requests

3 participants