How to create a new language for use in Visual Studio

前端 未结 7 1752
礼貌的吻别
礼貌的吻别 2020-11-28 17:42

I want to write a new templating language, and I want Visual Studio to \"support\" it. What I need to know is:

  1. How do I parse my new language?
相关标签:
7条回答
  • 2020-11-28 18:25

    I wrote a VS Language Service using this article as my basis: http://www.codeproject.com/KB/recipes/VSLanguageService.aspx

    It wasn't too bad if you have a basic handle on Grammars.

    0 讨论(0)
  • 2020-11-28 18:29

    I was using VS with own language and desperately needed a syntax highlight. I built mine based on this tutorial: https://mattduffield.wordpress.com/2012/07/31/writing-a-brightscript-syntax-highlight-extension-for-visual-studio-2010/

    I know the tutorial is in VS2010. I made mine in VS2012 with no or very small hiccups. (also worked in VS2013) Recently I changed to VS2015 and the solution can be edited, built with no problem.

    0 讨论(0)
  • 2020-11-28 18:30

    Regarding the Visual Studio aspects, what you need is a "language service", which is the entity that handles colorizing, intellisense, etc. for a given file extension/type.

    For an intro, see this article
    And for a code sample see here

    Regarding parsing, there are lots of technologies, and I won't offer an opinion/advice.

    Beware, there is a fair amount of work involved, although in my opinion it is much more straightforward in VS2010 than in previous versions of Visual Studio to provide this kind of extension.

    See also

    Visual Studio 2010 Extensibility, MPF and language services

    0 讨论(0)
  • 2020-11-28 18:30

    I found this very useful collection of recent samples for Visual Studio 2013 SDK: http://blogs.msdn.com/b/vsx/archive/2014/05/30/vs-2013-sdk-samples-released.aspx

    It also contains the recent version of the OokLanguage which sounds promising.

    We used ANTLR 4 to parse our language which works like a charm and allows direct interaction with C# code. Can totally recommend it.

    0 讨论(0)
  • 2020-11-28 18:32

    There is a sample in the VS SDK that shows most of the features you are looking for.

    0 讨论(0)
  • 2020-11-28 18:36

    I would take a look at another language that has already done the legwork of integrating with Visual Studio. A great example is Boo. The language and Visual Studio integration are open source. So you can take a look at exactly what they had to do.

    • Boo Language: https://github.com/boo/boo-lang
    • Boo Syntax Highlighting for VS2010 (VSX add-in): http://vs2010boo.codeplex.com/
    • Boo Language Studio (syntax highlighting for VS2008): http://boolangstudio.codeplex.com/

    The Boo Syntax Highlighting for VS2010 includes some recommended links on its homepage, which I'll copy for easy reference:

    • Nice article about "classification" (syntax highligting) in VS 2010: http://dotneteers.net/blogs/divedeeper/archive/2008/11/04/LearnVSXNowPart38.aspx
    • Examples for VSX add-ins: http://blogs.msdn.com/vsxteam/archive/2009/06/17/new-editor-samples-for-visual-studio-2010-beta-1.aspx
    0 讨论(0)
提交回复
热议问题