1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
|
<refentry id="lang-reference" revision="25 December 2006">
<refmeta>
<refentrytitle>Language Definition v2.0 Reference</refentrytitle>
</refmeta>
<refnamediv>
<refname>Language Definition v2.0 Reference</refname>
<refpurpose>
Reference to the GtkSourceView language definition file format
</refpurpose>
</refnamediv>
<refsect1>
<title>Overview</title>
<para>
This is an overview of the Language Definition XML format, describing the
meaning and usage of every element and attribute. The formal definition is
stored in the RelaxNG schema file <filename>language2.rng</filename> which
should be installed on your system in the directory
<filename>${PREFIX}/share/gtksourceview-2.0/</filename> (where
<filename>${PREFIX}</filename> can be <filename>/usr/</filename> or
<filename>/usr/local/</filename> if you have installed from source.
</para>
</refsect1>
<refsect1>
<title>Tag <code><language></code></title>
<para>
The root element for Language Definition files.
</para>
<para>
Contained elements:
<simplelist type="inline">
<member><code><metadata></code> (optional)</member>
<member><code><styles></code> (optional)</member>
<member><code><default-regex-options></code> (optional)</member>
<member><code><keyword-char-class></code> (optional)</member>
<member><code><definitions></code> (mandatory)</member>
</simplelist>.
</para>
<variablelist>
<title>Attributes:</title>
<varlistentry>
<term><code>id</code> (mandatory)</term>
<listitem><para>
Identifier for the description. This is used for
external references and must be unique among language descriptions. It can
contain a string of letters, digits, hyphens ("<code>-</code>") and
underscores ("<code>_</code>").
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>name</code> (mandatory)</term>
<listitem><para>
The translatable name of the language presented to the user.
It can be marked for translation putting an underscore before the attribute
name (see the gettext documentation).
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>version</code> (mandatory)</term>
<listitem><para>
The version of the XML format (currently "2.0").
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>section</code> (optional)</term>
<listitem><para>
The translatable category in which the language has to be grouped when
presented to the user. It can be marked for translation putting
an underscore before the attribute name. Currently used categories in
GtkSourceView are "Sources", "Scripts", "Markup" and "Others", but
it is possible to use arbitrary categories (while usually discouraged).
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>hidden</code> (optional)</term>
<listitem><para>
It's a hint that the language should be "hidden" from user. For instance,
def.lang has this flag, and a text editor should not present "default" as
a syntax highlighting choice.
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Tag <code><metadata></code></title>
<para>
Contains optional metadata about the language definition.
</para>
<para>
Recognized elements are (all optional):
</para>
<varlistentry>
<term><code>mimetypes</code></term>
<listitem><para>
The semicolon-separated list of mimetypes associated to the language.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>globs</code></term>
<listitem><para>
The semicolon-separated list of globs associated to the language.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>line-comment-start</code></term>
<listitem><para>
String used to create single-line comment in files of this type, e.g.
"#" in shell scripts.
It may be used in an editor to implement Comment/Uncomment functionality.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>block-comment-start</code></term>
<listitem><para>
String used to start block comment in files of this type, e.g. "/*" in C
files.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>block-comment-end</code></term>
<listitem><para>
String used to end block comment in files of this type, e.g. "*/" in C
files.
</para></listitem>
</varlistentry>
</refsect1>
<refsect1>
<title>Tag <code><styles></code></title>
<para>
Contains the definitions of every style used in the current language and
their association with predefined styles in GtkSourceView.
</para>
<para>
Contained elements:
<simplelist type="inline">
<member><code><style></code> (one or more)</member>
</simplelist>.
</para>
</refsect1>
<refsect1>
<title>Tag <code><style></code></title>
<para>
Defines a style, associating it's id with a user visible translatable
name and a default style.
</para>
<para>
Contained elements: none.
</para>
<variablelist>
<title>Attributes:</title>
<varlistentry>
<term><code>id</code> (mandatory)</term>
<listitem><para>
Identifier for the style. This is used in the current language
to refer to this style and must be unique for the current document.
It can contain a string of letters, digits,
hyphens ("<code>-</code>") and underscores ("<code>_</code>").
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>name</code> (mandatory)</term>
<listitem><para>
The user visible translatable name for the style. It has to be preceded
with a underscore ("<code>_</code>") to be marked for translation.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>map-to</code> (optional)</term>
<listitem><para>
Used to map the style with a default style, to use colors and
font properties defined for those default styles.
The id of the default style has to be preceded with the id of the
language where it is defined, separated with a semicolon ":".
When omitted the style is not considered derived from any style and will
be not highlighted until the user specifies a color scheme for this
style.
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Tag <code><keyword-char-class></code></title>
<para>
Contains a regex character class used to redefine the customizable
word boundary delimiters "\%[" and "\%]". This class is the set of character
that can be commonly found in a keyword.
If the element is omitted the two delimiters default to "\b".
</para>
<para>
Contained elements: none.
</para>
</refsect1>
<refsect1>
<title>Tag <code><default-regex-options></code></title>
<para>
Used to set global options for how regular expressions are processed.
</para>
<para>
Contained elements: none.
</para>
<variablelist>
<title>Attributes</title>
<varlistentry>
<term><code>case-sensitive</code> (optional)</term>
<listitem><para>Set to <code>false</code> to make regular expressions
ignore case.
Defaults to <code>true</code>.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>extended</code> (optional)</term>
<listitem><para>Setting this to <code>true</code> makes the regular
expression engine ignore spaces and comments. These comments start with
"<code>#</code>" and continue to the end of the line.
Defaults to <code>false</code>.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>dupnames</code> (optional)</term>
<listitem><para>Setting this to true allows one to repeat an identifier
for capturing parentheses. This is useful for some patterns that you
know only one instance of a named subpattern can ever be matched.
Defaults to <code>false</code>.
</para></listitem>
</varlistentry>
</variablelist>
<para>
Contained elements: none.
</para>
</refsect1>
<refsect1>
<title>Tag <code><definitions></code></title>
<para>
The element containing the real description of the syntax to be
highlighted. It contains one or more <code><context></code> element and an
arbitrary number of <code><define-regex></code> elements, interleaved.
It has no attributes.
Every contained element must have its <code>id</code> attribute set to an
identifier unique for the document. Exactly one of the contained
<code><context></code> element must have
the <code>id</code> attribute set to the <code>id</code> of the
<code><language></code> root element,
representing the initial context for the highlighting, the one the engine
enters at the beginning of the highlighted file.
</para>
<para>
Contained elements:
<simplelist type="inline">
<member><code><context></code> (one or more)</member>
<member><code><define-regex></code> (zero or more)</member>
</simplelist>.
</para>
</refsect1>
<refsect1>
<title>Tag <code><define-regex></code></title>
<para>
Defines a regular expression that can be reused inside other regular
expression, to avoid replicating common portions. Those regular
expressions are PCRE regular expressions in the form <code>/regex/options</code> (see
the documentation of PCRE for details). If there are no options to be
specified and you don't need to match the spaces at the start and at the
end of the regular expression, you can omit the slashes, putting here only
<code>regex</code>. The possible options are those specified above in the description
of the <code><default-regex-options></code> element. To disable a group of
options, instead, you have to prepend an hyphen <code>-</code> to them. In
GtkSourceView are also available some extensions to the standard Perl style
regular expressions:
</para>
<itemizedlist>
<listitem><para>
<code>\%[</code> and <code>\%]</code> are custom word boundaries, which can
be redefined with the <code><keyword-char-class></code> (in contrast with
<code>\b</code>);
</para></listitem>
<listitem><para>
<code>\%{id}</code> will include the regular expression defined in another
<code><define-regex></code> element with the specified id.
</para></listitem>
</itemizedlist>
<para>
Contained elements: none.
</para>
<variablelist>
<title>Attributes:</title>
<varlistentry>
<term><code>id</code> (mandatory)</term>
<listitem><para>
Identifier for the regular expression. This is used
for the inclusion of the defined regular expression and must be unique
for the current document. It can contain a string of letters, digits,
hyphens ("<code>-</code>") and underscores ("<code>_</code>").
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Tag <code><context></code></title>
<para>
This is the most important element when describing the syntax: the file to
be highlighted is partitioned in contexts representing the portions to be
colored differently. Contexts can also contain other contexts.
There are different kind of context elements: simple contexts, container
contexts, sub-pattern contexts, reference contexts and keyword contexts.
</para>
<refsect2>
<title>Simple contexts</title>
They contain a mandatory <code><match></code> element and an optional
<code><include></code> element. The context will span over the strings
matched by the regular expression contained in the <code><match></code>
element. In the <code><include></code> element you
can only put sub-pattern contexts.
<para>
Contained elements:
<simplelist type="inline">
<member><code><match></code> (mandatory)</member>
</simplelist>.
</para>
<variablelist>
<title>Attributes:</title>
<varlistentry>
<term><code>id</code> (optional)</term>
<listitem><para>
A unique identifier for the context, used in references to the context. It
can contain a string of letters, digits, hyphens ("<code>-</code>") and
underscores ("<code>_</code>").
</para></listitem></varlistentry>
<varlistentry>
<term><code>style-ref</code> (optional)</term>
<listitem><para>
Highlighting style for this context. Value of this attribute
may be id of a style defined in current lang file, or id of a style
defined in other files prefixed with corresponding language id,
e.g. "def:comment".
</para></listitem></varlistentry>
<varlistentry>
<term><code>extend-parent</code> (optional)</term>
<listitem><para>
A boolean value telling the engine whether the context has higher
priority than the end of its parent. If not specified it defaults to
<code>true</code>.
</para></listitem></varlistentry>
<varlistentry>
<term><code>end-parent</code> (optional)</term>
<listitem><para>
A boolean value telling the engine whether the context terminates parent context.
If not specified it defaults to <code>false</code>.
</para></listitem></varlistentry>
<varlistentry>
<term><code>first-line-only</code> (optional)</term>
<listitem><para>
A boolean value telling the engine whether the context can occur only
on the first line of buffer. If not specified it defaults to <code>false</code>.
</para></listitem></varlistentry>
<varlistentry>
<term><code>once-only</code> (optional)</term>
<listitem><para>
A boolean value telling the engine whether the context can occur only
once in its parent. If not specified it defaults to <code>false</code>.
</para></listitem></varlistentry>
</variablelist>
</refsect2>
<refsect2>
<title>Container contexts</title>
They contain a <code><start></code> element and an optional
<code><end></code>. They respectively contain the regular
expression that makes the engine enter in the context and the terminating one.
In the optional <code><include></code> element you can put contained
contexts of every type (simple, container, sub-pattern or reference).
If the <code><start></code> element is omitted, then the
<code>id</code> attribute and the <code><include></code> become
mandatory (the context can only be used as a container to include
its children).
<para>
Contained elements:
<simplelist type="inline">
<member><code><start></code> (optional)</member>
<member><code><end></code> (optional)</member>
<member><code><include></code> (optional)</member>
</simplelist>.
</para>
<variablelist>
<title>Attributes:</title>
<varlistentry>
<term><code>id</code> (mandatory only if <code><start></code> not present)</term>
<listitem><para>
A unique identifier for the context, used in references to the context. It
can contain a string of letters, digits, hyphens ("<code>-</code>") and
underscores ("<code>_</code>").
</para></listitem></varlistentry>
<varlistentry>
<term><code>style-ref</code> (optional)</term>
<listitem><para>
Highlighting style for this context. Value of this attribute
may be id of a style defined in current lang file, or id of a style
defined in other files prefixed with corresponding language id,
e.g. "def:comment".
</para></listitem></varlistentry>
<varlistentry>
<term><code>style-inside</code> (optional)</term>
<listitem><para>
If this attribute is "true", then the highlighting style will
be applied to the area between start and end matches; otherwise
whole context will be highlighted.
</para></listitem></varlistentry>
<varlistentry>
<term><code>extend-parent</code> (optional)</term>
<listitem><para>
A boolean value telling the engine whether the context has a higher
priority than the end of he parent. If not specified it defaults to
<code>true</code>.
</para></listitem></varlistentry>
<varlistentry>
<term><code>end-at-line-end</code> (optional)</term>
<listitem><para>
A boolean value telling the engine whether the context must be forced
to end at the end of the line, displaying an error ???? XXX. If not specified
it defaults to <code>false</code>.
</para></listitem></varlistentry>
<varlistentry>
<term><code>end-parent</code> (optional)</term>
<listitem><para>
A boolean value telling the engine whether the context terminates parent context
when it ends.
If not specified it defaults to <code>false</code>.
</para></listitem></varlistentry>
<varlistentry>
<term><code>first-line-only</code> (optional)</term>
<listitem><para>
A boolean value telling the engine whether the context can start only
on the first line of buffer. If not specified it defaults to <code>false</code>.
</para></listitem></varlistentry>
<varlistentry>
<term><code>once-only</code> (optional)</term>
<listitem><para>
A boolean value telling the engine whether the context can occur only
once in its parent. If not specified it defaults to <code>false</code>.
</para></listitem></varlistentry>
</variablelist>
</refsect2>
<refsect2>
<title>Sub-pattern contexts</title>
<para>
They refer to a group in a regular expression of the parent context, so it
is possible to highlight differently only a portion of the matched regular
expression.
</para>
<para>
Contained elements: none.
</para>
<variablelist>
<title>Attributes:</title>
<varlistentry>
<term><code>id</code> (optional)</term>
<listitem><para>
A unique identifier for the context. It can contain a string of letters,
digits, hyphens ("<code>-</code>") and underscores ("<code>_</code>").
</para></listitem></varlistentry>
<varlistentry>
<term><code>sub-pattern</code> (mandatory)</term>
<listitem><para>
The sub-pattern to which we refer. "0" means the whole expression, "1" the
first group, "2" the second one, etc. If named sub-patterns are used you can
also use the name.
</para></listitem></varlistentry>
<varlistentry>
<term><code>where</code> (mandatory only in container contexts)</term>
<listitem><para>
Can be "<code>start</code>" or "<code>end</code>". It has to be used
only if the parent is a container context to specify whether the
sub-pattern is in the regular
expression of the <code><start></code> or the <code><end></code>
element. In simple contexts it must be omitted.
</para></listitem></varlistentry>
</variablelist>
</refsect2>
<refsect2>
<title>Reference contexts</title>
<para>
Used to include a previously defined context.
</para>
<para>
Contained elements: none.
</para>
<variablelist>
<title>Attributes:</title>
<varlistentry>
<term><code>ref</code> (mandatory)</term>
<listitem><para>
The id of the context to be included. A colon followed by an asterisk
("<code>:*</code>") at the end of the id means that the parent should include
every children of the specified context, instead of the context itself.
Prepending the id of another language to the id of the context (separated
with a semicolon ":") is possible to include contexts defined inside such
external language.
</para></listitem></varlistentry>
<varlistentry>
<term><code>style-ref</code> (optional)</term>
<listitem><para>
Style in included context may be overridden by using this attribute.
Its value is id of the style to be used instead of style specified
in the referenced context.
</para></listitem></varlistentry>
<varlistentry>
<term><code>ignore-style</code> (optional)</term>
<listitem><para>
If this attribute it "true" then the referenced context will not
be highlighted. It does not affect child contexts and their styles.
</para></listitem></varlistentry>
</variablelist>
</refsect2>
<refsect2>
<title>Keyword contexts</title>
<para>
They contain a list of <code><keyword></code> and matches every keyword
listed. You can also put a <code><prefix></code> and/or a
<code><suffix></code> common to every keyword.
</para>
<para>
Note that keywords are matched in the order they are listed, so if you
have both a keyword "foo" and a keyword "foobar", you should always list
foobar before foo, or it will never be matched.
</para>
<para>
Contained elements:
<simplelist type="inline">
<member><code><prefix></code> (optional)</member>
<member><code><suffix></code> (optional)</member>
<member><code><keyword></code> (one or more)</member>
</simplelist>.
</para>
<para>
The attributes are the same used in simple contexts.
</para>
</refsect2>
</refsect1>
<refsect1>
<title>Tag <code><include></code></title>
<para>
Contains the list of context contained in the current
<code><context></code>.
</para>
<para>
Contained elements:
<simplelist type="inline">
<member><code><context></code> (one or more)</member>
<member><code><define-regex></code> (zero or more)</member>
</simplelist>.
</para>
</refsect1>
<refsect1>
<title>Tag <code><match></code></title>
<para>
Contains the regular expression for the current simple context.
The expression is in the same form used in
<code><define-regex></code> elements.
It is allowed to use any of the attributes from
<code><default-regex-opts></code> as attributes of this tag.
</para>
<para>
Contained elements: none.
</para>
</refsect1>
<refsect1>
<title>Tag <code><start></code></title>
<para>
Contains the starting regular expression for the current container context.
The expression is in the same form used in <code><define-regex></code>
elements.
It is allowed to use any of the attributes from
<code><default-regex-opts></code> as attributes of this tag.
</para>
<para>
Contained elements: none.
</para>
</refsect1>
<refsect1>
<title>Tag <code><end></code></title>
<para>
Contains the terminating regular expression for the current container
context. The expression is in the same form used in <code><define-regex></code>
elements, with an extension: <code>\%{sub-pattern@start}</code> will be
substituted with the string matched in the corresponding sub-pattern
(can be a number or a name if named sub-patterns are used) in the
preceding <code><start></code> element. For instance you could
implement shell-style here-documents with this code:
</para>
<programlisting>
<context id="here-doc">
<start>&lt;&lt;\s*(\S+)$</start>
<end>^\%{1@start}$</end>
</context>
</programlisting>
<para>
It is also possible to use any of the attributes from
<code><default-regex-opts></code> as attributes of this tag.
</para>
<para>
Contained elements: none.
</para>
</refsect1>
<refsect1>
<title>Tag <code><keyword></code></title>
<para>
Contains a keyword to be matched by the current context. The keyword is a
regular expression in the form used in <code><define-regex></code>.
</para>
<para>
Contained elements: none.
</para>
</refsect1>
<refsect1>
<title>Tag <code><prefix></code></title>
<para>
Contains a prefix common to all of the following keywords in the current
context. The prefix is a regular expression in the form used in
<code><define-regex></code>. If not specified it defaults to
<code>\%[</code>
</para>
<para>
Contained elements: none.
</para>
</refsect1>
<refsect1>
<title>Tag <code><suffix></code></title>
<para>
Contains a suffix common to all of the following keywords in the current
context. The suffix is a regular expression in the form used in
<code><define-regex></code>. If not specified it defaults to
<code>\%]</code>
</para>
<para>
Contained elements: none.
</para>
</refsect1>
<refsect1>
<title>Tag <code><replace></code></title>
<para>
The replace tag allows you to change one context so it functions as
another context. For example, in the <code>html.lang</code> definition,
there are a few references to a null context with id
"<code>external</code>". In <code>php.lang</code>, that context is
replaced like this: <code><replace id="html:external"
ref="php-block"></code>, so that php blocks are recognized within the
<code>html:html</code> context at the points where the
<code>external</code> context appears.
</para>
<para>
Contained elements: none.
</para>
<variablelist>
<title>Attributes:</title>
<varlistentry>
<term><code>id</code> (mandatory)</term>
<listitem><para>
The id of the context to replace. Ex: <code>id="html:external"</code>
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>ref</code> (mandatory)</term>
<listitem><para>
The id of the context to put in place of the context being replaced. Ex: <code>ref="php-block"</code>
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
</refentry>
|