Syntax languages are objects that can be assigned to any ICode
The ISyntaxLanguage Interface (Service Locator Architecture)
The ISyntax
The service locator design pattern is somewhat like a dictionary object. Any object can be assigned as a "service" to the language using a Type
-based key. There are a number of built-in feature service types that the text/parsing framework and products like SyntaxEditor look for, such as ILexer, ILine
Note
A complete list of the built-in service types, along with a more in-depth look at how the service locator architecture works, is given in the Service Locator Architecture topic.
A Real Service Type Example
Each one of these services provide some functionality that can be requested at any time. As a real example, say we have created an IText
Thus, via the use of the service locator architecture, we can register (or customize) built-in functionality for a particular language.
A Custom Service Type Example
Any custom service types can be registered too.
Say you made a service that returns an object which has a method indicating if a passed filename is supported by the language. If our language was Java and the passed filename had a .java extension, we'd return true
.
You could register similar functionality on all the languages you use and publish this service as a type called IFilenameSupported
. Then in your application where you maintained a list of available languages, when a file was opened you could enumerate your list of languages, get the IFilenameSupported
service, pass the filename to its method, and see if true
was returned. When you encounter a true
return value, you know that language supports the file.
Creating, Loading, and Using a Language
The Language Creation Guide has topics that cover how to create, load, and use syntax languages. It also goes into detail about the service locator architecture, event sinks, the available built-in service types, and more.
In addition, we provide a Language Designer application that makes it easy to get started building a custom syntax language. That tool lets you configure information about your language and then it generates language-related code that can be used in your applications. With the application's help, you can be up and running in a few minutes.
Notification of Document Language Changes
The ICode
Reusing Language Instances
It is encouraged to reuse ISyntaxSyntaxEditor
control and your IDE edits XML documents, load your XML syntax language one time and apply the same instance to each document. This saves on memory and reduces load time.