Chapter 11. Mode Definition Syntax

Table of Contents

11.1. An XML Primer
11.2. The Preamble and MODE tag
11.3. The PROPS Tag
11.4. The RULES Tag
11.4.1. Highlighting Numbers
11.4.2. Rule Ordering Requirements
11.4.3. Per-Ruleset Properties
11.5. The TERMINATE Tag
11.6. The SPAN Tag
11.7. The SPAN_REGEXP Tag
11.8. The EOL_SPAN Tag
11.9. The EOL_SPAN_REGEXP Tag
11.10. The MARK_PREVIOUS Tag
11.11. The MARK_FOLLOWING Tag
11.12. The SEQ Tag
11.13. The SEQ_REGEXP Tag
11.14. The IMPORT Tag
11.15. The KEYWORDS Tag
11.16. Token Types
11.17. The MATCH_TYPE Attribute

Edit modes are defined using XML, the eXtensible Markup Language; mode files have the extension .xml. XML is a very simple language, and as a result edit modes are easy to create and modify. This section will start with a short XML primer, followed by detailed information about each supported tag and highlighting rule.

Editing a mode or a mode catalog file within jEdit will cause the changes to take effect immediately. If you edit modes using another application, the changes will take effect after the Utilities > Troubleshooting > Reload Edit Modes command is invoked.

11.1. An XML Primer

A very simple XML file (which also happens to be an edit mode) looks like so:

<?xml version="1.0"?>

<!DOCTYPE MODE SYSTEM "xmode.dtd">

<MODE>
    <PROPS>
        <PROPERTY NAME="commentStart" VALUE="/*" />
        <PROPERTY NAME="commentEnd" VALUE="*/" />
    </PROPS>

    <RULES>
        <SPAN TYPE="COMMENT1">
            <BEGIN>/*</BEGIN>
            <END>*/</END>
        </SPAN>
    </RULES>
</MODE>

Note that each opening tag must have a corresponding closing tag. If there is nothing between the opening and closing tags, for example <TAG></TAG>, the shorthand notation <TAG /> may be used. An example of this shorthand can be seen in the <PROPERTY> tags above.

Validation and Errors

Most XML file formats have a formal grammar specified in either DTD, XSD or RNG. In the example above, we can see that the DOCTYPE, or formal grammar for jEdit mode files is described in xmode.dtd, which happens to come from jEdit's source code. If you install the XML plugin, and while editing a mode file in jEdit, go to Plugins - XML - Parse as XML, you should see a structure tree in Sidekick, and you will also see errors (if there are any) in ErrorList, if the document does not conform to the proper XML syntax or the document's formal grammar. In addition, the XML plugin provides completion tips for elements and attributes. All of these things can help immensely especially when learning XML.

It is highly recommended that you check your XML files for validation errors before submitting them to the community.

XML is case sensitive. Span or span is not the same as SPAN.

To insert a special character such as < or > literally in XML (for example, inside an attribute value), you must write it as an entity. An entity consists of the character's symbolic name enclosed within & and ;. The most frequently used entities are:

  • &lt; - The less-than (<) character

  • &gt; - The greater-than (>) character

  • &amp; - The ampersand (&) character

For example, the following will cause a syntax error:

<SEQ TYPE="OPERATOR">&</SEQ>

Instead, you must write:

<SEQ TYPE="OPERATOR">&amp;</SEQ>

Now that the basics of XML have been covered, the rest of this section will cover each construct in detail.