Jawz84 / explainpowershell

PowerShell version of explainshell.com
https://www.explainpowershell.com/
MIT License
34 stars 1 forks source link

An escaped String and a string seem identical #81

Closed LaurentDardenne closed 1 year ago

LaurentDardenne commented 2 years ago

With

Write-host "$Name, action !"; Write-host "`$Name, action !"; Write-host "Name, action !" 

For the second , the escape character is not explained For the last : "String in which variables would be expanded.", but it is just a string whitout variable.

Jawz84 commented 2 years ago

About the second expamle:

"`$Name, action !"

Where the backtick ` is not explained: this is also a Tokenizer/AST issue I think. After tokenizing has taken place, the backtick is gone, and the string is just a string with a $ character in it, without the semantic meaning of a variable marker.

Here we can see it in action: image

So the solution could be simply to check the Extent for backtics, and if they are present, explain them. If you are interested, this is not a complicated fix. This is the relevant code where this could be added: https://github.com/Jawz84/explainpowershell/blob/9b2a3447dc952a9d102c02e27071e0bec6d259f6/explainpowershell.analysisservice/AstVisitorExplainer.cs#L821-L865

A test for this could be added here: https://github.com/Jawz84/explainpowershell/blob/9b2a3447dc952a9d102c02e27071e0bec6d259f6/explainpowershell.analysisservice.tests/Invoke-SyntaxAnalyzer.Tests.ps1#L9

As for the last one, that explanation is subtle, it only mentions that variables would be expanded (if they were present). It's just there to explain the difference between single quotes and double qoutes. Do you feel it's confusing?