[gtksourceview] Improvements to the lang file tutorial
- From: Paolo Borelli <pborelli src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtksourceview] Improvements to the lang file tutorial
- Date: Sun, 19 Jul 2009 15:29:28 +0000 (UTC)
commit 7e619b62b64427558ba34b52aa50f603c6194742
Author: Paolo Borelli <porelli gnome org>
Date: Sun Jul 19 17:29:53 2009 +0200
Improvements to the lang file tutorial
docs/reference/lang-tutorial.sgml | 124 +++++++++++++++++--------------------
1 files changed, 58 insertions(+), 66 deletions(-)
---
diff --git a/docs/reference/lang-tutorial.sgml b/docs/reference/lang-tutorial.sgml
index 7e19250..2b2e91d 100644
--- a/docs/reference/lang-tutorial.sgml
+++ b/docs/reference/lang-tutorial.sgml
@@ -39,8 +39,7 @@ After the usual preamble, the main tag is the <code><language></code> elem
</para>
<programlisting>
-<language id="c" _name="C" version="2.0" _section="Sources"
- mimetypes="text/x-c;text/x-chdr;text/x-csrc">
+<language id="c" _name="C" version="2.0" _section="Sources">
</programlisting>
<para>
@@ -53,24 +52,43 @@ the name presented to the user (it is translatable using gettext prepending a
<para>
The attribute <code>section</code>, also translatable, tells the category where
this language should be grouped when it is presented to the user. Currently
-available categories in GtkSourceView are "Sources", "Scripts", "Markup"
-and "Others".
+available categories in GtkSourceView are "Sources", "Scripts", "Markup",
+"Scientific" and "Others".
</para>
<para>
-The attribute <code>mimetypes</code> contains a semi-colon separated list of
-mimetypes to be associated to the language.
+The attribute <code>version</code> specifies the version of the xml syntax
+used in your language definition file, so it should always be <code>2.0</code>.
</para>
<para>
-The <code><language></code> element contains an optional
-<code><metadata></code>, which can contain arbitrary elements in
-different namespaces to specifiy author, creation time, etc., and
-<code><styles></code> element followed by a
-<code><definitions></code> element:
+The <code><language></code> element contains three sections:
+<code><metadata></code>, <code><styles></code> and
+<code><definitions></code>
</para>
<programlisting>
+<metadata>
+</programlisting>
+
+<para>
+The <code><metadata></code> element is optional and provides a collection
+of properties which specify arbitrary information about the language definition
+file itself. It is particularly important to specify the conventional
+<code>mimetypes</code> and <code>globs</code> properties that
+GtkSourceView uses to automatically detect which syntax highlighting to use
+for a given file. They respectively contain a semi-colon separated list of
+mimetypes and filename extensions.
+</para>
+
+<programlisting>
+<metadata>
+ <property name="mimetypes">text/x-c;text/x-csrc</property>
+ <property name="globs">*.c</property>
+</metadata>
+</programlisting>
+
+<programlisting>
<styles>
</programlisting>
@@ -98,21 +116,13 @@ contexts, so they will share the same appearance.
</para>
<programlisting>
-<style id="string" _name="String"
- map-to="def:string"/>
-<style id="escape" _name="Escape"
- map-to="def:escape"/>
-<style id="preprocessor" _name="Preprocessor"
- map-to="def:preprocessor"/>
-<style id="included-file" _name="Included File"
- map-to="def:package"/>
-<style id="char" _name="Character"
- map-to="def:string"/>
-<style id="keyword" _name="Keyword"
- map-to="def:keyword"/>
-<style id="data-type" _name="Data Type"
- map-to="def:data-type"/>
-</styles>
+<style id="string" _name="String" map-to="def:string"/>
+<style id="escaped-character" _name="Escaped Character" map-to="def:special-char"/>
+<style id="preprocessor" _name="Preprocessor" map-to="def:preprocessor"/>
+<style id="included-file" _name="Included File" map-to="def:string"/>
+<style id="char" _name="Character" map-to="def:character"/>
+<style id="keyword" _name="Keyword" map-to="def:keyword"/>
+<style id="type" _name="Data Type" map-to="def:type"/>
</programlisting>
<para>
@@ -255,7 +265,7 @@ To implement the escape handling we include a <code>escape</code> context:
</para>
<programlisting>
- <context id="escape" style-ref="escape">
+ <context id="escape" style-ref="escaped-character">
<match>\\.</match>
</context>
</programlisting>
@@ -309,7 +319,7 @@ the comment.
</para>
<programlisting>
-/* This is a comment http://www.gnome.org*/
+/* This is a comment http://www.gnome.org */
</programlisting>
<para>
@@ -354,7 +364,7 @@ reusable contexts wich every language definition can import.
</para>
<para>
-The <code>def</code> language file contains a <code>comment</code> context that can contain
+The <code>def</code> language file contains an <code>in-comment</code> context that can contain
addresses and tags such as FIXME and TODO, so we can write a new version of
our <code>comment-multiline</code> context that uses the definitions from <code>def.lang</code>.
</para>
@@ -364,14 +374,9 @@ our <code>comment-multiline</code> context that uses the definitions from <code>
<start>\/\*</start>
<end>\*\/</end>
<include>
- <context ref="def:comment:*"/>
+ <context ref="def:in-comment"/>
</programlisting>
-<para>
-The <code>:*</code> after the id in the ref means the <code>comment-multiline</code>
-includes every children of the specified context, instead of the context itself.
-</para>
-
<programlisting>
</include>
</context>
@@ -406,7 +411,7 @@ possible to highlight them differently:
</para>
<programlisting>
-<context id="types" style-ref="data-type">
+<context id="types" style-ref="type">
<keyword>char</keyword>
<keyword>const</keyword>
<keyword>double</keyword>
@@ -590,22 +595,13 @@ for this tutorial:
<language id="c" _name="C" version="2.0" _section="Sources"
mimetypes="text/x-c;text/x-chdr;text/x-csrc">
<styles>
- <style id="comment" _name="Comment"
- map-to="def:comment"/>
- <style id="string" _name="String"
- map-to="def:string"/>
- <style id="escape" _name="Escape"
- map-to="def:escape"/>
- <style id="preprocessor" _name="Preprocessor"
- map-to="def:preprocessor"/>
- <style id="included-file" _name="Included File"
- map-to="def:package"/>
- <style id="char" _name="Character"
- map-to="def:string"/>
- <style id="keyword" _name="Keyword"
- map-to="def:keyword"/>
- <style id="data-type" _name="Data Type"
- map-to="def:data-type"/>
+ <style id="string" _name="String" map-to="def:string"/>
+ <style id="escaped-character" _name="Escaped Character" map-to="def:special-char"/>
+ <style id="preprocessor" _name="Preprocessor" map-to="def:preprocessor"/>
+ <style id="included-file" _name="Included File" map-to="def:string"/>
+ <style id="char" _name="Character" map-to="def:character"/>
+ <style id="keyword" _name="Keyword" map-to="def:keyword"/>
+ <style id="type" _name="Data Type" map-to="def:type"/>
</styles>
<definitions>
<context id="c">
@@ -621,8 +617,7 @@ for this tutorial:
<start>"</start>
<end>"</end>
<include>
- <context id="escape"
- style-ref="escape">
+ <context id="escaped-character" style-ref="escaped-character">
<match>\\.</match>
</context>
</include>
@@ -633,16 +628,15 @@ for this tutorial:
<start>\/\*</start>
<end>\*\/</end>
<include>
- <context ref="def:comment:*"/>
+ <context ref="def:in-comment"/>
</include>
</context>
- <context id="char" end-at-line-end="true"
- style-ref="char">
+ <context id="char" end-at-line-end="true" style-ref="char">
<start>'</start>
<end>'</end>
<include>
- <context ref="escape"/>
+ <context ref="escaped-character"/>
</include>
</context>
@@ -665,7 +659,7 @@ for this tutorial:
<keyword>sizeof</keyword>
</context>
- <context id="types" style-ref="data-type">
+ <context id="types" style-ref="type">
<keyword>char</keyword>
<keyword>const</keyword>
<keyword>double</keyword>
@@ -682,11 +676,11 @@ for this tutorial:
<keyword>unsigned</keyword>
<keyword>void</keyword>
</context>
-
+
<context id="preprocessor"
style-ref="preprocessor">
<prefix>^#</prefix>
-
+
<keyword>define</keyword>
<keyword>undef</keyword>
<keyword>if(n?def)?</keyword>
@@ -695,8 +689,7 @@ for this tutorial:
<keyword>endif</keyword>
</context>
- <context id="if0-comment"
- style-ref="comment">
+ <context id="if0-comment" style-ref="comment">
<start>^#if 0\b</start>
<end>^#(endif|else|elif)\b</end>
<include>
@@ -710,8 +703,7 @@ for this tutorial:
</include>
</context>
- <context id="include"
- style-ref="preprocessor">
+ <context id="include" style-ref="preprocessor">
<match>^#include (".*"|<.*>)</match>
<include>
<context id="included-file"
@@ -726,6 +718,6 @@ for this tutorial:
</language>
</programlisting>
-</refsect1>
+</refsect1>
</refentry>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]