The different Syntax Highlighting schemes in 010 Editor can be controlled using the Syntax Options dialog. Access the Syntax Options dialog by clicking 'Tools > Options...' and selecting Syntax from the list of options.
A Syntax Highlight allows coloring of textual data according to a number of rules. When a rule is active, it applies colors to the data using a Style. Syntax Highlighting is applied to a file using the 'View > Highlighting > Syntax Highlighting' menu option. Note that the chosen Syntax Highlight is automatically remembered by the current File Interface. By default, 010 Editor contains Syntax Highlights for C/C++, 010 Editor Scripts/Templates, HTML, PHP and XML. 010 Editor also has File Interfaces which automatically apply the Syntax Highlights (for example, when loading a file with extension .html, that file is assigned the File Interface 'HTML' which then applies the HTML Syntax Highlight scheme).
The list of existing Syntax Highlights is located in a table at the top of the dialog. Create a new Syntax Highlight by clicking the New button or remove a Syntax Highlight by selecting it from the list and then clicking the Delete button. The Up and Down arrows beside the Syntax Highlight list can be used to reorder the Syntax Highlights.
Select a Syntax Highlight from the list to edit the name and the rules for that Highlight. Modify the name of the Syntax Highlight using the Name text field. How the highlighting is applied depends upon the rules listed in the Rules table. The rules are applied in order from top to bottom and the rules on top take precedence over the rules beneath. Create a new rule by clicking the '+' icon or delete the selected rule by clicking the 'X' icon. Rules can be moved up or down by clicking the Up and Down arrows above the Rules table.
Once a rule is selected in the Rules table, its details are displayed in the Rule Details area. The Rule Type drop-down list chooses how the rule is applied to characters and is discussed further below. Any text in a file that matches this rule will be coloring according the style chosen using the Style drop-down list. Using styles means that multiple rules can share the same style and see the Theme/Color Options dialog to edit the list of styles. Note that an icon indicating the foreground (text) and background color of the style is displayed on the Style drop-down list. The Keywords table lists a set of keywords, one per line. How the keywords function depends upon the type of rule being used:
- Multi-Line Block - This is the most flexible rule within the syntax highlighting rules. When the first keyword in the Keywords list is found in the file text, this rule is considered active. The rule will remain active until the second keyword in the Keywords list is found. Each following pair of keywords in the Keywords list can be used to indicate an alternate start and end keyword (i.e. the 1st, 3rd, 5th, etc. keywords indicate the starting markers and the 2nd, 4th, 6th, etc. keywords indicate the end markers). This rule can span multiple lines and can also be used as the parent rule for Sub-rules as discussed below.
- Single-Line Comment - If the text of the file matches any of the keywords in the list then this rule is active until the end of the current line. For example, this rule can be used to implement C++-style line comments with the keyword "//".
- Keywords - When using this type of rule, if any of the words in the Keywords list match the text of the file they will be colored according to the chosen style. For example, use this rule to color reserved words in C++ such as 'if', 'for', 'while', etc.
- Single-Line Block - This rule is considered active when the first keyword in the Keywords list is found in the text of the file and will end when the second keyword in the list is found or the end of the line is found. For example, use the keywords " and " to implement a regular single-line string. Multi-line strings can be implemented with the Multi-Line Block rule above. Each following pair of keywords in the Keywords list can be used as additional start and end delimiters for this rule.
- C-Style String - Similar to the Single-Line Block rule type except this properly handles escaped quotes (i.e. '\"') in strings as well as using '\' at the end of a line to create a multi-line string.
- Tag Name - This rule is used when highlighting XML or HTML tags. The first word found is highlighted according to this rule and the Keywords list is ignored.
- Tag Attribute - This rule is used when highlighting XML or HTML tags. Every word found except the first word is highlighted according to this rule. The Keywords list is ignored.
- Regular Expression - If any of the regular expressions listed in the Keywords match text in the file, the text will be coloring according to this rule. See Using Regular Expressions for more information on regular expressions. For example, use a regular expression of '\b[0-9]+\b' to applying coloring to numbers. Note that regular expressions that span multiple lines are currently not supported.
Enabling the Ignore Case toggle at the bottom of the dialog means that the keywords are case independent. Clicking the Reset button will restore all Syntax Highlights to their original values.
Importing and Exporting Syntax Highlights
The list of Syntax Highlights can be exported to a file by clicking the Export List... button. The exported file contains all the syntax highlighting rules and styles and will have the extension ".1hl". To import a list click the Import List... button and select a file. Next in the dialog that is displayed, select which Syntax Highlights to import and click the Import > button. If a Syntax Highlight is imported which already exists, it will overwrite the current rules for that Syntax Highlight. Any new styles contained in the file will be automatically added. If the imported file contains styles which have the same name as an existing style but different colors, you will asked whether to keep the original colors or accept the colors from the imported file.