title: What's the best way to highlight C# syntax using Roslyn?
body: <p>I'm trying to make a Xamarin.Android app that highlights the syntax of many different languages. I plan to use ANTLR to deal with most of them, but for C# I want to use Roslyn as that will undoubtedly be faster and less buggy than ANTLR.</p>
  
  <p>What is the best way to implement syntax highlighting with Roslyn? For highlighting Java syntax, the approach I took was parsing the text into a parse tree, and using a visitor to color the text associated with each terminal. You can view my code <a href="https://github.com/jamesqo/Repository/tree/master/Repository.EditorServices/Internal/Languages/Java/SyntaxHighlighting" rel="nofollow noreferrer">here</a>. Is this also a good idea for Roslyn, or does Roslyn provide APIs for syntax highlighting? (e.g. Does the code behind syntax highlighting in Visual Studio live in the <a href="https://github.com/dotnet/roslyn" rel="nofollow noreferrer">dotnet/roslyn</a> repo?) I'd really prefer not to reinvent the wheel, but I will if I have to.</p>
  
  <p><strong>edit:</strong> I have accepted Tamas' answer because his solution is the most practical for my use case; I do not have access to the full solution to build a semantic model with, so I will have to do some of my own analysis. However, if your app supports more broad C# integration and can build a semantic model, take a look at the Roslyn Classification APIs which are used in Jonathon Marolf's answer.</p>