Share via


Managed Babel Essentials

Managed Babel is a component of the managed language services that are integrated into Visual Studio. It provides the colorization, brace matching, and IntelliSense features that are available to built-in Visual Studio languages such as Visual C# and Visual Basic. Managed Babel can be extended to provide many more Visual Studio editing features.

Managed Babel is written in C#. It depends on the parser and scanner generation tools named MPLex and MPPG, which resemble lex and yacc except that they generate C# code.

Managed Babel Components

Managed Babel consists of the following three components:

  • Managed Package Lex Scanner Generator (MPLex)

  • Managed Package Parser Generator (MPPG)

  • Managed Babel source code that extends Managed Package Framework (MPF) classes

MPLex and MPPG are located in

Visual Studio SDK installation path\VisualStudioIntegration\Tools\Bin\.

The ManagedBabel source code is located in

Visual Studio SDK installation path\VisualStudioIntegration\Common\Source\CSharp\Babel\.

The supporting documentation is located in

Visual Studio SDK installation path\VisualStudioIntegration\ExtraDocumentation\. Look for Managed Babel Overview.pdf, MPLex.pdf, and MPPG.pdf

Note

MPLex and MPPG are supported on .NET Framework 2.0 and later versions. They are not supported on earlier versions of the .NET Framework.

How Managed Babel Works

The language developer first writes two files, typically named something like lexer.lex and parser.y These files follow the lex and yacc conventions for token definition and formatting. A special build step calls MPLex, which generates a scanner.cs file that defines the scanner class. Another build step calls MPPG, which generates a parser.cs file that partially defines the parser class. These classes are integrated together with the Managed Babel source code and user-supplied code to form a complete language service.

The Managed Package Lex (MPLex) Scanner Generator

MPLex is a scanner generator that accepts a lex-like specification file that defines the tokens of the language and produces a C# scanner class. The tokens can then be processed by a parser that is generated by MPPG. For more information about MPLex, see MPLEX.pdf.

The Managed Package Parser Generator (MPPG)

MPPG is a parser generator that accepts a yacc-like specification file, plus the output of the MPLex tool, and generates a C# partial parser class. For more information about MPPG, see MPPG.pdf.

Managed Babel Source Code

Managed Babel source code integrates the scanner and parser classes that are generated by MPLex and MPPG together with Managed Babel classes to add user-defined tokens and grammar into a Visual Studio language service. Some of the important Managed Babel classes are the following ones:

  • The BabelPackage class, which is a subclass of the Package class. Defines the Managed Babel VSPackage and integrates it into Visual Studio.

  • The BabelLanguageService class, which is an abstract subclass of the LanguageService class. A user-defined subclass of BabelLanguageService sets the characteristics of the particular language.

  • The Parser partial class, which defines basic language features such as errors and brace matching. This partial class is defined by the parser class that is generated by the MPPG tool.

  • The IASTResolver interface, which defines the methods that should be implemented by a user-supplied class to support auto-completion and IntelliSense.

  • The LineScanner class is the Managed Babel implementation of the interface IScanner. It is used to retrieve information about colorization from the document.

  • The Configuration partial class, which defines some basic aspects of language customization such as token color and token definitions. A user-supplied partial class is required to complete the definitions.

As an option, you can modify some of these files to add or customize certain language service features.

User-Supplied Source Code

Some of the Managed Babel classes and interfaces must have user-supplied implementations or subclasses. These user-supplied classes are as follows:

  • A Package class that is a subclass of the BabelPackage class. At a minimum, this Package class should provide the package attributes that register the GUID of the package, the file name extension that is used by files written in your language, and the language service features that are supported for your language.

  • A LanguageService class that inherits from the abstract BabelLanguageService class. This class should provide at least the GUID of the language service and implement the abstract method GetFormatFilterList to provide the file name extension that is used by files written in your language.

  • A Configuration partial class that defines the name of your language, the file name extension that is used by your language, and the colors that can be used by colorization. It should also map colors to tokens and provide a CommentInfo structure that defines how your language is commented.

  • A Resolver class that implements the IASTResolver interface that is provided by the Managed Babel source code. The IASTResolver methods are primarily used for the auto-completion and tooltip features.

Tokens

Tokens are the basis for all language definitions. They specify the keywords and special characters that are used by the language. The lexer file defines the tokens, and the parser file defines the token grammar, that is, the possible relationships among different tokens. The language service has to understand several aspects of tokens, for example, their colors and the kinds of actions they trigger.

The user-supplied Configuration.cs file associates types of tokens, for example, TokenType.Keyword or TokenType.Comment, with colors and token triggers. Triggers are defined to start specific kinds of processing when a given token occurs, for example, matching for the { and } characters, or displaying a list of properties and methods after a class name that is followed by a period.

See Also

Tasks

Walkthrough: Using Managed Babel

Change History

Date

History

Reason

July 2008

Rewrote and refactored project.

Content bug fix.