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

(Rust) Escaped double quotations in string at attribute are not highlighted properly #3817

Open
keiichiw opened this issue Jul 10, 2023 · 3 comments
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language

Comments

@keiichiw
Copy link

Describe the issue

Escaped double quotations in string at attributes are not treated as a escaped character but a normal quotation.

Which language seems to have the issue?

Rust

Sample Code to Reproduce

#[derive(ThisError)]
enum MyError {
  #[error("\" appears in a string")]
  UnexpectedDoubleQuote
}

fn main() {}

sample at jsfiddle

image

Expected behavior

The escaped double quotation \" shouldn't be treated as a normal double quotation.

@keiichiw keiichiw added bug help welcome Could use help from community language labels Jul 10, 2023
@joshgoebel joshgoebel added the good first issue Should be easier for first time contributors label Jul 10, 2023
@joshgoebel
Copy link
Member

Confirm. Looks like a good first issue, probably need to reuse the full string rules inside meta... can ALL the syntactic features of strings be used in a #[] block?

@mohiyaddeen7
Copy link

{
className: 'string',
variants: [
{ begin: /b?r(#)"(.|\n)?"\1(?!#)/ }, // Handles raw strings with escaped double quotes
{ begin: /b?'\?(x\w{2}|u\w{4}|U\w{8}|.)'/ } // Handles character literals with escaped double quotes
]
]
}

we should add (.|\")*? to the first variant to match any character or an escaped double quote within the string.
we should add (\") to the second variant to allow for escaped double quotation marks within character literals.

update code snippet :

{
className: 'string',
variants: [
{ begin: /b?r(#)"(.|\")?"\1(?!#)/ }, // Handles raw strings with escaped double quotes
{ begin: /b?'\?(x\w{2}|u\w{4}|U\w{8}|.|\")'/ } // Handles character literals with escaped double quotes
]
}

please correct me if i am wrong.

@joshgoebel
Copy link
Member

Very hard to review code here when just thrown in as regular text, but if you'd be game to make a PR I'd be happy to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language
Projects
None yet
Development

No branches or pull requests

3 participants