pygments / pygments

Pygments is a generic syntax highlighter written in Python
http://pygments.org/
BSD 2-Clause "Simplified" License
1.75k stars 640 forks source link

Tcl: backslashes #2686

Open verhovsky opened 2 months ago

verhovsky commented 2 months ago

None of these are errors

set amount \$16.42
puts lots\nof\n\n\n\n\n\nnewlines
set somevar {
    This is a literal $ sign, and this \} escaped
    brace remains uninterpreted
}

https://pygments.org/demo/?lexer=tcl&style=solarized-light&formatter=html&code=%23+backslash+suppresses+the+special+meaning+of+characters%3A%0Aset+amount+%5C%2416.42%0A%0A%0A%23+backslash+adds+special+meaning+to+certain+characters%3A%0Aputs+lots%5Cnof%5Cn%5Cn%5Cn%5Cn%5Cn%5Cnnewlines%0A%0A%0A%23+A+word+enclosed+in+braces+is+not+subject+to+any+special+interpretation+or%0A%23+substitutions%2C+except+that+a+backslash+before+a+brace+is+not+counted+when%0A%23+looking+for+the+closing+brace%3A%0Aset+somevar+%7B%0A++++This+is+a+literal+%24+sign%2C+and+this+%5C%7D+escaped%0A++++brace+remains+uninterpreted%0A%7D%0A

Anteru commented 1 month ago

We're not trying to be accurate in terms of finding errors; if you provide invalid code, there's no way for us to flag it. The goal of Pygments is to highlight semantically correct code.

verhovsky commented 1 month ago

Pygments is highlighting the backslashes as errors but they're not errors. It is correct code, it comes from here

# backslash suppresses the special meaning of characters:
set amount \$16.42

# backslash adds special meaning to certain characters:
puts lots\nof\n\n\n\n\n\nnewlines

https://www.learnxinyminutes.com/docs/tcl/

Anteru commented 1 month ago

Ah ok, sorry, misread your initial statement.

IshaanVerma1130 commented 4 weeks ago

What should be the intended output for the \n characters? Is it TEXT.WHITESPACE or Literal.String.Escape. The TcL highlighter in VSCODE marks it as String.Escape. Below is the output after considering them as Literal.String.Escape: image