PowerShell / EditorSyntax

PowerShell syntax highlighting for editors (VS Code, Atom, SublimeText, TextMate, etc.) and GitHub!
MIT License
133 stars 45 forks source link

Discussion: (-|+) before digits #4

Closed gravejester closed 8 years ago

gravejester commented 8 years ago

I'd like a discussion to decide whether +|- before a digit should be scoped as a part of the number literal or as a unary operator.

In IE it's scoped (and highlighted) as part of the number literal, but according to the PowerShell Language Specification they are in fact considered unary operators.

My initial though were to follow the specifications, but what are your thoughts?

Examples:

12 + 7 Here the + is clearly an operator.

+7 The question is whether it should be here as well, considering that this is also allowed: -$true and +"0xabc"

daviwil commented 8 years ago

@Jaykul @KirkMunro @rkeithhill - Any input here? My personal preference would be to make it part of the number if it's easy to do so in the grammar.

rkeithhill commented 8 years ago

PSReadLine colorizes +/- differently depending on whether it is part of a ConstantExpressionAst e.g. +5 or is part of a BinaryExpressionAst 1+5. But PSReadLine has access to the AST. Here, we are just talking about regex's right?

For instance, -$true and +"0xabc" are of type UnaryExpressionAst. I'd colorize that like +/- in a BinaryExpression.

This would be so much easier with help from the AST. :-) That said, I'd say go for it. I think you can whip a regex to distinguish between constants and other expression types and if it colorizes wrong on occasion - big deal.

gravejester commented 8 years ago

Yeah, this would have been so much easier with access to the AST, but there is always a way :)

I guess we have two votes for +- before digits as part of the number. I'll wait a bit before implementing anything so that others can chime in as well.

KirkMunro commented 8 years ago

Both PSReadLine and ISE change the coloring if the +/- is attached to the constant expression. I vote to follow that lead.

gravejester commented 8 years ago

Ok, I guess we have come to a consensus for letting the +/- before a digit be highlighted as part of that digit. I have already implemented this in my general refactoring of the tmlanguage file.

Thanks for your input!