Next: Defining text aliases, Previous: Defining new search patterns, Up: Customizing through XML and Python files
You can define new languages in a custom file by using the Language
tag. Defining languages gives GPS the ability to highlight the syntax of a
file, explore a file (using e.g. the project view), find files
associated with a given language, ...
As described previously for menu items, any file in the plug-ins directory will be loaded by GPS at start up. Therefore, you can either define new languages in a separate file, or reuse a file where you already define actions and menus.
The following tags are available in a Language section:
NameParentAda, C++) or
another custom language, this language will inherit by default all its
properties from this language. Any field explicitly defined for this language
will override the inherited settings.
Spec_SuffixExtension tag instead.
This tag must be unique.
Body_SuffixSpec_Suffix, so that the user
can choose to easily go from one file to the other.
This tag must be unique.
ExtensionKeywordsKeywords tags can be specified, and will be concatenated
into a single regular expression. If the regular expression needs to match
characters other than letters and underscore, you must also edit the
Wordchars node. If a parent language has been specified for the
current language definition it is possible to append to the parent Keywords
by setting the mode attribute to append, the default value is
override meaning that the keywords definition will replace the
parent's one.
The full grammar of the regular expression can be found in the spec of the
file g-regpat.ads in the GNAT run time.
WordcharsEngineThe name can be a full pathname, or a short name. E.g. under most Unix systems
if you specify custom, GPS will look for libcustom.so in
the LD_LIBRARY_PATH run time search path. You can also specify
explicitly e.g. libcustom.so or /usr/lib/libcustom.so.
For each of the following five items, GPS will look for the corresponding
symbol in Engine and if found, will call this symbol when needed.
Otherwise, it will default to the static behavior, as defined by the other
language-related items describing a language.
You will find the required specification for the C and Ada languages
to implement the following functions in the directory
<prefix>/share/examples/gps/language of your GPS installation.
language_custom.ads is the Ada spec file; language_custom.h is
the C spec file; gpr_custom.ad? are example files showing a possible Ada
implementation of the function Comment_Line
for the GPS project files (.gpr files), or any other Ada-like language;
gprcustom.c is the C version of gpr_custom.adb.
Comment_LineEdit->Un/Comment Lines).
Parse_ConstructsThis procedure is used by GPS to implement several capabilities such as
listing constructs in the project view, highlighting the current block of
code, going to the next or previous procedure, ...
Format_BufferThis procedure is used to implement the auto indentation when hitting the
<enter> key, or when using the format key on the current selection or
the current line.
Parse_EntitiesContext node described below.
ContextComment_StartComment_EndNew_Line_Comment_Start;|# for comments starting
after a semicolon or after the hash sign. If a parent language has been
specified for the current language definition it is possible to append
to the parent New_Line_Comment_Start by setting the mode attribute to
append, the default value is override meaning that the
New_Line_Comment_Start definition will replace the parent's one.
String_DelimiterQuote_Character\ in C).
Constant_CharacterCan_IndentSyntax_HighlightingCase_SensitiveCategoriesCategory nodes,
each describing the characteristics of a given category, with the following
nodes:
NamePatternKeywords node, multiple Pattern tags can be
specified and will be concatenated into a single regular expression.
IndexEnd_IndexIconHere is an example of a possible language definition for the GPS project files:
<?xml version="1.0"?>
<Custom>
<Language>
<Name>Project File</Name>
<Spec_Suffix>.gpr</Spec_Suffix>
<Keywords>^(case|e(nd|xte(nds|rnal))|for|is|</Keywords>
<Keywords>limited|null|others|</Keywords>
<Keywords>p(ackage|roject)|renames|type|use|w(hen|ith))\b</Keywords>
<Context>
<New_Line_Comment_Start>--</New_Line_Comment_Start>
<String_Delimiter>"</String_Delimiter>
<Constant_Character>'</Constant_Character>
<Can_Indent>True</Can_Indent>
<Syntax_Highlighting>True</Syntax_Highlighting>
<Case_Sensitive>False</Case_Sensitive>
</Context>
<Categories>
<Category>
<Name>package</Name>
<Pattern>^[ \t]*package[ \t]+((\w|\.)+)</Pattern>
<Index>1</Index>
</Category>
<Category>
<Name>type</Name>
<Pattern>^[ \t]*type[ \t]+(\w+)</Pattern>
<Index>1</Index>
</Category>
</Categories>
<Engine>gpr</Engine>
<Comment_Line>gpr_comment_line</Comment_Line>
</Language>
</Custom>