Powershell: Support for SyntaxTrivia in the AST

Created on 15 Aug 2016  路  6Comments  路  Source: PowerShell/PowerShell

Roslyn accomplishes this by having LeadingTrivia and TrailingTrivia collections for each token in the Syntax Tree. PowerShell doesn't maintain this type of trivia in the AST so refactoring algorithms have to take the AST and parsed tokens into account when processing and reordering a script.

I feel like I talked to @lzybkr about this at one point so there may be a good reason for not doing this that I don't remember but I figure it'd be a cool discussion.

Up-for-Grabs WG-Engine

Most helpful comment

Yeah, we've discussed it. Refactoring is a major design point for Roslyn, so *Trivia collections are pretty much required.

It might make sense to add *Trivia collections to PowerShell, but probably as a build time option in a stand-alone dll for PowerShell editor services.

The reason PowerShell doesn't have whitespace trivia yet is that it's not needed at runtime (really the most important scenario for PowerShell) and computing the trivia has a non-zero cost. It took a lot of work from Roslyn to reach parity with the native compiler, so adding such a feature to PowerShell is expected to be a lot of work to do well.

Now it's certainly reasonable to build the parser as a standalone dll as a tools such as PowerShell editor services - in that build configuration, having *Trivia makes a lot of sense.

All 6 comments

Yeah, we've discussed it. Refactoring is a major design point for Roslyn, so *Trivia collections are pretty much required.

It might make sense to add *Trivia collections to PowerShell, but probably as a build time option in a stand-alone dll for PowerShell editor services.

The reason PowerShell doesn't have whitespace trivia yet is that it's not needed at runtime (really the most important scenario for PowerShell) and computing the trivia has a non-zero cost. It took a lot of work from Roslyn to reach parity with the native compiler, so adding such a feature to PowerShell is expected to be a lot of work to do well.

Now it's certainly reasonable to build the parser as a standalone dll as a tools such as PowerShell editor services - in that build configuration, having *Trivia makes a lot of sense.

@bergmeister Perhaps it can be interesting for you.

Having the parser as a standalone DLL would be pretty cool

I'd can investigate this but currently we have over 45 open PRs - slow reviews from MSFT team slow down community works 馃槙

No no, it's just a daydream for now. Tooling would benefit, but we should focus on what's being worked on currently for now.

The slow reviews are a consequence of driving other work at the moment -- hopefully it will pay dividends so that we can spend more time working on PowerShell itself.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ajensenwaud picture ajensenwaud  路  3Comments

aragula12 picture aragula12  路  3Comments

alx9r picture alx9r  路  3Comments

andschwa picture andschwa  路  3Comments

rkeithhill picture rkeithhill  路  3Comments