Upstream changes

master
Yevgen Muntyan 2007-11-03 12:49:50 -05:00
parent c446f77f97
commit 83d1ead0e0
6 changed files with 85 additions and 28 deletions

View File

@ -50,6 +50,7 @@ struct _GtkSourceLanguagePrivate
/* Maps ids to GtkSourceStyleInfo objects */ /* Maps ids to GtkSourceStyleInfo objects */
/* Names of styles defined in other lang files are not stored */ /* Names of styles defined in other lang files are not stored */
GHashTable *styles; GHashTable *styles;
gboolean styles_loaded;
gint version; gint version;
gboolean hidden; gboolean hidden;
@ -84,7 +85,7 @@ GtkSourceEngine *_gtk_source_language_create_engine (GtkSourceLanguage *lan
/* Utility functions for GtkSourceStyleInfo */ /* Utility functions for GtkSourceStyleInfo */
GtkSourceStyleInfo *_gtk_source_style_info_new (const gchar *name, GtkSourceStyleInfo *_gtk_source_style_info_new (const gchar *name,
const gchar *map_to); const gchar *map_to);
GtkSourceStyleInfo *_gtk_source_style_info_copy (GtkSourceStyleInfo *info);
void _gtk_source_style_info_free (GtkSourceStyleInfo *info); void _gtk_source_style_info_free (GtkSourceStyleInfo *info);
G_END_DECLS G_END_DECLS

View File

@ -52,8 +52,9 @@ enum {
G_DEFINE_TYPE (GtkSourceLanguage, gtk_source_language, G_TYPE_OBJECT) G_DEFINE_TYPE (GtkSourceLanguage, gtk_source_language, G_TYPE_OBJECT)
static GtkSourceLanguage *process_language_node (xmlTextReaderPtr reader, static GtkSourceLanguage *process_language_node (xmlTextReaderPtr reader,
const gchar *filename); const gchar *filename);
static gboolean force_styles (GtkSourceLanguage *language);
GtkSourceLanguage * GtkSourceLanguage *
_gtk_source_language_new_from_file (const gchar *filename, _gtk_source_language_new_from_file (const gchar *filename,
@ -624,6 +625,15 @@ _gtk_source_language_get_language_manager (GtkSourceLanguage *language)
/* Highlighting engine creation ------------------------------------------ */ /* Highlighting engine creation ------------------------------------------ */
static void
copy_style_info (const char *style_id,
GtkSourceStyleInfo *info,
GHashTable *dest)
{
g_hash_table_insert (dest, g_strdup (style_id),
_gtk_source_style_info_copy (info));
}
void void
_gtk_source_language_define_language_styles (GtkSourceLanguage *lang) _gtk_source_language_define_language_styles (GtkSourceLanguage *lang)
{ {
@ -642,6 +652,8 @@ _gtk_source_language_define_language_styles (GtkSourceLanguage *lang)
{NULL, NULL}}; {NULL, NULL}};
gint i = 0; gint i = 0;
GtkSourceLanguageManager *lm;
GtkSourceLanguage *def_lang;
while (alias[i][0] != NULL) while (alias[i][0] != NULL)
{ {
@ -655,13 +667,26 @@ _gtk_source_language_define_language_styles (GtkSourceLanguage *lang)
++i; ++i;
} }
/* We translate String to def:string, but def:string is mapped-to
* def:constant in def.lang, so we got to take style mappings from def.lang */
lm = _gtk_source_language_get_language_manager (lang);
def_lang = gtk_source_language_manager_get_language (lm, "def");
if (def_lang != NULL)
{
force_styles (def_lang);
g_hash_table_foreach (def_lang->priv->styles,
(GHFunc) copy_style_info,
lang->priv->styles);
}
} }
GtkSourceEngine * /* returns new reference, which _must_ be unref'ed */
_gtk_source_language_create_engine (GtkSourceLanguage *language) static GtkSourceContextData *
gtk_source_language_parse_file (GtkSourceLanguage *language)
{ {
GtkSourceContextEngine *ce = NULL;
if (language->priv->ctx_data == NULL) if (language->priv->ctx_data == NULL)
{ {
gboolean success = FALSE; gboolean success = FALSE;
@ -698,10 +723,21 @@ _gtk_source_language_create_engine (GtkSourceLanguage *language)
_gtk_source_context_data_ref (language->priv->ctx_data); _gtk_source_context_data_ref (language->priv->ctx_data);
} }
if (language->priv->ctx_data) return language->priv->ctx_data;
}
GtkSourceEngine *
_gtk_source_language_create_engine (GtkSourceLanguage *language)
{
GtkSourceContextEngine *ce = NULL;
GtkSourceContextData *ctx_data;
ctx_data = gtk_source_language_parse_file (language);
if (ctx_data != NULL)
{ {
ce = _gtk_source_context_engine_new (language->priv->ctx_data); ce = _gtk_source_context_engine_new (ctx_data);
_gtk_source_context_data_unref (language->priv->ctx_data); _gtk_source_context_data_unref (ctx_data);
} }
return ce ? GTK_SOURCE_ENGINE (ce) : NULL; return ce ? GTK_SOURCE_ENGINE (ce) : NULL;
@ -760,19 +796,20 @@ get_style_ids (GtkSourceLanguage *language)
static gboolean static gboolean
force_styles (GtkSourceLanguage *language) force_styles (GtkSourceLanguage *language)
{ {
GtkSourceEngine *ce; /* To be sure to have the list of styles we need to parse lang file
* as if we were to create an engine. In the future we can improve
/* To be sure to have the list of styles we need to create a * this by parsing styles only.
* GtkSourceContextEngine.
* In the future we can improve this avoiding to create a context
* engine.
*/ */
if (language->priv->ctx_data == NULL) if (!language->priv->styles_loaded && language->priv->ctx_data == NULL)
{ {
ce = _gtk_source_language_create_engine (language); GtkSourceContextData *ctx_data;
if (ce == NULL)
ctx_data = gtk_source_language_parse_file (language);
if (ctx_data == NULL)
return FALSE; return FALSE;
g_object_unref (ce);
language->priv->styles_loaded = TRUE;
_gtk_source_context_data_unref (ctx_data);
} }
return TRUE; return TRUE;
@ -859,6 +896,13 @@ _gtk_source_style_info_new (const gchar *name, const gchar *map_to)
return info; return info;
} }
GtkSourceStyleInfo *
_gtk_source_style_info_copy (GtkSourceStyleInfo *info)
{
g_return_val_if_fail (info != NULL, NULL);
return _gtk_source_style_info_new (info->name, info->map_to);
}
void void
_gtk_source_style_info_free (GtkSourceStyleInfo *info) _gtk_source_style_info_free (GtkSourceStyleInfo *info)
{ {

View File

@ -48,7 +48,7 @@
<style id="doc-comment" _name="Documentation comment" map-to="def:comment"/> <style id="doc-comment" _name="Documentation comment" map-to="def:comment"/>
<!-- A element inside a documentation comment: @author --> <!-- A element inside a documentation comment: @author -->
<!-- This style doesn't map to anything since it must be used as an additional <!-- This style doesn't map to anything since it must be used as an additional
style for text which is already styled as a "doc-comment" --> style for text which is already styled as a "doc-comment" -->
<style id="doc-comment-element" _name="Documentation comment element" /> <style id="doc-comment-element" _name="Documentation comment element" />
@ -61,11 +61,11 @@
<!-- A character constant: 'c' --> <!-- A character constant: 'c' -->
<style id="character" _name="Character" map-to="def:constant"/> <style id="character" _name="Character" map-to="def:constant"/>
<!-- A string constant: "this is a string" --> <!-- A string constant: "this is a string" -->
<style id="string" _name="String" map-to="def:constant"/> <style id="string" _name="String" map-to="def:constant"/>
<!-- Special character in a string constant: "%s", "\t" --> <!-- Special character in a string constant: "%s", "\t" -->
<!-- This style doesn't map to anything since it must be used as an additional <!-- This style doesn't map to anything since it must be used as an additional
style for text which is already styled as a "string" --> style for text which is already styled as a "string" -->
<style id="special-char" _name="Special character (inside a string)" /> <style id="special-char" _name="Special character (inside a string)" />
@ -99,7 +99,7 @@
<!-- A function name (also: methods for classes) --> <!-- A function name (also: methods for classes) -->
<style id="function" _name="Function" map-to="def:identifier"/> <style id="function" _name="Function" map-to="def:identifier"/>
<!-- A builtin name: like __import__, abs in Python <!-- A builtin name: like __import__, abs in Python
(see http://docs.python.org/lib/built-in-funcs.html) --> (see http://docs.python.org/lib/built-in-funcs.html) -->
<style id="builtin" _name="Built-in identifier" map-to="def:identifier"/> <style id="builtin" _name="Built-in identifier" map-to="def:identifier"/>
@ -261,5 +261,8 @@
</include> </include>
</context> </context>
<!-- Dummy context, needed to load the style mappings when parsing v1 files -->
<context id="def"/>
</definitions> </definitions>
</language> </language>

View File

@ -36,6 +36,8 @@
<style id="type" _name="Data Type" map-to="def:type"/> <style id="type" _name="Data Type" map-to="def:type"/>
</styles> </styles>
<default-regex-options case-sensitive="false"/>
<definitions> <definitions>
<!-- Note: contains an hack to avoid considering ^COMMON a comment --> <!-- Note: contains an hack to avoid considering ^COMMON a comment -->

View File

@ -71,7 +71,7 @@
<include> <include>
<context ref="skip-asterisk"/> <context ref="skip-asterisk"/>
<context extend-parent="false"> <context extend-parent="false">
<start>(([\w_]+\:\:[\w_-]+)|([\w_]+\:[\w_-]+)|([\w_]+))\:?</start> <start>(([\w_]+\:\:[\w_-]+)|([\w_]+\:[\w_-]+)|([\w_]+))\:\s*$</start>
<include> <include>
<context sub-pattern="2" where="start" style-ref="function-name"/> <context sub-pattern="2" where="start" style-ref="function-name"/>
<context sub-pattern="3" where="start" style-ref="signal-name"/> <context sub-pattern="3" where="start" style-ref="signal-name"/>

View File

@ -32,6 +32,8 @@
<style id="location" _name="Location" map-to="def:comment"/> <style id="location" _name="Location" map-to="def:comment"/>
<style id="string" _name="String" map-to="def:string"/> <style id="string" _name="String" map-to="def:string"/>
<style id="keyword" _name="Keyword" map-to="def:keyword"/> <style id="keyword" _name="Keyword" map-to="def:keyword"/>
<!-- FIXME make it some nice name and mark it translatable -->
<style id="special" name="Special" map-to="def:special-char"/>
</styles> </styles>
<definitions> <definitions>
@ -41,11 +43,16 @@
<include> <include>
<context ref="def:escape"/> <context ref="def:escape"/>
<context ref="def:line-continue"/> <context ref="def:line-continue"/>
<context ref="c:printf"/> <context ref="def:email-address"/>
<context ref="python:format"/> <context ref="def:net-address"/>
<context id="mnemonic" style-ref="def:special-char"> <context id="mnemonic" style-ref="special">
<match>[&amp;_][a-zA-Z]</match> <match>[&amp;_][a-zA-Z]</match>
</context> </context>
<context id="tag" style-ref="special">
<match>&lt;[a-zA-Z\=\"\/ ]+&gt;</match>
</context>
<context ref="python:format" style-ref="special"/>
<context ref="c:printf" style-ref="special"/>
</include> </include>
</context> </context>
<context id="format" style-ref="comment" end-at-line-end="true"> <context id="format" style-ref="comment" end-at-line-end="true">