Skip to content

Repository files navigation

The (C) Sharp Syntax Rewriter Tool

This is a Roslyn-based tool for C# syntax rewriting with the purpose of source-code desugaring.

Design

There are 2 varieties of rewriter:

  • a purely syntactic one, Rewriter, and
  • a symbolic one, SymbolicRewriter.

For the rewriting, the former relies on syntactic information only; the latter also relies on symbolic information by means of a SemanticModel.

Rewriters

  • BlockifyExpressionBody
  • DeanonymizeType
  • DecomposeNullConditional
  • EmplaceGlobalStatement
  • EnsureVisibleConstructor
  • ExpandForeach
  • ImplementAutoProperty
  • ImposeExplicitReturn
  • ImposeThisPrefix
  • InitializeOutArgument
  • ReplicateLocalInitialization
  • StoreObjectCreation
  • TranslateLinq
  • UncoalesceCoalescedNull
  • UninterpolateStrings
  • UnparameterizeRecordDeclaration

Hint: A "description" of the exact rewrite performed by a given rewriter, you might want to check the tests.

Example

voidApplyRewrite(IRewriterrewriter,SyntaxTreetree){SyntaxTreetree_P;if(rewriter.IsPurelySyntactic()){tree_P=((Rewriter)rewriter).Apply(tree);}else{Compilationcompilation=/* ... */tree_P=((SymbolicRewriter)rewriter).Apply(tree,compilation.GetSemanticModel(tree));}}

About

A C# syntax rewriter

Topics

Resources

Stars

20 stars

Watchers

15 watching

Forks

Releases

Packages

Used by

Contributors

Languages