Language Sugars add support for new coding languages to Espresso, or less often modify or extend the language support for another Sugar.
Espresso generates the syntax zones that make up a document using regular expressions defined in syntax definitions within language Sugars.
Defining a new syntax for Espresso can involve several files and folders:
- Languages.xml: this file defines the rules that determine when your syntax will be used to interpret a document (typically based on file extensions)
- Syntaxes/: the XML file(s) in this folder contain the regex that Espresso uses to parse a document into syntax zones
- SyntaxInjections/: the XML file(s) in this folder define syntax zones to inject into pre-existing syntaxes (see Syntaxes for documentation)
- Itemizers/: the XML file(s) in this folder define how to logically group the syntax zones for your language into larger chunks that can be folded or browsed in the Navigator
- PlaceholderThemes/: the CSS file in this folder is used to add default syntax colors for your new language. See SyntaxThemes for documentation
- ContextualSettings/: the XML files in this folder define language-specific settings for various actions (typically used to customize Espresso’s automatic commenting action, but can be leveraged by other actions, as well)
Language Sugar checklist
Although some of these can be done in a different order, these are generally the steps to creating a language Sugar:
- Create a basic Sugar (download basic Sugar template or find more info in SugarStructure)
- Create a Languages.xml file and populate it with basic details for your language
- Create a Syntaxes folder, and start defining your basic syntax zone regex
While working on the syntax zones, you will want to have an example document open so you can make sure that everything is working the way you expect (use the Syntax Inspector to verify). Remember that XML changes to your Sugar require restarting Espresso before you can see the changes!
Once you are happy with the basics of your syntax definition, you can implement Itemizers if you are so inclined, and a placeholder theme. If your language uses non-standard comments, you can define them with ContextualSettings.
Typically you will also want to implement CodeSense in your language Sugar, as well.