Home
Categories
Dictionary
Download
Project Details
Changes Log
License

Adding a syntax pack



It is possible to support other syntaxes by calling the SyntaxMapper.installSyntaxPack(URL, boolean) method. The URL must point to a Jar file.

Structure of the jar file

The URL must be a jar file with a manifest with either:
  • The jEditor-def attribute which identifies the XML file describing each syntax
  • The two following attributes:
    • jEditor-extensions: identifies the name of the syntax syntax for each extension
    • jEditor-type: identifies the class which implements the syntax highlighting for each syntax. This class must extend the TokenMarker class

Structure of the jEditor-def XML file

See the XML file grammar.

The XML file contains a list of file elements, which contain:
  • A name attribute for the syntax name
  • A path attribute for the syntax TokenMarker class
  • An optional extension attribute for the syntax extension
  • An optional type attribute for the syntax type[1]
    The valid types are: markup, code, shell, text
    . The syntax types are specified by the SyntaxType interface
  • An optional list of altname children elements if the syntax has more than one name
  • An optional list of extension children elements if the syntax has more than one extension

Example

For a Java syntax:
     <file name="java" extension="java" path="org.jeditor.scripts.tokenmarkers.JavaTokenMarker" type="code" />
For a HTML syntax:
      <file name="html" path="org.jeditor.scripts.tokenmarkers.HTMLTokenMarker" type="markup">
         <extension extension="html" />
         <extension extension="htm" />
      </file>

Second example with alternate names

For a C++ syntax:
      <file name="c++" path="org.jeditor.scripts.tokenmarkers.CCTokenMarker" type="code">
         <altName name="cpp" />
         <extension extension="cpp" />
         <extension extension="cc" />
         <extension extension="hpp" />
      </file>
In that case, you can name your syntax either c++ or cpp, and the file can have one of the following extensions: cpp, cc, or hpp.

Structure of the extensions and types properties files

There are two properties files:
  • The file specified by the jEditor-type attribute identifies the path of the class which implements the syntax highlighting for each syntax. This class must extend the TokenMarker class
  • The file specified by the jEditor-extensionsatttribute identifies the name of the syntax for each extension
Note that in this case the Syntax.getSyntaxType() will always return the SyntaxType.UNDEF value.

Example for a HTML syntax

For the file specified by the jEditor-type attribute:
      html=org.jeditor.scripts.tokenmarkers.HTMLTokenMarker
For the file specified by the jEditor-extensions attribute:
      html=html
      htm=htm

Built-in syntax pack

The jEditor-syntaxes.jar jar file, released with the library, provides syntaxes for the following languages:
  • povray
  • Ruby
  • Groovy: note that this Groovy syntax replaces the default one, which uses a Java syntax

Example

We use for example the built-in syntax-pack.

Example with the jEditor-def attribute

We have the following manifest:
      jEditor-def: org/jeditor/scripts/pack/filetypes.xml      
For the filetypes.xml file:
      <fileTypes>
         <file name="povray" extension="pov" path="org.jeditor.scripts.pack.PovrayTokenMarker" type="code" />
         <file name="ruby" extension="rb" path="org.jeditor.scripts.pack.RubyTokenMarker" type="code" />
         <file name="groovy" path="org.jeditor.scripts.pack.GroovyTokenMarker" type="code">
            <extension extension="groovy" />
            <extension extension="gvy" /> 
            <extension extension="gy" />        
            <extension extension="gsh" />           
         </file>
      </fileTypes>

Example with the jEditor-extensions and jEditor-type attributes

We have the following manifest:
      jEditor-extensions: org/jeditor/scripts/pack/fileextensionpack.properties
      jEditor-type: org/jeditor/scripts/pack/filetypepack.properties      
For the fileextensionpack.properties file:
      pov=povray
      rb=ruby
      groovy=groovy
For the filetypepack.properties file:
      povray=org.jeditor.scripts.pack.PovrayTokenMarker
      ruby=org.jeditor.scripts.pack.RubyTokenMarker
      groovy=org.jeditor.scripts.pack.GroovyTokenMarker

Notes

  1. ^ The valid types are: markup, code, shell, text

Categories: syntax

Copyright 2016-2019 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence