Menu

Built-in Syntax Highlighters

Built-in Syntax Highlighters

The CodeXCavator application supports the following built-in syntax highlighters:

RegexHighlighter

The RegexHighlighter highlights source code elements by using regular expression patterns. You can specify an arbitrary number of element types, which should be highlighted. For each element type a regular expression pattern must be provided and the text foreground color, which should be used for highlighting.

  • Use a <configuration></configuration> tag below the <highlighter></highlighter> element in order to configure the syntax highlighter
    • You can use the boolean CaseSensitive attribute, in order to specify, whether the patterns are case-sensitive ( attribute value "True" ) or not ( attribute value "False" ).
  • Put a <patterns></patterns> tag below the <configuration></configuration> tag in order to specify a list of token patterns.
  • Put as many <pattern></pattern> tags below the <patterns></patterns> tag as needed.
    • Use the Token attribute in order to specify the name of the token type. Some token types are treated in a special manner by the highlighter.
    • Use the RegEx attribute in order to specify a regular expression for the token. The .NET regular expression syntax is used.
    • Use the Color attribute in order to specify a color, which should be used for highlighting the token.
      The color must be specified as a 32-bit hexadecimal number in the ARGB including a leading # character. ( i.e. #FFFFFFFF corresponds to white ).
  • The order of the token pattern elements also defines a highlighting priority, which means, that if multiple patterns are matched, the pattern which comes first in the pattern list is used for highlighting.

Example: Using and configuring the RegexHighlighter

  <Highlighter Type="RegexHighlighter" FileExtensions=".xml">
    <Configuration CaseSensitive="true">
      <Patterns>
        <Pattern Token="COMMENT_START" RegEx="&lt;\!\-\-" Color="#ff808080"/>
        <Pattern Token="COMMENT_END" RegEx="\-\-&gt;" Color="#ff808080"/>
        <Pattern Token="XML_TAG_START" RegEx="&lt;/|&lt;\?|&lt;" Color="#ff0000ff"/>
        <Pattern Token="XML_TAG_END" RegEx="/&gt;|\?&gt;|&gt;" Color="#ff0000ff"/>
        <Pattern Token="XML_ATTRIBUTE" RegEx="[a-zA-Z_0-9_-]+\s*\=" Color="#ffff0000"/>
        <Pattern Token="XML_ATTRIBUTE_VALUE" RegEx="@\&quot;(?:\&quot;\&quot;|[^\&quot;\r\n])*\&quot;|\&quot;(?:\\.|[^\\\&quot;\r\n])*\&quot;" Color="#ffff00ff"/>
        <Pattenr Token="XML_NAMESPACE_DECL" RegEx="xmlns:" Color="#ff0080ff"/>
        <Pattern Token="TAG" RegEx="\+\#[_a-zA-Z][a-zA-Z_0-9\.]*\#\+" Color="#ffff8000"/>
      </Patterns>
    </Configuration>
  </Highlighter>

Special token types

The RegexHighlighter treats the following token types in a special manner

  • KEYWORD and IDENTIFIER:
    Keyword and identifier tokens are treated specially. As patterns for identifiers are often more general than patterns for keywords, they might include keywords a substrings, which would lead to broken highlighting. In this case if a string simultanously matches a keyword and an identifier the keyword is only highlighted if it is not a part of the matched identifier.

  • COMMENT_START and COMMENT_END:
    The comment start and comment end token types are used for highlighting multiline block comments. In this case the color specified with the COMMENT_START pattern is used for highlighting. While the highlighter is highlighting a block comment, all other highlighter patterns are ignored except for the tag pattern.

  • LINE_COMMENT:
    The line comment token type is used for highlighting single line comments. While the highlighter is highlighting a line comment, all other highlighter patterns are ignored except for the tag pattern.

  • TAG:
    The tag token type is used for highlighting tags contained in source code comments.

[Home][Extensibility]


Related

Wiki: Extensibility
Wiki: Home