Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new language for use in Visual Studio

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?
    Given some code in my new template language, how do I translate it into HTML? Right now I'm using regular expressions to parse it token by token, but I don't think this is going to scale very well as the language gets more complicated, and there's no error checking. I've heard of ANTLR but never used it. Would that be the right tool for this job, or is there perhaps something simpler? Ideally I'd like to send any syntax errors to the error window with as much information as possible (line #, type of error) like other languages do.
  2. How do I create a new file type for Visual Studio?
  3. How do I get syntax highlighting?
    Can I use the same parser I created in step 1, or is this something entirely different?
  4. How do I get Intellisense?

I'd prefer to write my parser in C#.

like image 874
mpen Avatar asked Nov 26 '10 06:11

mpen


People also ask

How do I add more languages to Visual Studio?

Modify language packs To do so: Choose the Language packs tab in the Visual Studio Installer. Select the language you prefer. Follow the prompts.

Can Visual Studio run multiple languages?

1) You cannot have a Visual Studio project that uses multiple languages (unless you count ASM in C/C++). However, a single Visual Studio solution can have multiple projects where each project uses a different language.

Can I change Visual Studio language?

Once the installer is launched, click on Modify to modify the current installation of Visual Studio. 3. Then, you'll want to click on the Language Packs tab and select the language pack that you wish to install.

How do I change the script language in Visual Studio?

The standard way On the tab Installed, click button Modify next to the version of Visual Studio you need the English language pack for: In the next window, select Language packs tab, tick the English language and then accept changes by clicking Modify button (right bottom corner).


2 Answers

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
like image 135
James Kovacs Avatar answered Oct 12 '22 11:10

James Kovacs


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

like image 44
Brian Avatar answered Oct 12 '22 09:10

Brian