Upstream changes
parent
c446f77f97
commit
83d1ead0e0
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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 -->
|
||||||
|
|
|
@ -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"/>
|
||||||
|
|
|
@ -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>[&_][a-zA-Z]</match>
|
<match>[&_][a-zA-Z]</match>
|
||||||
</context>
|
</context>
|
||||||
|
<context id="tag" style-ref="special">
|
||||||
|
<match><[a-zA-Z\=\"\/ ]+></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">
|
||||||
|
|
Loading…
Reference in New Issue