PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/doc/users-guide/writing-modes.xml

#
XML | 531 lines | 523 code | 6 blank | 2 comment | 0 complexity | af6f31dbe096f406d46e526e0871facc MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. <!-- jEdit buffer-local properties: -->
  2. <!-- :indentSize=1:noTabs=true: -->
  3. <chapter id="writing-modes"><title>Writing Edit Modes</title>
  4. <para>
  5. Edit modes are defined using XML, the <firstterm>extensible markup
  6. language</firstterm>; mode files have the extension
  7. <filename>.xml</filename>. XML is a very simple language, and as a result
  8. edit modes are easy to create and modify. This section will
  9. start with a short XML primer, followed by detailed information about
  10. each supported tag and highlighting rule.
  11. </para>
  12. <para>
  13. Note that changes to mode files take effect immediately;
  14. editing a mode or a mode catalog file within jEdit will cause the
  15. file to be re-parsed as soon it is saved.
  16. </para>
  17. <para>
  18. The <guimenu>Utilities</guimenu>&gt;<guimenuitem>Reload Edit Modes</guimenuitem>
  19. command can be used to reload edit modes after changes to mode files are made
  20. outside jEdit.
  21. </para>
  22. <sect1 id="xml-primer"><title>An XML Primer</title>
  23. <para>
  24. A very simple edit mode looks like so:
  25. </para>
  26. <programlisting><![CDATA[<?xml version="1.0"?>
  27. <!DOCTYPE MODE SYSTEM "xmode.dtd">
  28. <MODE>
  29. <PROPS>
  30. <PROPERTY NAME="commentStart" VALUE="/*" />
  31. <PROPERTY NAME="commentEnd" VALUE="*/" />
  32. </PROPS>
  33. <RULES>
  34. <SPAN TYPE="COMMENT1">
  35. <BEGIN>/*</BEGIN>
  36. <END>*/</END>
  37. </SPAN>
  38. </RULES>
  39. </MODE>]]></programlisting>
  40. <para>
  41. Note that each opening tag must have a corresponding closing tag.
  42. If there is nothing between the opening and closing tags, for example
  43. <literal>&lt;TAG&gt;&lt;/TAG&gt;</literal>, the shorthand notation
  44. <literal>&lt;TAG /&gt;</literal> may be used. An example of this shorthand
  45. can be seen
  46. in the <literal>&lt;PROPERTY&gt;</literal> tags above.
  47. </para>
  48. <para>
  49. XML is case sensitive. <literal>Span</literal> or <literal>span</literal>
  50. is not the same as <literal>SPAN</literal>.
  51. </para>
  52. <para>
  53. To insert a special character such as &lt; or &gt; literally in XML
  54. (for example, inside an attribute value), you must write it as
  55. an <firstterm>entity</firstterm>. An
  56. entity consists of the character's symbolic name enclosed with
  57. <quote>&amp;</quote> and <quote>;</quote>. The most frequently used entities
  58. are:
  59. </para>
  60. <itemizedlist>
  61. <listitem><para><literal>&amp;lt;</literal> - The less-than (&lt;)
  62. character</para></listitem>
  63. <listitem><para><literal>&amp;gt;</literal> - The greater-than (&gt;)
  64. character</para></listitem>
  65. <listitem><para><literal>&amp;amp;</literal> - The ampersand (&amp;)
  66. character</para></listitem>
  67. </itemizedlist>
  68. <para>
  69. For example, the following will cause a syntax error:
  70. </para>
  71. <programlisting>&lt;SEQ TYPE="OPERATOR"&gt;&amp;&lt;/SEQ&gt;</programlisting>
  72. <para>
  73. Instead, you must write:
  74. </para>
  75. <programlisting>&lt;SEQ TYPE="OPERATOR"&gt;&amp;amp;&lt;/SEQ&gt;</programlisting>
  76. <para>
  77. Now that the basics of XML have been covered, the rest of this
  78. section will cover each construct in detail.
  79. </para>
  80. </sect1>
  81. <sect1 id="mode-preamble"><title>The Preamble and MODE tag</title>
  82. <para>
  83. Each mode definition must begin with the following:
  84. </para>
  85. <programlisting>&lt;?xml version="1.0"?&gt;
  86. &lt;!DOCTYPE MODE SYSTEM "xmode.dtd"&gt;</programlisting>
  87. <para>
  88. Each mode definition must also contain exactly one <literal>MODE</literal>
  89. tag. All other tags (<literal>PROPS</literal>, <literal>RULES</literal>)
  90. must be placed inside the <literal>MODE</literal> tag. The
  91. <literal>MODE</literal> tag does not have any defined attributes.
  92. Here is an example:
  93. </para>
  94. <programlisting><![CDATA[<MODE>]]>
  95. <replaceable>... mode definition goes here ...</replaceable>
  96. <![CDATA[</MODE>]]></programlisting>
  97. </sect1>
  98. <sect1 id="mode-tag-props"><title>The PROPS Tag</title>
  99. <para>
  100. The <literal>PROPS</literal> tag and the <literal>PROPERTY</literal> tags
  101. inside it are used to define mode-specific
  102. properties. Each <literal>PROPERTY</literal> tag must have a
  103. <literal>NAME</literal> attribute set to the property's name, and a
  104. <literal>VALUE</literal> attribute with the property's value.
  105. </para>
  106. <para>
  107. All buffer-local properties listed in <xref linkend="buffer-local" />
  108. may be given values in edit modes. In addition, the following mode
  109. properties have no buffer-local equivalent:
  110. </para>
  111. <itemizedlist>
  112. <listitem><para><literal>commentEnd</literal> - the comment end
  113. string, used by the <guimenuitem>Range Comment</guimenuitem> command.
  114. </para></listitem>
  115. <listitem><para><literal>commentStart</literal> - the comment start
  116. string, used by the <guimenuitem>Range Comment</guimenuitem> command.
  117. </para></listitem>
  118. <listitem><para><literal>lineComment</literal> - the line comment
  119. string, used by the <guimenuitem>Line Comment</guimenuitem> command.
  120. </para></listitem>
  121. <listitem><para><literal>doubleBracketIndent</literal> -
  122. If a line matches the <literal>indentPrevLine</literal> regular
  123. expression and the next line contains an opening bracket,
  124. a level of indent will not be added to the next line, unless
  125. this property is set to <quote>true</quote>. For example, with this
  126. property set to <quote>false</quote>, Java code will be indented like so:
  127. </para>
  128. <programlisting>while(objects.hasMoreElements())
  129. {
  130. ((Drawable)objects.nextElement()).draw();
  131. }</programlisting>
  132. <para>
  133. On the other hand, settings this property to <quote>true</quote> will
  134. give the following result:
  135. </para>
  136. <programlisting>while(objects.hasMoreElements())
  137. {
  138. ((Drawable)objects.nextElement()).draw();
  139. }</programlisting></listitem>
  140. <listitem><para><literal>indentCloseBrackets</literal> -
  141. A list of characters (usually brackets) that subtract indent from
  142. the <emphasis>current</emphasis> line. For example, in Java mode this
  143. property is set to <quote>}</quote>.</para></listitem>
  144. <listitem><para><literal>indentOpenBrackets</literal> -
  145. A list of characters (usually brackets) that add indent to
  146. the <emphasis>next</emphasis> line. For example, in Java mode this
  147. property is set to <quote>{</quote>.</para></listitem>
  148. <listitem><para><literal>indentPrevLine</literal> -
  149. When indenting a line, jEdit checks if the previous line matches
  150. the regular expression stored in this property. If it does, a level
  151. of indent is added. For example, in Java mode this regular expression
  152. matches language constructs such as
  153. <quote>if</quote>, <quote>else</quote>, <quote>while</quote>, etc.</para>
  154. </listitem>
  155. </itemizedlist>
  156. <para>
  157. Here is the complete <literal>&lt;PROPS&gt;</literal> tag for Java mode:
  158. </para>
  159. <programlisting>&lt;PROPS&gt;
  160. &lt;PROPERTY NAME="indentOpenBrackets" VALUE="{" /&gt;
  161. &lt;PROPERTY NAME="indentCloseBrackets" VALUE="}" /&gt;
  162. &lt;PROPERTY NAME="indentPrevLine" VALUE="\s*(((if|while)
  163. \s*\(|else|case|default)[^;]*|for\s*\(.*)" /&gt;
  164. &lt;PROPERTY NAME="doubleBracketIndent" VALUE="false" /&gt;
  165. &lt;PROPERTY NAME="commentStart" VALUE="/*" /&gt;
  166. &lt;PROPERTY NAME="commentEnd" VALUE="*/" /&gt;
  167. &lt;PROPERTY NAME="blockComment" VALUE="//" /&gt;
  168. &lt;PROPERTY NAME="wordBreakChars" VALUE=",+-=&lt;&gt;/?^&amp;*" /&gt;
  169. &lt;/PROPS&gt;</programlisting>
  170. </sect1>
  171. <sect1 id="mode-tag-rules"><title>The RULES Tag</title>
  172. <para>
  173. <literal>RULES</literal> tags must be placed inside the
  174. <literal>MODE</literal> tag. Each <literal>RULES</literal> tag defines a
  175. <firstterm>ruleset</firstterm>. A ruleset consists of a number of
  176. <firstterm>parser rules</firstterm>, with each parser
  177. rule specifying how to highlight a specific syntax token. There must
  178. be at least one ruleset in each edit mode. There can also be more
  179. than one, with different rulesets being used to highlight different
  180. parts of a buffer (for example, in HTML mode, one rule set
  181. highlights HTML tags, and another highlights inline JavaScript).
  182. For information about using more
  183. than one ruleset, see <xref linkend="mode-rule-span" />.
  184. </para>
  185. <para>
  186. The <literal>RULES</literal> tag supports the following attributes, all of
  187. which are optional:
  188. </para>
  189. <itemizedlist>
  190. <listitem><para><literal>SET</literal> - the name of this ruleset.
  191. All rulesets other than the first must have a name.
  192. </para></listitem>
  193. <listitem><para><literal>HIGHLIGHT_DIGITS</literal> - if set to
  194. <literal>TRUE</literal>, digits (0-9, as well as hexadecimal literals
  195. prefixed with <quote>0x</quote>) will be highlighted with the
  196. <classname>DIGIT</classname> token type. Default is <literal>FALSE</literal>.
  197. </para></listitem>
  198. <listitem><para><literal>IGNORE_CASE</literal> - if set to
  199. <literal>FALSE</literal>, matches will be case sensitive. Otherwise, case
  200. will not matter. Default is <literal>TRUE</literal>.
  201. </para></listitem>
  202. <listitem><para><literal>DEFAULT</literal> - the token type for
  203. text which doesn't match
  204. any specific rule. Default is <literal>NULL</literal>. See
  205. <xref linkend="mode-syntax-tokens" /> for a list of token types.
  206. </para></listitem>
  207. </itemizedlist>
  208. <para>
  209. Here is an example <literal>RULES</literal> tag:
  210. </para>
  211. <programlisting>&lt;RULES IGNORE_CASE="FALSE" HIGHLIGHT_DIGITS="TRUE"&gt;
  212. <replaceable>... parser rules go here ...</replaceable>
  213. &lt;/RULES&gt;</programlisting>
  214. <sect2><title>Rule Ordering Requirements</title>
  215. <para>
  216. You might encounter this very common pitfall when writing your own modes.
  217. </para>
  218. <para>
  219. Since jEdit checks buffer text against parser rules in the order they appear
  220. in the ruleset, more specific rules must be placed before generalized ones,
  221. otherwise the generalized rules will catch everything.
  222. </para>
  223. <para>
  224. This is best demonstrated with an example. The following is incorrect rule
  225. ordering:
  226. </para>
  227. <programlisting><![CDATA[<SPAN TYPE="MARKUP">
  228. <BEGIN>[</BEGIN>
  229. <END>]</END>
  230. </SPAN>
  231. <SPAN TYPE="KEYWORD1">
  232. <BEGIN>[!</BEGIN>
  233. <END>]</END>
  234. </SPAN>]]></programlisting>
  235. <para>
  236. If you write the above in a rule set, any occurrence of <quote>[</quote>
  237. (even things like <quote>[!DEFINE</quote>, etc)
  238. will be highlighted using the first rule, because it will be the
  239. first to match. This is most likely not the intended behavior.
  240. </para>
  241. <para>
  242. The problem can be solved by placing the more specific rule before the
  243. general one:
  244. </para>
  245. <programlisting><![CDATA[<SPAN TYPE="KEYWORD1">
  246. <BEGIN>[!</BEGIN>
  247. <END>]</END>
  248. </SPAN>
  249. <SPAN TYPE="MARKUP">
  250. <BEGIN>[</BEGIN>
  251. <END>]</END>
  252. </SPAN>]]></programlisting>
  253. <para>
  254. Now, if the buffer contains the text <quote>[!SPECIAL]</quote>, the
  255. rules will be checked in order, and the first rule will be the first
  256. to match. However, if you write <quote>[FOO]</quote>, it will be highlighted
  257. using the second rule, which is exactly what you would expect.
  258. </para>
  259. </sect2>
  260. <sect2><title>Per-Ruleset Properties</title>
  261. <para>
  262. The <literal>PROPS</literal> tag (described in <xref linkend="mode-tag-props"/>)
  263. can also be placed inside the <literal>RULES</literal> tag to define
  264. ruleset-specific properties. Only the following properties can
  265. be set on a per-ruleset basis:
  266. </para>
  267. <itemizedlist>
  268. <listitem><para><literal>commentEnd</literal> - the comment end
  269. string.
  270. </para></listitem>
  271. <listitem><para><literal>commentStart</literal> - the comment start
  272. string.
  273. </para></listitem>
  274. <listitem><para><literal>lineComment</literal> - the line comment
  275. string.
  276. </para></listitem>
  277. </itemizedlist>
  278. <para>
  279. These properties are used by the commenting commands to implement
  280. context-sensitive comments; see <xref linkend="commenting"/>.
  281. </para>
  282. </sect2>
  283. <sect2 id="mode-rule-terminate"><title>The TERMINATE Rule</title>
  284. <para>
  285. The <literal>TERMINATE</literal> rule specifies that parsing should stop
  286. after the specified number of characters have been read from a line. The
  287. number of characters to terminate after should be specified with the
  288. <literal>AT_CHAR</literal> attribute. Here is an example:
  289. </para>
  290. <programlisting>&lt;TERMINATE AT_CHAR="1" /&gt;</programlisting>
  291. <para>
  292. This rule is used in Patch mode, for example, because only the first
  293. character of each line affects highlighting.
  294. </para>
  295. </sect2>
  296. <sect2 id="mode-rule-span"><title>The SPAN Rule</title>
  297. <para>
  298. The <literal>SPAN</literal> rule highlights text between a start
  299. and end string. The start and end strings are specified inside
  300. child elements of the <literal>SPAN</literal> tag.
  301. The following attributes are supported:
  302. </para>
  303. <itemizedlist>
  304. <listitem><para><literal>TYPE</literal> - The token type to highlight the
  305. span with. See <xref linkend="mode-syntax-tokens" /> for a list of token
  306. types</para></listitem>
  307. <listitem><para><literal>AT_LINE_START</literal> - If set to
  308. <literal>TRUE</literal>, the span will only be highlighted if the start
  309. sequence occurs at the beginning of a line</para></listitem>
  310. <listitem><para><literal>EXCLUDE_MATCH</literal> - If set to
  311. <literal>TRUE</literal>, the start and end sequences will not be highlighted,
  312. only the text between them will</para></listitem>
  313. <listitem><para><literal>NO_LINE_BREAK</literal> - If set to
  314. <literal>TRUE</literal>, the span will be highlighted with the
  315. <classname>INVALID</classname> token type if it spans more than one
  316. line</para></listitem>
  317. <listitem><para><literal>NO_WORD_BREAK</literal> - If set to
  318. <literal>TRUE</literal>, the span will be highlighted with the
  319. <classname>INVALID</classname> token type if it includes
  320. whitespace</para></listitem>
  321. <listitem><para><literal>DELEGATE</literal> - text inside the span will be
  322. highlighted with the specified ruleset. To delegate to a ruleset defined
  323. in the current mode, just specify its name. To delegate to a ruleset
  324. defined in another mode, specify a name of the form
  325. <literal><replaceable>mode</replaceable>::<replaceable>ruleset</replaceable></literal>.
  326. Note that the first (unnamed) ruleset in a mode is called
  327. <quote>MAIN</quote>.</para></listitem>
  328. </itemizedlist>
  329. <para>
  330. Here is a <literal>SPAN</literal> that highlights Java string literals,
  331. which cannot include line breaks:
  332. </para>
  333. <programlisting>&lt;SPAN TYPE="LITERAL1" NO_LINE_BREAK="TRUE"&gt;
  334. &lt;BEGIN&gt;"&lt;/BEGIN&gt;
  335. &lt;END&gt;"&lt;/END&gt;
  336. &lt;/SPAN&gt;</programlisting>
  337. <para>
  338. Here is a <literal>SPAN</literal> that highlights Java documentation
  339. comments by delegating to the <quote>JAVADOC</quote> ruleset defined
  340. elsewhere in the current mode:
  341. </para>
  342. <programlisting>&lt;SPAN TYPE="COMMENT2" DELEGATE="JAVADOC"&gt;
  343. &lt;BEGIN&gt;/**&lt;/BEGIN&gt;
  344. &lt;END&gt;*/&lt;/END&gt;
  345. &lt;/SPAN&gt;</programlisting>
  346. <para>
  347. Here is a <literal>SPAN</literal> that highlights HTML cascading stylesheets
  348. inside <literal>&lt;STYLE&gt;</literal> tags by delegating to the main
  349. ruleset in the CSS edit mode:
  350. </para>
  351. <programlisting>&lt;SPAN TYPE="MARKUP" DELEGATE="css::MAIN"&gt;
  352. &lt;BEGIN&gt;&amp;lt;style&amp;gt;&lt;/BEGIN&gt;
  353. &lt;END&gt;&amp;lt;/style&amp;gt;&lt;/END&gt;
  354. &lt;/SPAN&gt;</programlisting>
  355. <tip>
  356. <para>
  357. The <literal>&lt;END&gt;</literal> tag is optional. If it is not specified,
  358. any occurrence of the start string will cause the remainder of the buffer
  359. to be highlighted with this rule.
  360. </para>
  361. <para>
  362. This can be very useful when combined with delegation.
  363. </para>
  364. </tip>
  365. </sect2>
  366. <sect2 id="mode-rule-eol-span"><title>The EOL_SPAN Rule</title>
  367. <para>
  368. An <literal>EOL_SPAN</literal> is similar to a <literal>SPAN</literal>
  369. except that highlighting stops at the end of the line, not after the end
  370. sequence is found. The text to match is specified between the opening and
  371. closing <literal>EOL_SPAN</literal> tags.
  372. The following attributes are supported:
  373. </para>
  374. <itemizedlist>
  375. <listitem><para><literal>TYPE</literal> - The token type to highlight the span
  376. with. See <xref linkend="mode-syntax-tokens" /> for a list of token
  377. types</para></listitem>
  378. <listitem><para><literal>AT_LINE_START</literal> - If set to
  379. <literal>TRUE</literal>, the span will only be highlighted if the start
  380. sequence occurs at the beginning of a line</para></listitem>
  381. <listitem><para><literal>EXCLUDE_MATCH</literal> - If set to
  382. <literal>TRUE</literal>, the start sequence will not be highlighted,
  383. only the text after it will</para></listitem>
  384. </itemizedlist>
  385. <para>
  386. Here is an <literal>EOL_SPAN</literal> that highlights C++ comments:
  387. </para>
  388. <programlisting>&lt;EOL_SPAN TYPE="COMMENT1"&gt;//&lt;/EOL_SPAN&gt;</programlisting>
  389. </sect2>
  390. <sect2 id="mode-rule-mark-prev"><title>The MARK_PREVIOUS Rule</title>
  391. <para>
  392. The <literal>MARK_PREVIOUS</literal> rule highlights from the end of the
  393. previous syntax token to the matched text. The text to match
  394. is specified between opening and closing <literal>MARK_PREVIOUS</literal>
  395. tags. The following attributes are supported:
  396. </para>
  397. <itemizedlist>
  398. <listitem><para><literal>TYPE</literal> - The token type to highlight the
  399. text with. See <xref linkend="mode-syntax-tokens" /> for a list of token
  400. types</para></listitem>
  401. <listitem><para><literal>AT_LINE_START</literal> - If set to
  402. <literal>TRUE</literal>,
  403. the text will only be highlighted if it occurs at the beginning of
  404. the line</para></listitem>
  405. <listitem><para><literal>EXCLUDE_MATCH</literal> - If set to
  406. <literal>TRUE</literal>, the match will not be highlighted,
  407. only the text before it will</para></listitem>
  408. </itemizedlist>
  409. <para>
  410. Here is a rule that highlights labels in Java mode (for example,
  411. <quote>XXX:</quote>):
  412. </para>
  413. <programlisting>&lt;MARK_PREVIOUS AT_LINE_START="TRUE"
  414. EXCLUDE_MATCH="TRUE"&gt;:&lt;/MARK_PREVIOUS&gt;</programlisting>
  415. </sect2>
  416. <sect2 id="mode-rule-mark-following"><title>The MARK_FOLLOWING Rule</title>
  417. <para>
  418. The <literal>MARK_FOLLOWING</literal> rule highlights from the start of the
  419. match to the next syntax token. The text to match
  420. is specified between opening and closing <literal>MARK_FOLLOWING</literal>
  421. tags. The following attributes are supported:
  422. </para>
  423. <itemizedlist>
  424. <listitem><para><literal>TYPE</literal> - The token type to highlight the
  425. text with. See <xref linkend="mode-syntax-tokens" /> for a list of token
  426. types</para></listitem>
  427. <listitem><para><literal>AT_LINE_START</literal> - If set to
  428. <literal>TRUE</literal>, the text will only be highlighted if the start
  429. sequence occurs at the beginning of a line</para></listitem>
  430. <listitem><para><literal>EXCLUDE_MATCH</literal> - If set to
  431. <literal>TRUE</literal>, the match will not be highlighted,
  432. only the text after it will</para></listitem>
  433. </itemizedlist>
  434. <para>
  435. Here is a rule that highlights variables in Unix shell scripts
  436. (<quote>$CLASSPATH</quote>, <quote>$IFS</quote>, etc):
  437. </para>
  438. <programlisting>&lt;MARK_FOLLOWING TYPE="KEYWORD2"&gt;$&lt;/MARK_FOLLOWING&gt;</programlisting>
  439. </sect2>
  440. <sect2 id="mode-rule-seq"><title>The SEQ Rule</title>
  441. <para>
  442. The <literal>SEQ</literal> rule highlights fixed sequences of text. The text
  443. to highlight is specified between opening and closing <literal>SEQ</literal>
  444. tags. The following attributes are supported:
  445. </para>
  446. <itemizedlist>
  447. <listitem><para><literal>TYPE</literal> - the token type to highlight the
  448. sequence with. See <xref linkend="mode-syntax-tokens" /> for a list of token
  449. types</para></listitem>
  450. <listitem><para><literal>AT_LINE_START</literal> - If set to
  451. <literal>TRUE</literal>, the sequence will only be highlighted if it occurs
  452. at the beginning of a line</para></listitem>
  453. </itemizedlist>
  454. <para>
  455. The following rules highlight a few Java operators:
  456. </para>
  457. <programlisting>&lt;SEQ TYPE="OPERATOR"&gt;+&lt;/SEQ&gt;
  458. &lt;SEQ TYPE="OPERATOR"&gt;-&lt;/SEQ&gt;
  459. &lt;SEQ TYPE="OPERATOR"&gt;*&lt;/SEQ&gt;
  460. &lt;SEQ TYPE="OPERATOR"&gt;/&lt;/SEQ&gt;</programlisting>
  461. </sect2>
  462. <sect2 id="mode-rule-keywords"><title>The KEYWORDS Rule</title>
  463. <para>
  464. There can only be one <literal>KEYWORDS</literal> tag per ruleset.
  465. The <literal>KEYWORDS</literal> rule defines keywords to highlight.
  466. Keywords are similar to <literal>SEQ</literal>s, except that
  467. <literal>SEQ</literal>s match anywhere in the text, whereas keywords only
  468. match whole words.
  469. </para>
  470. <para>
  471. The <literal>KEYWORDS</literal> tag does not define any attributes.
  472. </para>
  473. <para>
  474. Each child element of the <literal>KEYWORDS</literal> tag should be named
  475. after the desired token type, with the keyword text between the start and
  476. end tags. For example, the following rule highlights the most common Java
  477. keywords:
  478. </para>
  479. <programlisting>&lt;KEYWORDS IGNORE_CASE="FALSE"&gt;
  480. &lt;KEYWORD1&gt;if&lt;/KEYWORD1&gt;
  481. &lt;KEYWORD1&gt;else&lt;/KEYWORD1&gt;
  482. &lt;KEYWORD3&gt;int&lt;/KEYWORD3&gt;
  483. &lt;KEYWORD3&gt;void&lt;/KEYWORD3&gt;
  484. &lt;/KEYWORDS&gt;</programlisting>
  485. </sect2>
  486. <sect2 id="mode-syntax-tokens"><title>Token Types</title>
  487. <para>
  488. Parser rules can highlight tokens using any of the following token
  489. types:
  490. </para>
  491. <itemizedlist>
  492. <listitem><para><literal>NULL</literal> - no special
  493. highlighting is performed on tokens of type <literal>NULL</literal>
  494. </para></listitem>
  495. <listitem><para><literal>COMMENT1</literal>
  496. </para></listitem>
  497. <listitem><para><literal>COMMENT2</literal>
  498. </para></listitem>
  499. <listitem><para><literal>FUNCTION</literal>
  500. </para></listitem>
  501. <listitem><para><literal>INVALID</literal> - tokens of this type are
  502. automatically added if a <literal>NO_WORD_BREAK</literal> or
  503. <literal>NO_LINE_BREAK</literal> <literal>SPAN</literal> spans more than
  504. one word or line, respectively.
  505. </para></listitem>
  506. <listitem><para><literal>KEYWORD1</literal>
  507. </para></listitem>
  508. <listitem><para><literal>KEYWORD2</literal>
  509. </para></listitem>
  510. <listitem><para><literal>KEYWORD3</literal>
  511. </para></listitem>
  512. <listitem><para><literal>LABEL</literal>
  513. </para></listitem>
  514. <listitem><para><literal>LITERAL1</literal>
  515. </para></listitem>
  516. <listitem><para><literal>LITERAL2</literal>
  517. </para></listitem>
  518. <listitem><para><literal>MARKUP</literal>
  519. </para></listitem>
  520. <listitem><para><literal>OPERATOR</literal>
  521. </para></listitem>
  522. </itemizedlist>
  523. </sect2>
  524. </sect1>
  525. </chapter>