The Visual Studio 2008 Language Service Wizard can quickly establish a Babel language service for a new Visual Studio 2008 language. For more information on Babel, see Babel Package Overview. You can provide language service support for your own language by specifying the appropriate lexical (lex) and grammar (yacc) files, or for a sample language, My C Package, provided with the Visual Studio Industry Partner (VSIP) program. The Language Service Wizard allows you to define syntax highlighting, syntax checking, block commenting, brace matching, statement completion, and quick info for your language.
注意
The lexer and parser tools are not shipped with the Visual Studio 2008 SDK. There are a number of sources for lexers and parsers; two commonly used programs are lex and yacc. Alternatively, you can use open source versions of lex and yacc called flex and bison (one source for the latter two is Cygwin [http://www.cygwin.com]). Whichever tools you use, be sure to check the license agreement for those tools before distributing your language service.
The Language Service Wizard requires a lexer tool and a parser tool to be installed before the language service as created through the wizard can be built.
To create a language service VSPackage using the Visual Studio Language Service Wizard:
Create a new project.
On the File menu, point to New, and then click Project.
In the New Project dialog box, expand the Other Project Types, and select Extensibility.
Click the Visual Studio Language Package icon in the Templates pane.
In the Location box, type the file path for your VSPackage and in the Name box, type the name for the solution.
Click OK to start the wizard.
On the Language Information page, provide the name and the file extensions for your language. The maximum length for the language name is hundred (100) characters. This information is registered in the Visual Studio environment only, and not in the larger Windows environment.
On the Language Specification page, select the Use default lexer and parser check box to use the default lexer and grammar (provided by My C).
You can alternatively specify your own grammar files by clearing the Use default lexer and parser check box. You must then specify the Source file, the Output headers and Output sources for both the Lexer and the Parser.
In either case, you must provide your own grammar tools as they are not included in the Visual Studio SDK installation and the files generated by the Language Service Wizard cannot build without them. To build the My C language service VSPackage, you must use version 1.24 or later of Bison (a parser) and version 2.5.4a or later of Flex (a lexer). For your own language service, you can use these tools or your own tools; just change the Command line for both the Lexer and Parser in the Language Service Wizard to point to your tools.
For the default lexer and parser command lines, place the Bison and Flex executables in the Babel tools folder (for example, <root>\Program Files\VSIP 8.0\EnvSDK\Babel\Tools).
If you choose to provide your own source files for the lexer and parser, the limitations to the files are:
The wizard takes one lexer and one parser source file.
The tools used to compile a lexer and a parser must generate C++ code, and they must be executable from the command line.
Select the features you want your Language Service VSPackage to support on the Language Service Options page. The options you can select are:
Enable syntax highlighting.
To make this option fully functional, you need to specify the ColorClass for each token in the Language Tokens page (see step #5) or update the tokenInfoTable in service.cpp that is generated by the Language Service Wizard. For more information, see How-to: Enable Syntax Highlighting, specifically the "Mapping tokens to color classes" subtopic.
Enable syntax checking.
Select this check box to set the CodeSense registry entry to one (1) (found in [<VS Reg Root>\Languages\Language Services\<Language Name>]) to enable syntax checking. For more information on the registry entries, see Babel Registry Information. To make this option fully functional, you need to provide error productions in your grammar file (examples are included in the My C sample). For more information on error productions, see How-to: Add Syntax Checking, specifically the "Adding Error Productions" subtopic.
Allow block commenting and uncommenting.
For more information, see How to: Enable Block Commenting.
Enable brace matching.
Select this check box to set the MatchBraces registry entry to one (1) (found in [<VS Reg Root>\Languages\Language Services\<Language Name>]). To make this option fully functional, you need to add brace matching information into your grammar file (an example is included in My C sample language). For more information on brace matching, see How-to: Provide Automatic Brace Matching.
Match brace at cursor.
Select this check box to set MatchBracesAtCaret registry entry to one (1) (found in [<VS Reg Root>\Languages\Language Services\<Language Name>]) to enable brace matching as the caret moves through the source file.
Enable statement completion.
Select this check box to set the ShowCompletion and SortMemberList registry entries to one (1) (found in [<VS Reg Root>\Languages\Language Services\<Language Name>]) to enable statement completion. A default implementation of IScope Interface is also added to the language.
Enable quick info.
Select this check box to set the QuickInfo registry entry to one (1) (found in [<VS Reg Root>\Languages\Language Services\<Language Name>]). This enables quick info tips to be displayed when the user hovers the mouse over an identifier.
Define the tokens for syntax highlighting on the Language Tokens page.
The Load button loads a list of tokens from the parser source file (if that file follows the format of a yacc or bison source file). You can then select tokens from the list or you can define new tokens. For each token, you can define the Color Class (how each token should be colorized, see ColorClass) and the Char Class (specifies the type of token, see CharClass), as well as any possible triggers to make the parsing of your language more efficient. For more information on triggers, see How-to: Provide Automatic Brace Matching specifically the "Adding Triggers" subtopic, and TriggerClass. You can also rename and delete tokens on this page.
Click Finish to generate the code for your Language Service VSPackage.
After You Create the Visual Studio Language Service VSPackage
The language service VSPackage generated by the Language Service Wizard is properly registered to run in the Visual Studio 2008 Exp (experimental) environment. Carry out the following steps in the order mentioned below:
Build your language service VSPackage in Visual Studio 2008.
At the Visual Studio 2008 command prompt, start an instance of the EXP version of the Visual Studio 2008 by typing:
Devenv /rootsuffix exp
You can now open a file with an extension that is associated with your language service and see the language service effects in the editor window. If you used the lexer and grammar files for My C, do the following to see your language service in action:
To open a MyC file
On the File menu, select Open File.
Find the tflow.myc file and click OK.
The default location is <drive>:\Program Files\Visual Studio 2005 SDK\<build number>\VisualStudioIntegration\Archive\MyCPkgs\MyCC\TestsNavigate.
You now have an open code window in which you can see a MyC file. All the identifiers are colored as you described on the Language Tokens page of the Language Service Wizard.
Related Sections
You can also create a VSPackage by using the Visual Studio 2008 Package Wizard. The Package Wizard allows you to create either a boilerplate VSPackage or a VSPackage with a tool window, menu command, or basic editor as optional components. For more information, see How to: Create VSPackages (C# and VB)