Happy new year!

master
Yevgen Muntyan 2006-12-31 04:54:51 -06:00
parent 03f1b83e55
commit eb3a481089
30 changed files with 847 additions and 494 deletions

View File

@ -35,6 +35,8 @@
#define _gtk_source_engine_set_style_scheme _moo_gtk_source_engine_set_style_scheme
#define gtk_source_iter_forward_search _moo_gtk_source_iter_forward_search
#define gtk_source_iter_backward_search _moo_gtk_source_iter_backward_search
#define gtk_source_style_new _moo_gtk_source_style_new
#define gtk_source_style_copy _moo_gtk_source_style_copy
#define gtk_source_style_free _moo_gtk_source_style_free
#define gtk_source_style_scheme_get_id _moo_gtk_source_style_scheme_get_id
#define gtk_source_style_scheme_get_name _moo_gtk_source_style_scheme_get_name

View File

@ -78,7 +78,7 @@
#define LOOKUP_DEFINITION(ctx_data, id) \
(g_hash_table_lookup ((ctx_data)->definitions, (id)))
#define HAS_OPTION(def,opt) (((def)->match_options & GTK_SOURCE_CONTEXT_##opt) != 0)
#define HAS_OPTION(def,opt) (((def)->flags & GTK_SOURCE_CONTEXT_##opt) != 0)
/* Can the context be terminated by ancestor? */
/* Root context can't be terminated; its child may not be terminated by it;
@ -92,6 +92,12 @@
((ctx)->parent == NULL || (ctx)->parent->parent == NULL || \
HAS_OPTION ((ctx)->definition, EXTEND_PARENT))
/* Root and its children have this FALSE; grandchildren use the flag */
#define CONTEXT_ENDS_PARENT(ctx) \
((ctx)->parent != NULL && (ctx)->parent->parent != NULL && \
HAS_OPTION ((ctx)->definition, END_PARENT))
#define SEGMENT_ENDS_PARENT(s) CONTEXT_ENDS_PARENT ((s)->context)
/* Does the segment terminate at line end? */
/* Root segment doesn't, children look at the flag */
#define CONTEXT_END_AT_LINE_END(ctx) \
@ -187,7 +193,7 @@ struct _ContextDefinition
* context. */
Regex *reg_all;
GtkSourceContextMatchOptions match_options;
GtkSourceContextFlags flags;
};
struct _SubPatternDefinition
@ -295,6 +301,11 @@ struct _Segment
gint start_at;
gint end_at;
/* In case of container contexts, start_len/end_len is length in chars
* of start/end match. */
gint start_len;
gint end_len;
/* Whether this segment is a whole good segment, or it's an
* an end of bigger one left after erase_segments() call. */
guint is_start : 1;
@ -529,6 +540,8 @@ set_tag_style (GtkSourceContextEngine *ce,
while (style == NULL)
{
/* XXX Style references really must be fixed, both parser for
* sane use in lang files, and engine for safe use. */
/* FIXME This may be an infinite loop *if* we allow circular
* references between lang files. */
map_to = g_hash_table_lookup (ENGINE_STYLES_MAP(ce), map_to);
@ -711,9 +724,27 @@ apply_tags (GtkSourceContextEngine *ce,
if (tag != NULL)
{
gtk_text_buffer_get_iter_at_offset (ce->priv->buffer, &start_iter, start_offset);
gtk_text_buffer_get_iter_at_offset (ce->priv->buffer, &end_iter, end_offset);
gtk_text_buffer_apply_tag (ce->priv->buffer, tag, &start_iter, &end_iter);
gint style_start_at, style_end_at;
style_start_at = start_offset;
style_end_at = end_offset;
if (HAS_OPTION (segment->context->definition, STYLE_INSIDE))
{
style_start_at = MAX (segment->start_at + segment->start_len, start_offset);
style_end_at = MIN (segment->end_at - segment->end_len, end_offset);
}
if (style_start_at > style_end_at)
{
g_critical ("%s: oops", G_STRLOC);
}
else
{
gtk_text_buffer_get_iter_at_offset (ce->priv->buffer, &start_iter, style_start_at);
gtk_text_buffer_get_iter_at_offset (ce->priv->buffer, &end_iter, style_end_at);
gtk_text_buffer_apply_tag (ce->priv->buffer, tag, &start_iter, &end_iter);
}
}
for (sp = segment->sub_patterns; sp != NULL; sp = sp->next)
@ -840,7 +871,7 @@ ensure_highlighted (GtkSourceContextEngine *ce,
* refresh_region.
*
* Marks the area as updated - notifies view about it, and adds it to
* refresh_region if @modify_refresh_region is TRUE (update_syntax may
* refresh_region if @modify_refresh_region is %TRUE (update_syntax may
* process huge area though actually updated is couple of lines, so in
* that case update_syntax() takes care of refresh_region, and this
* function only notifies the view).
@ -1195,6 +1226,8 @@ find_insertion_place (Segment *segment,
*
* Finds invalid segment adjacent to offset (i.e. such that start <= offset <= end),
* if any.
*
* Returns: invalid segment or %NULL.
*/
static Segment *
get_invalid_at (GtkSourceContextEngine *ce,
@ -1246,6 +1279,8 @@ segment_add_subpattern (Segment *state,
*
* Creates new subpattern and adds it to the segment's
* subpatterns list.
*
* Returns: new subpattern.
*/
static SubPattern *
sub_pattern_new (Segment *segment,
@ -1312,6 +1347,8 @@ segment_make_invalid_ (GtkSourceContextEngine *ce,
ctx = segment->context;
segment->context = NULL;
segment->is_start = FALSE;
segment->start_len = 0;
segment->end_len = 0;
add_invalid (ce, segment);
context_unref (ctx);
}
@ -1391,7 +1428,7 @@ simple_segment_split_ (GtkSourceContextEngine *ce,
* means insertion; 0 means "something happened here", it's
* treated as zero-length insertion.
*/
static gboolean
static void
invalidate_region (GtkSourceContextEngine *ce,
gint offset,
gint length)
@ -1447,8 +1484,6 @@ invalidate_region (GtkSourceContextEngine *ce,
CHECK_TREE (ce);
install_first_update (ce);
return TRUE;
}
/**
@ -1461,7 +1496,7 @@ invalidate_region (GtkSourceContextEngine *ce,
* Updates segment tree after insertion: it updates tree
* offsets as appropriate, and inserts a new invalid segment
* or extends existing invalid segment as @offset, so
* after the call segment [offset, offset + length) is marked
* after the call segment [@offset, @offset + @length) is marked
* invalid in the tree.
* It may be safely called with length == 0 at any moment
* to invalidate some offset (and it's used here and there).
@ -1597,7 +1632,7 @@ gtk_source_context_engine_text_inserted (GtkSourceEngine *engine,
* @start: start of deleted text.
* @length: length of deleted text.
*
* Returns new offset depending on location of @offset
* Returns: new offset depending on location of @offset
* relative to deleted text.
* Called only from fix_offsets_delete_().
*/
@ -1722,7 +1757,7 @@ gtk_source_context_engine_text_deleted (GtkSourceEngine *engine,
*
* @ce: a #GtkSourceContextEngine.
*
* Returns first invalid segment, or NULL.
* Returns: first invalid segment, or %NULL.
*/
static Segment *
get_invalid_segment (GtkSourceContextEngine *ce)
@ -1736,7 +1771,7 @@ get_invalid_segment (GtkSourceContextEngine *ce)
*
* @ce: a #GtkSourceContextEngine.
*
* Returns first invalid line, or -1.
* Returns: first invalid line, or -1.
*/
static gint
get_invalid_line (GtkSourceContextEngine *ce)
@ -1846,7 +1881,7 @@ update_tree (GtkSourceContextEngine *ce)
* GtkSourceEngine::update_highlight method.
*
* Makes sure the area is analyzed and highlighted. If @asynchronous
* is FALSE, then it queues idle worker.
* is %FALSE, then it queues idle worker.
*/
static void
gtk_source_context_engine_update_highlight (GtkSourceEngine *engine,
@ -1940,7 +1975,7 @@ buffer_notify_highlight_cb (GtkSourceContextEngine *ce)
*
* @ce: a #GtkSourceContextEngine.
*
* Returns whether everything is analyzed (but it doesn't care about the tags).
* Returns: whether everything is analyzed (but it doesn't care about the tags).
*/
static gboolean
all_analyzed (GtkSourceContextEngine *ce)
@ -2095,7 +2130,7 @@ destroy_tags_hash (GtkSourceContextEngine *ce)
* @buffer: buffer.
*
* Detaches engine from previous buffer, and attaches to @buffer if
* it's not NULL.
* it's not %NULL.
*/
static void
gtk_source_context_engine_attach_buffer (GtkSourceEngine *engine,
@ -2184,8 +2219,17 @@ gtk_source_context_engine_attach_buffer (GtkSourceEngine *engine,
&start, TRUE);
ce->priv->invalid_region.end = gtk_text_buffer_create_mark (buffer, NULL,
&end, FALSE);
ce->priv->invalid_region.empty = FALSE;
ce->priv->invalid_region.delta = gtk_text_buffer_get_char_count (buffer);
if (gtk_text_buffer_get_char_count (buffer) != 0)
{
ce->priv->invalid_region.empty = FALSE;
ce->priv->invalid_region.delta = gtk_text_buffer_get_char_count (buffer);
}
else
{
ce->priv->invalid_region.empty = TRUE;
ce->priv->invalid_region.delta = 0;
}
g_object_get (ce->priv->buffer, "highlight", &ce->priv->highlight, NULL);
ce->priv->refresh_region = gtk_text_region_new (buffer);
@ -2302,6 +2346,7 @@ _gtk_source_context_engine_new (GtkSourceContextData *ctx_data)
GtkSourceContextEngine *ce;
g_return_val_if_fail (ctx_data != NULL, NULL);
g_return_val_if_fail (ctx_data->lang != NULL, NULL);
ce = g_object_new (GTK_TYPE_SOURCE_CONTEXT_ENGINE, NULL);
ce->priv->ctx_data = _gtk_source_context_data_ref (ctx_data);
@ -2351,7 +2396,7 @@ _gtk_source_context_data_ref (GtkSourceContextData *ctx_data)
*
* @ctx_data: #GtkSourceContextData.
*
* Decreases reference count in ctx_data. Then reference count
* Decreases reference count in ctx_data. When reference count
* drops to zero, ctx_data is freed, and ctx_data->lang->priv->ctx_data
* is unset.
*/
@ -2438,11 +2483,11 @@ find_single_byte_escape (const gchar *string)
*
* @pattern: the regular expression.
* @flags: compile options for @pattern.
* @error: location to store the error occuring, or NULL to ignore errors.
* @error: location to store the error occuring, or %NULL to ignore errors.
*
* Creates a new regex.
*
* Return value: a newly-allocated #Regex.
* Returns: a newly-allocated #Regex.
*/
static Regex *
regex_new (const gchar *pattern,
@ -2457,7 +2502,7 @@ regex_new (const gchar *pattern,
{
g_set_error (error, GTK_SOURCE_CONTEXT_ENGINE_ERROR,
GTK_SOURCE_CONTEXT_ENGINE_ERROR_INVALID_REGEX,
"using \\C is not supported");
_("using \\C is not supported in language definitions"));
return NULL;
}
@ -2581,7 +2626,7 @@ replace_start_regex (const EggRegex *regex,
* them (they are extracted from @start_regex and @matched_text) and
* returns the new regular expression.
*
* Return value: a #Regex.
* Returns: a #Regex.
*/
static Regex *
regex_resolve (Regex *regex,
@ -2734,6 +2779,33 @@ apply_sub_patterns (Segment *state,
{
GSList *sub_pattern_list = state->context->definition->sub_patterns;
if (SEGMENT_IS_CONTAINER (state))
{
gint start_pos;
gint end_pos;
regex_fetch_pos (regex, line->text, 0, &start_pos, &end_pos);
if (where == SUB_PATTERN_WHERE_START)
{
if (line->start_at + start_pos != state->start_at)
g_critical ("%s: oops", G_STRLOC);
else if (line->start_at + end_pos > state->end_at)
g_critical ("%s: oops", G_STRLOC);
else
state->start_len = line->start_at + end_pos - state->start_at;
}
else
{
if (line->start_at + start_pos < state->start_at)
g_critical ("%s: oops", G_STRLOC);
else if (line->start_at + end_pos != state->end_at)
g_critical ("%s: oops", G_STRLOC);
else
state->end_len = state->end_at - line->start_at - start_pos;
}
}
while (sub_pattern_list != NULL)
{
SubPatternDefinition *sp_def = sub_pattern_list->data;
@ -2770,25 +2842,18 @@ apply_sub_patterns (Segment *state,
}
/**
* apply_match:
* can_apply_match:
*
* @state: the current state of the parser.
* @line_starts_at: beginning offset of the line.
* @line: the line to analyze.
* @line_pos: the position inside @line.
* @line_length: the length of @line.
* @regex: regex that matched.
* @match_start: start position of match.
* @match_end: where to put end of match.
* @where: kind of sub patterns to apply.
*
* Moves @line_pos after the matched text. @line_pos is not
* updated and the function returns %FALSE if the match cannot be
* applied beacuse an ancestor ends in the middle of the matched
* text.
* See apply_match(), this function is a helper function
* called from where, it doesn't modify syntax tree.
*
* If the match can be applied the function applies the appropriate
* sub patterns.
*
* Return value: %TRUE if the match can be applied.
* Returns: %TRUE if the match can be applied.
*/
static gboolean
can_apply_match (Context *state,
@ -2850,6 +2915,24 @@ can_apply_match (Context *state,
return TRUE;
}
/**
* apply_match:
*
* @state: the current state of the parser.
* @line: the line to analyze.
* @regex: regex that matched.
* @where: kind of sub patterns to apply.
*
* Moves @line_pos after the matched text. @line_pos is not
* updated and the function returns %FALSE if the match cannot be
* applied because an ancestor ends in the middle of the matched
* text.
*
* If the match can be applied the function applies the appropriate
* sub patterns.
*
* Returns: %TRUE if the match can be applied.
*/
static gboolean
apply_match (Segment *state,
LineInfo *line,
@ -2871,6 +2954,26 @@ apply_match (Segment *state,
return TRUE;
}
/**
* create_reg_all:
*
* @context: context.
* @definition: context definition.
*
* Creates regular expression for all possible transitions: it
* combines terminating regex, terminating regexes of parent
* contexts if those can terminate this one, and start regexes
* of child contexts.
*
* It takes as an argument actual context or a context definition. In
* case when context end depends on start (\%{foo@start} references),
* it must use the context, definition is not enough. If there are no
* those references, then the reg_all is created right in the definition
* when no contexts exist yet. This is why this function has its funny
* arguments.
*
* Returns: resulting regex or %NULL when pcre failed to compile the regex.
*/
static Regex *
create_reg_all (Context *context,
ContextDefinition *definition)
@ -2920,6 +3023,9 @@ create_reg_all (Context *context,
{
gboolean append = TRUE;
/* Code as it is seems to be right, and seems working right.
* Remove FIXME's below if everything is fine. */
if (tmp->parent->end != NULL)
g_string_append (all, regex_get_pattern (tmp->parent->end));
/* FIXME ?
@ -2981,14 +3087,12 @@ create_reg_all (Context *context,
if (regex == NULL)
{
/* regex_new could fail, for instance if there are different
* named sub-patterns with the same name. */
/* FIXME: this error also happens when some patterns are screwed up,
* and printing error here actually helps. But the "for all the transitions"
* part is questionable (and one would want to fix it in any case, even
* if all patterns are correct). */
g_warning ("Cannot create a regex for all the transitions, "
"the syntax highlighting process will be slower "
"than usual.\nThe error was: %s", error->message);
* named sub-patterns with the same name or if resulting regex is
* too long. In this case fixing lang file helps (e.g. renaming
* subpatterns, making huge keywords use bigger prefixes, etc.) */
g_warning (_("Cannot create a regex for all the transitions, "
"the syntax highlighting process will be slower "
"than usual.\nThe error was: %s"), error->message);
g_error_free (error);
}
@ -3207,6 +3311,9 @@ context_freeze_hash_cb (G_GNUC_UNUSED gpointer text,
* and decrement it when we are done with analysis, so no more needed
* contexts go away. Keeping a list of referenced contexts is painful
* or slow, so we just reference all contexts present at the moment.
*
* Note this is not reentrant, context_freeze()/context_thaw() pair is called
* only from update_syntax().
*/
static void
context_freeze (Context *ctx)
@ -3246,7 +3353,7 @@ get_child_contexts_hash_cb (G_GNUC_UNUSED gpointer text,
* @context: the context.
*
* Recursively decrements reference count in context and its children,
* if it was incremented by context_freeze.
* if it was incremented by context_freeze().
*/
static void
context_thaw (Context *ctx)
@ -3349,8 +3456,8 @@ create_child_context (Context *parent,
* segment_new:
*
* @ce: the engine.
* @parent: parent segment (NULL for the root segment).
* @context: context for this segment (NULL for invalid segments).
* @parent: parent segment (%NULL for the root segment).
* @context: context for this segment (%NULL for invalid segments).
* @start_at: start offset.
* @end_at: end offset.
* @is_start: is_start flag.
@ -3457,7 +3564,7 @@ find_segment_position_backward_ (Segment *segment,
/**
* find_segment_position:
*
* @parent: parent segment (not NULL).
* @parent: parent segment (not %NULL).
* @hint: segment somewhere near new segment position.
* @start_at: start offset.
* @end_at: end offset.
@ -3511,8 +3618,8 @@ find_segment_position (Segment *parent,
* create_segment:
*
* @ce: the engine.
* @parent: parent segment (NULL for the root segment).
* @context: context for this segment (NULL for invalid segments).
* @parent: parent segment (%NULL for the root segment).
* @context: context for this segment (%NULL for invalid segments).
* @start_at: start offset.
* @end_at: end offset.
* @is_start: is_start flag.
@ -3741,7 +3848,6 @@ simple_context_starts_here (GtkSourceContextEngine *ce,
{
gint match_end;
Context *new_context;
Segment *new_segment;
ContextDefinition *definition = child_def->u.definition;
g_return_val_if_fail (definition->u.match != NULL, FALSE);
@ -3754,27 +3860,54 @@ simple_context_starts_here (GtkSourceContextEngine *ce,
new_context = create_child_context (state->context, child_def, line->text);
g_return_val_if_fail (new_context != NULL, FALSE);
if (!can_apply_match (new_context, line, *line_pos, &match_end, definition->u.match) ||
/* if length of the match is zero, then we get zero-length segment and return to
* the same state, so it's an infinite loop */
*line_pos == match_end)
if (!can_apply_match (new_context, line, *line_pos, &match_end, definition->u.match))
{
context_unref (new_context);
return FALSE;
}
/* If length of the match is zero, then we get zero-length segment and return to
* the same state, so it's an infinite loop. But, if this child ends parent, we
* do want to terminate parent. Still, if match is at the beginning of the parent
* then we get an infinite loop again, so we check that (FIXME it really should destroy
* parent context then, but then we again can get parent context be recreated here and
* so on) */
if (*line_pos == match_end &&
(!CONTEXT_ENDS_PARENT (new_context) || *line_pos == state->start_at))
{
context_unref (new_context);
return FALSE;
}
g_assert (match_end <= line->length);
segment_extend (state, line->start_at + match_end);
new_segment = create_segment (ce, state, new_context,
line->start_at + *line_pos,
line->start_at + match_end,
TRUE,
ce->priv->hint2);
apply_sub_patterns (new_segment, line, definition->u.match, SUB_PATTERN_WHERE_DEFAULT);
if (*line_pos != match_end)
{
/* Normal non-zero-length match, create a child segment */
Segment *new_segment;
new_segment = create_segment (ce, state, new_context,
line->start_at + *line_pos,
line->start_at + match_end,
TRUE,
ce->priv->hint2);
apply_sub_patterns (new_segment, line, definition->u.match, SUB_PATTERN_WHERE_DEFAULT);
ce->priv->hint2 = new_segment;
}
/* Terminate parent if needed */
if (CONTEXT_ENDS_PARENT (new_context))
{
do
{
ce->priv->hint2 = state;
state = state->parent;
}
while (SEGMENT_ENDS_PARENT (state));
}
*line_pos = match_end;
*new_state = state;
ce->priv->hint2 = new_segment;
context_unref (new_context);
return TRUE;
}
@ -3793,7 +3926,7 @@ simple_context_starts_here (GtkSourceContextEngine *ce,
* @line_pos in @line. If the contexts start here @new_state and
* @line_pos are updated.
*
* Return value: %TRUE if the context starts here.
* Returns: %TRUE if the context starts here.
*/
static gboolean
child_starts_here (GtkSourceContextEngine *ce,
@ -3862,7 +3995,7 @@ segment_ends_here (Segment *state,
* This function only checks conetxts and does not modify the tree,
* it's used by ancestor_ends_here().
*
* Return value: the ancestor context that terminates here or NULL.
* Returns: the ancestor context that terminates here or %NULL.
*/
static Context *
ancestor_context_ends_here (Context *state,
@ -3922,11 +4055,11 @@ ancestor_context_ends_here (Context *state,
* @new_state: where to store the new state.
*
* Verifies if some ancestor context ends at given position. If
* state changed and @new_state is not NULL, then the new state is stored
* state changed and @new_state is not %NULL, then the new state is stored
* in @new_state, and descendants of @new_state are closed, so the
* terminating segment becomes current state.
*
* Return value: %TRUE if an ancestor ends at the given position.
* Returns: %TRUE if an ancestor ends at the given position.
*/
static gboolean
ancestor_ends_here (Segment *state,
@ -3968,7 +4101,7 @@ ancestor_ends_here (Segment *state,
* Verifies if a context starts or ends in @line at @line_pos of after it.
* If the contexts starts or ends here @new_state and @line_pos are updated.
*
* Return value: %FALSE is there are no more contexts in @line.
* Returns: %FALSE is there are no more contexts in @line.
*/
static gboolean
next_segment (GtkSourceContextEngine *ce,
@ -4077,7 +4210,10 @@ next_segment (GtkSourceContextEngine *ce,
if (apply_match (state, line, &pos, state->context->end, SUB_PATTERN_WHERE_END))
{
g_assert (pos <= line->length);
/* FIXME: if child may terminate parent */
while (SEGMENT_ENDS_PARENT (state))
state = state->parent;
*new_state = state->parent;
ce->priv->hint2 = state;
*line_pos = pos;
@ -4101,7 +4237,7 @@ next_segment (GtkSourceContextEngine *ce,
* Closes the contexts that cannot contain end of lines if needed.
* Updates hint if new state is different from @state.
*
* Return value: the new state.
* Returns: the new state.
*/
static Segment *
check_line_end (GtkSourceContextEngine *ce,
@ -4210,7 +4346,7 @@ delete_zero_length_segments (GtkSourceContextEngine *ce,
*
* Finds contexts at the line and updates the syntax tree on it.
*
* Return value: starting state at the next line.
* Returns: starting state at the next line.
*/
static Segment *
analyze_line (GtkSourceContextEngine *ce,
@ -4572,7 +4708,7 @@ get_segment_ (Segment *segment,
* get_segment_at_offset:
*
* @ce: #GtkSoucreContextEngine.
* @hint: segment to start search from or NULL.
* @hint: segment to start search from or %NULL.
* @offset: the offset.
*
* Finds the deepest segment "at @offset".
@ -5061,11 +5197,11 @@ erase_segments (GtkSourceContextEngine *ce,
* update_syntax:
*
* @ce: #GtkSourceContextEngine.
* @end: desired end of region to analyze or NULL.
* @end: desired end of region to analyze or %NULL.
* @time: maximal amount of time in milliseconds allowed to spend here
* or 0 for 'unlimited'.
*
* Updates syntax tree. If @end is not NULL, then it analyzes
* Updates syntax tree. If @end is not %NULL, then it analyzes
* (reanalyzes invalid areas in) region from start of buffer
* to @end. Otherwise, it analyzes batch of text starting at
* first invalid line.
@ -5073,7 +5209,7 @@ erase_segments (GtkSourceContextEngine *ce,
* when time elapsed is greater than @time, so analyzed region is
* not necessarily what's requested (unless @time is 0).
*/
/* XXX it needs to be refactored. */
/* XXX it must be refactored. */
static void
update_syntax (GtkSourceContextEngine *ce,
const GtkTextIter *end,
@ -5201,6 +5337,8 @@ update_syntax (GtkSourceContextEngine *ce,
#endif
/* XXX this is wrong */
/* I don't know anymore why it's wrong, I guess it means
* "may be inefficient" */
if (ce->priv->hint2 != NULL)
ce->priv->hint = ce->priv->hint2;
else
@ -5356,7 +5494,7 @@ context_definition_new (const gchar *id,
const gchar *start,
const gchar *end,
const gchar *style,
GtkSourceContextMatchOptions options,
GtkSourceContextFlags flags,
GError **error)
{
ContextDefinition *definition;
@ -5426,7 +5564,7 @@ context_definition_new (const gchar *id,
g_set_error (error,
GTK_SOURCE_CONTEXT_ENGINE_ERROR,
GTK_SOURCE_CONTEXT_ENGINE_ERROR_INVALID_START_REF,
"context '%s' cannot contain a \\%%{...@start} command",
_("context '%s' cannot contain a \\%%{...@start} command"),
id);
regex_error = TRUE;
}
@ -5440,7 +5578,7 @@ context_definition_new (const gchar *id,
definition->id = g_strdup (id);
definition->default_style = g_strdup (style);
definition->type = type;
definition->match_options = options;
definition->flags = flags;
definition->children = NULL;
definition->sub_patterns = NULL;
definition->n_sub_patterns = 0;
@ -5550,7 +5688,7 @@ _gtk_source_context_data_define_context (GtkSourceContextData *ctx_data,
const gchar *start_regex,
const gchar *end_regex,
const gchar *style,
GtkSourceContextMatchOptions options,
GtkSourceContextFlags flags,
GError **error)
{
ContextDefinition *definition, *parent = NULL;
@ -5569,7 +5707,7 @@ _gtk_source_context_data_define_context (GtkSourceContextData *ctx_data,
g_set_error (error,
GTK_SOURCE_CONTEXT_ENGINE_ERROR,
GTK_SOURCE_CONTEXT_ENGINE_ERROR_DUPLICATED_ID,
"duplicated context id '%s'", id);
_("duplicated context id '%s'"), id);
return FALSE;
}
@ -5596,7 +5734,8 @@ _gtk_source_context_data_define_context (GtkSourceContextData *ctx_data,
g_set_error (error,
GTK_SOURCE_CONTEXT_ENGINE_ERROR,
GTK_SOURCE_CONTEXT_ENGINE_ERROR_INVALID_ARGS,
"insufficient or redunduant arguments creating "
/* do not translate, parser should take care of this */
"insufficient or redundant arguments creating "
"the context '%s'", id);
return FALSE;
}
@ -5613,7 +5752,7 @@ _gtk_source_context_data_define_context (GtkSourceContextData *ctx_data,
definition = context_definition_new (id, type, match_regex,
start_regex, end_regex, style,
options, error);
flags, error);
if (definition == NULL)
return FALSE;
@ -5652,7 +5791,7 @@ _gtk_source_context_data_add_sub_pattern (GtkSourceContextData *ctx_data,
g_set_error (error,
GTK_SOURCE_CONTEXT_ENGINE_ERROR,
GTK_SOURCE_CONTEXT_ENGINE_ERROR_DUPLICATED_ID,
"duplicated context id '%s'", id);
_("duplicated context id '%s'"), id);
return FALSE;
}
@ -5679,6 +5818,7 @@ _gtk_source_context_data_add_sub_pattern (GtkSourceContextData *ctx_data,
g_set_error (error,
GTK_SOURCE_CONTEXT_ENGINE_ERROR,
GTK_SOURCE_CONTEXT_ENGINE_ERROR_INVALID_WHERE,
/* do not translate, parent takes care of this */
"invalid location ('%s') for sub pattern '%s'",
where, id);
return FALSE;
@ -5751,7 +5891,8 @@ _gtk_source_context_data_add_ref (GtkSourceContextData *ctx_data,
g_set_error (error,
GTK_SOURCE_CONTEXT_ENGINE_ERROR,
GTK_SOURCE_CONTEXT_ENGINE_ERROR_INVALID_PARENT,
_("invalid parent type for the context '%s'"),
/* do not translate, parent takes care of this */
"invalid parent type for the context '%s'",
ref_id);
return FALSE;
}
@ -5823,8 +5964,8 @@ resolve_reference (G_GNUC_UNUSED const gchar *id,
{
g_set_error (&data->error, GTK_SOURCE_CONTEXT_ENGINE_ERROR,
GTK_SOURCE_CONTEXT_ENGINE_ERROR_INVALID_STYLE,
"style override used with wildcard context reference"
" in language '%s' in ref '%s'",
_("style override used with wildcard context reference"
" in language '%s' in ref '%s'"),
data->ctx_data->lang->priv->id, ref->id);
}
else
@ -5837,7 +5978,7 @@ resolve_reference (G_GNUC_UNUSED const gchar *id,
{
g_set_error (&data->error, GTK_SOURCE_CONTEXT_ENGINE_ERROR,
GTK_SOURCE_CONTEXT_ENGINE_ERROR_INVALID_REF,
"invalid reference '%s'", child_def->u.id);
_("invalid reference '%s'"), child_def->u.id);
}
}
}
@ -5857,7 +5998,7 @@ resolve_reference (G_GNUC_UNUSED const gchar *id,
* May be called any number of times, must be called after parsing is
* done.
*
* Return value: TRUE on success, FALSE if there were unresolved
* Returns: %TRUE on success, %FALSE if there were unresolved
* references.
*/
gboolean

View File

@ -54,10 +54,12 @@ struct _GtkSourceContextEngineClass
typedef enum {
GTK_SOURCE_CONTEXT_EXTEND_PARENT = 1 << 0,
GTK_SOURCE_CONTEXT_END_AT_LINE_END = 1 << 1,
GTK_SOURCE_CONTEXT_FIRST_LINE_ONLY = 1 << 2,
GTK_SOURCE_CONTEXT_ONCE_ONLY = 1 << 3
} GtkSourceContextMatchOptions;
GTK_SOURCE_CONTEXT_END_PARENT = 1 << 1,
GTK_SOURCE_CONTEXT_END_AT_LINE_END = 1 << 2,
GTK_SOURCE_CONTEXT_FIRST_LINE_ONLY = 1 << 3,
GTK_SOURCE_CONTEXT_ONCE_ONLY = 1 << 4,
GTK_SOURCE_CONTEXT_STYLE_INSIDE = 1 << 5
} GtkSourceContextFlags;
typedef enum {
GTK_SOURCE_CONTEXT_IGNORE_STYLE = 1 << 0,
@ -80,7 +82,7 @@ gboolean _gtk_source_context_data_define_context
const gchar *start_regex,
const gchar *end_regex,
const gchar *style,
GtkSourceContextMatchOptions options,
GtkSourceContextFlags flags,
GError **error);
gboolean _gtk_source_context_data_add_sub_pattern

View File

@ -99,7 +99,7 @@ ctx_data_add_syntax_pattern (GtkSourceContextData *ctx_data,
gchar *real_id, *root_id;
gchar *fixed_start, *fixed_end;
GError *error = NULL;
GtkSourceContextMatchOptions options = GTK_SOURCE_CONTEXT_EXTEND_PARENT;
GtkSourceContextFlags flags = GTK_SOURCE_CONTEXT_EXTEND_PARENT;
g_return_val_if_fail (id != NULL, FALSE);
@ -110,14 +110,14 @@ ctx_data_add_syntax_pattern (GtkSourceContextData *ctx_data,
fixed_end = fix_pattern (pattern_end, &end_at_line_end);
if (end_at_line_end)
options |= GTK_SOURCE_CONTEXT_END_AT_LINE_END;
flags |= GTK_SOURCE_CONTEXT_END_AT_LINE_END;
result = _gtk_source_context_data_define_context (ctx_data, real_id, root_id,
NULL,
pattern_start,
pattern_end,
style,
options,
flags,
&error);
if (error != NULL)

View File

@ -76,14 +76,15 @@ struct _ParserState
GHashTable *defined_regexes;
/* The mapping between style ids and their default styles.
* If lang file contains this:
* If lang file 'mama' contains this:
* <style id="foo" map-to="def:blah"/>
* <style id="bar"/>
* then in styles_mapping: "foo"->"def:blah", "bar"->"bar". */
* then in styles_mapping: "mama:foo"->"def:blah", "mama:bar"->"mama:bar". */
GHashTable *styles_mapping;
/* The list of loaded languages (the item are XmlChar pointers) */
GSList **loaded_lang_ids;
/* The list of loaded languages (the item are xmlChar pointers),
* mapping is id -> id */
GHashTable *loaded_lang_ids;
/* A serial number incremented to get unique generated names */
guint id_cookie;
@ -111,7 +112,7 @@ static ParserState *parser_state_new (GtkSourceLanguage *language
GHashTable *defined_regexes,
GHashTable *styles_mapping,
xmlTextReader *reader,
GSList **loaded_lang_ids);
GHashTable *loaded_lang_ids);
static void parser_state_destroy (ParserState *parser_state);
static gboolean file_parse (gchar *filename,
@ -119,7 +120,7 @@ static gboolean file_parse (gchar *filename
GtkSourceContextData *ctx_data,
GHashTable *defined_regexes,
GHashTable *styles,
GSList **loaded_lang_ids,
GHashTable *loaded_lang_ids,
GError **error);
static EggRegexCompileFlags
@ -194,34 +195,18 @@ id_is_decorated (const gchar *id,
/* This function is quite simple because the XML validator check for
* the correctness of the id with a regex */
gchar **tokens;
gboolean is_decorated;
const gchar *colon;
gboolean is_decorated = FALSE;
tokens = g_strsplit (id, ":", 2);
colon = strchr (id, ':');
g_return_val_if_fail (tokens != NULL, FALSE);
if (tokens [1] == NULL)
{
/* There is no ":" in the id */
is_decorated = FALSE;
}
else if (tokens [1] != NULL && strcmp ("*", tokens[1]) == 0)
{
/* This is an undecorated "import all", and not a decorated
* reference */
is_decorated = FALSE;
}
else
if (colon != NULL && strcmp ("*", colon + 1) != 0)
{
is_decorated = TRUE;
if (lang_id != NULL)
{
*lang_id = g_strdup (tokens[0]);
}
}
g_strfreev (tokens);
if (lang_id != NULL)
*lang_id = g_strndup (id, colon - id);
}
return is_decorated;
}
@ -243,23 +228,7 @@ decorate_id (ParserState *parser_state,
static gboolean
lang_id_is_already_loaded (ParserState *parser_state, gchar *lang_id)
{
GSList *l;
gchar *loaded_lang;
l = *(parser_state->loaded_lang_ids);
g_return_val_if_fail (lang_id != NULL, FALSE);
while (l != NULL)
{
loaded_lang = l->data;
if (strcmp (loaded_lang, lang_id) == 0)
{
return TRUE;
}
l = g_slist_next (l);
}
return FALSE;
return g_hash_table_lookup (parser_state->loaded_lang_ids, lang_id) != NULL;
}
@ -293,20 +262,27 @@ get_regex_flags (xmlNode *node,
return flags;
}
static GtkSourceContextMatchOptions
check_context_options (ParserState *parser_state,
GtkSourceContextMatchOptions options)
static GtkSourceContextFlags
get_context_flags (ParserState *parser_state)
{
guint i;
xmlChar *value;
GtkSourceContextFlags flags = GTK_SOURCE_CONTEXT_EXTEND_PARENT;
const gchar *names[] = {
"extend-parent", "end-at-line-end", "first-line-only", "once-only"
"extend-parent", "end-parent", "end-at-line-end",
"first-line-only", "once-only", "style-inside"
};
GtkSourceContextMatchOptions flags[] = {
GTK_SOURCE_CONTEXT_EXTEND_PARENT, GTK_SOURCE_CONTEXT_END_AT_LINE_END,
GTK_SOURCE_CONTEXT_FIRST_LINE_ONLY, GTK_SOURCE_CONTEXT_ONCE_ONLY
GtkSourceContextFlags values[] = {
GTK_SOURCE_CONTEXT_EXTEND_PARENT,
GTK_SOURCE_CONTEXT_END_PARENT,
GTK_SOURCE_CONTEXT_END_AT_LINE_END,
GTK_SOURCE_CONTEXT_FIRST_LINE_ONLY,
GTK_SOURCE_CONTEXT_ONCE_ONLY,
GTK_SOURCE_CONTEXT_STYLE_INSIDE
};
g_assert (G_N_ELEMENTS (names) == G_N_ELEMENTS (values));
for (i = 0; i < G_N_ELEMENTS (names); ++i)
{
value = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST names[i]);
@ -314,15 +290,15 @@ check_context_options (ParserState *parser_state,
if (value != NULL)
{
if (str_to_bool (value))
options |= flags[i];
flags |= values[i];
else
options &= ~flags[i];
flags &= ~values[i];
}
xmlFree (value);
}
return options;
return flags;
}
static gboolean
@ -334,7 +310,7 @@ create_definition (ParserState *parser_state,
{
gchar *match = NULL, *start = NULL, *end = NULL;
gchar *prefix = NULL, *suffix = NULL;
GtkSourceContextMatchOptions options;
GtkSourceContextFlags flags;
xmlNode *context_node, *child;
@ -348,7 +324,7 @@ create_definition (ParserState *parser_state,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
options = check_context_options (parser_state, GTK_SOURCE_CONTEXT_EXTEND_PARENT);
flags = get_context_flags (parser_state);
DEBUG (g_message ("creating context %s, child of %s", id, parent_id ? parent_id : "(null)"));
@ -496,7 +472,7 @@ create_definition (ParserState *parser_state,
start,
end,
style,
options,
flags,
&tmp_error);
g_free (match);
@ -718,6 +694,7 @@ handle_context_element (ParserState *parser_state,
g_warning ("style-ref and ignore-style used simultaneously");
}
/* XXX */
if (!ignore_style && style_ref != NULL &&
g_hash_table_lookup (parser_state->styles_mapping, style_ref) == NULL)
{
@ -821,10 +798,8 @@ handle_language_element (ParserState *parser_state,
lang_id = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "id");
parser_state->current_lang_id = g_strdup ((gchar *)lang_id);
*(parser_state->loaded_lang_ids) = g_slist_prepend (
*(parser_state->loaded_lang_ids), lang_id);
parser_state->current_lang_id = g_strdup ((gchar *) lang_id);
g_hash_table_insert (parser_state->loaded_lang_ids, lang_id, lang_id);
xmlFree (lang_version);
}
@ -1298,46 +1273,6 @@ handle_default_regex_options_element (ParserState *parser_state,
xmlFree (options);
}
static void
map_style (ParserState *parser_state,
gchar *style_id,
gchar *map_to,
GError **error)
{
const gchar *real_map_to;
g_return_if_fail (error != NULL && *error == NULL);
g_return_if_fail (style_id != NULL);
if (map_to != NULL)
{
if (g_hash_table_lookup (parser_state->styles_mapping, map_to) != NULL)
real_map_to = map_to;
else
real_map_to = NULL;
}
else
{
real_map_to = style_id;
}
DEBUG (g_message ("mapping the style of '%s' to '%s' -> '%s'",
style_id,
map_to ? map_to : "(null)",
mapped_style));
if (real_map_to != NULL)
g_hash_table_insert (parser_state->styles_mapping,
g_strdup (style_id),
g_strdup (real_map_to));
else
g_set_error (error,
PARSER_ERROR,
PARSER_ERROR_WRONG_ID,
"unable to map style '%s' to '%s'",
style_id, map_to);
}
static void
parse_language_with_id (ParserState *parser_state,
gchar *lang_id,
@ -1403,6 +1338,7 @@ parse_style (ParserState *parser_state,
name = xmlTextReaderGetAttribute (parser_state->reader,
BAD_CAST "_name");
/* FIXME: actually use this name somehow */
if (name != NULL)
{
tmp = xmlStrdup (BAD_CAST dgettext (parser_state->language->priv->translation_domain,
@ -1441,7 +1377,8 @@ parse_style (ParserState *parser_state,
name, id, map_to ? (char*) map_to : "(null)"));
if (tmp_error == NULL)
map_style (parser_state, id, (gchar*) map_to, &tmp_error);
g_hash_table_insert (parser_state->styles_mapping, g_strdup (id),
map_to ? g_strdup ((char*) map_to) : g_strdup (id));
g_free (lang_id);
g_free (id);
@ -1612,7 +1549,7 @@ file_parse (gchar *filename,
GtkSourceContextData *ctx_data,
GHashTable *defined_regexes,
GHashTable *styles,
GSList **loaded_lang_ids,
GHashTable *loaded_lang_ids,
GError **error)
{
ParserState *parser_state;
@ -1715,7 +1652,7 @@ parser_state_new (GtkSourceLanguage *language,
GHashTable *defined_regexes,
GHashTable *styles_mapping,
xmlTextReader *reader,
GSList **loaded_lang_ids)
GHashTable *loaded_lang_ids)
{
ParserState *parser_state;
parser_state = g_new (ParserState, 1);
@ -1780,8 +1717,7 @@ _gtk_source_language_file_parse_version2 (GtkSourceLanguage *language,
gboolean success;
GError *error = NULL;
gchar *filename;
GSList *loaded_lang_ids = NULL;
GSList *l;
GHashTable *loaded_lang_ids;
g_return_val_if_fail (ctx_data != NULL, FALSE);
@ -1800,10 +1736,13 @@ _gtk_source_language_file_parse_version2 (GtkSourceLanguage *language,
g_free, g_free);
styles = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
loaded_lang_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) xmlFree,
NULL);
success = file_parse (filename, language, ctx_data,
defined_regexes, styles,
&loaded_lang_ids, &error);
loaded_lang_ids, &error);
if (success)
success = _gtk_source_context_data_resolve_refs (ctx_data, &error);
@ -1813,12 +1752,7 @@ _gtk_source_language_file_parse_version2 (GtkSourceLanguage *language,
(GHRFunc) steal_styles_mapping,
language->priv->styles);
for (l = loaded_lang_ids; l != NULL; l = l->next)
{
xmlFree (l->data);
}
g_slist_free (loaded_lang_ids);
g_hash_table_destroy (loaded_lang_ids);
g_hash_table_destroy (defined_regexes);
g_hash_table_destroy (styles);

View File

@ -384,7 +384,7 @@ process_language_node (xmlTextReaderPtr reader, const gchar *filename)
*
* Returns the ID of the language. The ID is not locale-dependent.
*
* Return value: the ID of @language, it must be freed it with g_free.
* Returns: the ID of @language, it must be freed it with g_free.
**/
gchar *
gtk_source_language_get_id (GtkSourceLanguage *language)
@ -401,7 +401,7 @@ gtk_source_language_get_id (GtkSourceLanguage *language)
*
* Returns the localized name of the language.
*
* Return value: the name of @language.
* Returns: the name of @language.
**/
gchar *
gtk_source_language_get_name (GtkSourceLanguage *language)
@ -420,7 +420,7 @@ gtk_source_language_get_name (GtkSourceLanguage *language)
* Each language belong to a section (ex. HTML belogs to the
* Markup section).
*
* Return value: the section of @language.
* Returns: the section of @language.
**/
gchar *
gtk_source_language_get_section (GtkSourceLanguage *language)
@ -431,57 +431,14 @@ gtk_source_language_get_section (GtkSourceLanguage *language)
return g_strdup (language->priv->section);
}
gint
gtk_source_language_get_version (GtkSourceLanguage *language)
{
g_return_val_if_fail (GTK_IS_SOURCE_LANGUAGE (language), 0);
return language->priv->version;
}
/**
* gtk_source_language_get_mime_types:
* @language: a #GtkSourceLanguage.
*
* Returns a list of mime types for the given @language. After usage you should
* free each element of the list as well as the list itself.
*
* Return value: a list of mime types (strings).
**/
GSList *
gtk_source_language_get_mime_types (GtkSourceLanguage *language)
{
const gchar *prop;
gchar **mtl;
gint i;
GSList *list = NULL;
g_return_val_if_fail (GTK_IS_SOURCE_LANGUAGE (language), NULL);
prop = gtk_source_language_get_property (language, "mimetypes");
if (!prop)
return NULL;
mtl = g_strsplit_set (prop, ";,", 0);
for (i = 0; mtl[i] != NULL; i++)
/* steal the strings from the array */
list = g_slist_prepend (list, mtl[i]);
g_free (mtl);
return g_slist_reverse (list);
}
/**
* gtk_source_language_get_property:
*
* @language: a #GtkSourceLanguage.
* @name: property name.
*
* Returns value of property %name if it's set in the lang file
* and NULL otherwise.
* Returns: value of property %name if it's set in @language
* and %NULL otherwise.
**/
const gchar *
gtk_source_language_get_property (GtkSourceLanguage *language,
@ -497,9 +454,7 @@ gtk_source_language_get_property (GtkSourceLanguage *language,
* _gtk_source_language_get_languages_manager:
* @language: a #GtkSourceLanguage.
*
* Returns the #GtkSourceLanguagesManager for the #GtkSourceLanguage.
*
* Return value: #GtkSourceLanguagesManager for @language.
* Returns: #GtkSourceLanguagesManager for @language.
**/
GtkSourceLanguagesManager *
_gtk_source_language_get_languages_manager (GtkSourceLanguage *language)

View File

@ -57,10 +57,7 @@ gchar *gtk_source_language_get_id (GtkSourceLanguage *language);
gchar *gtk_source_language_get_name (GtkSourceLanguage *language);
gchar *gtk_source_language_get_section (GtkSourceLanguage *language);
gint gtk_source_language_get_version (GtkSourceLanguage *language);
/* Should free the list (and free each string in it also). */
GSList *gtk_source_language_get_mime_types (GtkSourceLanguage *language);
const gchar *gtk_source_language_get_property (GtkSourceLanguage *language,
const gchar *name);

View File

@ -39,6 +39,7 @@ enum {
struct _GtkSourceLanguagesManagerPrivate
{
GHashTable *language_ids;
GSList *available_languages;
GSList *language_specs_directories;
char *rng_file;
@ -142,7 +143,7 @@ gtk_source_languages_manager_init (GtkSourceLanguagesManager *lm)
*
* Creates a new language manager.
*
* Return value: a #GtkSourceLanguagesManager.
* Returns: a #GtkSourceLanguagesManager.
**/
GtkSourceLanguagesManager *
gtk_source_languages_manager_new (void)
@ -157,6 +158,9 @@ gtk_source_languages_manager_finalize (GObject *object)
lm = GTK_SOURCE_LANGUAGES_MANAGER (object);
if (lm->priv->language_ids)
g_hash_table_destroy (lm->priv->language_ids);
g_slist_foreach (lm->priv->available_languages, (GFunc) g_object_unref, NULL);
g_slist_free (lm->priv->available_languages);
slist_deep_free (lm->priv->language_specs_directories);
@ -234,7 +238,7 @@ gtk_source_languages_manager_set_specs_dirs (GtkSourceLanguagesManager *lm,
*
* Gets a list of language files directories for the given language manager.
*
* Return value: a list of language files directories (as strings).
* Returns: a list of language files directories (as strings).
**/
const GSList *
gtk_source_languages_manager_get_lang_files_dirs (GtkSourceLanguagesManager *lm)
@ -291,114 +295,61 @@ prepend_lang (G_GNUC_UNUSED gchar *id,
g_slist_prepend (lm->priv->available_languages, lang);
}
static void
ensure_languages (GtkSourceLanguagesManager *lm)
{
GSList *filenames, *l;
if (lm->priv->language_ids != NULL)
return;
/* Build list of availables languages */
filenames = get_lang_files (lm);
lm->priv->language_ids = g_hash_table_new (g_str_hash, g_str_equal);
for (l = filenames; l != NULL; l = l->next)
{
GtkSourceLanguage *lang;
const gchar *filename;
filename = l->data;
lang = _gtk_source_language_new_from_file (filename, lm);
if (lang == NULL)
{
g_warning ("Error reading language specification file '%s'", filename);
continue;
}
if (g_hash_table_lookup (lm->priv->language_ids, lang->priv->id) == NULL)
g_hash_table_insert (lm->priv->language_ids,
lang->priv->id,
lang);
else
g_object_unref (lang);
}
g_hash_table_foreach (lm->priv->language_ids, (GHFunc) prepend_lang, lm);
slist_deep_free (filenames);
}
/**
* gtk_source_languages_manager_get_available_languages:
* @lm: a #GtkSourceLanguagesManager.
*
* Gets a list of available languages for the given language manager.
* This function returns a pointer to a internal list, so there is no need to
* free it after usage.
*
* Return value: a list of #GtkSourceLanguage.
* Returns: a list of #GtkSourceLanguage. Return value is owned by @lm and should
* not be modified or freed.
**/
const GSList *
gtk_source_languages_manager_get_available_languages (GtkSourceLanguagesManager *lm)
{
GSList *filenames, *l;
GHashTable *lang_hash;
g_return_val_if_fail (GTK_IS_SOURCE_LANGUAGES_MANAGER (lm), NULL);
if (lm->priv->available_languages != NULL)
{
return lm->priv->available_languages;
}
/* Build list of availables languages */
filenames = get_lang_files (lm);
lang_hash = g_hash_table_new (g_str_hash, g_str_equal);
for (l = filenames; l != NULL; l = l->next)
{
GtkSourceLanguage *lang;
lang = _gtk_source_language_new_from_file ((const gchar*)l->data,
lm);
if (lang == NULL)
{
g_warning ("Error reading language specification file '%s'",
(const gchar*)l->data);
continue;
}
if (g_hash_table_lookup (lang_hash, lang->priv->id) == NULL)
{
g_hash_table_insert (lang_hash,
lang->priv->id,
lang);
}
}
slist_deep_free (filenames);
g_hash_table_foreach (lang_hash, (GHFunc) prepend_lang, lm);
g_hash_table_destroy (lang_hash);
ensure_languages (lm);
return lm->priv->available_languages;
}
/**
* gtk_source_languages_manager_get_language_for_mime_type:
* @lm: a #GtkSourceLanguagesManager.
* @mime_type: a mime type.
*
* Gets the #GtkSourceLanguage which is associated with the given @mime_type
* in the language manager.
*
* Return value: a #GtkSourceLanguage, or %NULL if there is no language
* associated with the given @mime_type.
**/
/* FIXME use hash table here */
GtkSourceLanguage *
gtk_source_languages_manager_get_language_for_mime_type (GtkSourceLanguagesManager *lm,
const gchar *mime_type)
{
const GSList *languages;
g_return_val_if_fail (mime_type != NULL, NULL);
languages = gtk_source_languages_manager_get_available_languages (lm);
while (languages != NULL)
{
GSList *mime_types, *tmp;
GtkSourceLanguage *lang = GTK_SOURCE_LANGUAGE (languages->data);
tmp = mime_types = gtk_source_language_get_mime_types (lang);
while (tmp != NULL)
{
if (strcmp ((const gchar*)tmp->data, mime_type) == 0)
{
break;
}
tmp = g_slist_next (tmp);
}
slist_deep_free (mime_types);
if (tmp != NULL)
return lang;
languages = g_slist_next (languages);
}
return NULL;
}
/**
* gtk_source_languages_manager_get_language_by_id:
* @lm: a #GtkSourceLanguagesManager.
@ -407,41 +358,17 @@ gtk_source_languages_manager_get_language_for_mime_type (GtkSourceLanguagesManag
* Gets the #GtkSourceLanguage identified by the given @id in the language
* manager.
*
* Return value: a #GtkSourceLanguage, or %NULL if there is no language
* identified by the given @id.
* Returns: a #GtkSourceLanguage, or %NULL if there is no language
* identified by the given @id. Return value is owned by @lm and should not
* be freed.
**/
GtkSourceLanguage *
gtk_source_languages_manager_get_language_by_id (GtkSourceLanguagesManager *lm,
const gchar *id)
{
const GSList *languages;
gboolean found = FALSE;
g_return_val_if_fail (id != NULL, NULL);
languages = gtk_source_languages_manager_get_available_languages (lm);
while (languages != NULL)
{
gchar *lang_id;
GtkSourceLanguage *lang = GTK_SOURCE_LANGUAGE (languages->data);
lang_id = gtk_source_language_get_id (lang);
if (lang_id != NULL && (strcmp (lang_id, id) == 0))
{
found = TRUE;
}
g_free (lang_id);
if (found)
return lang;
languages = g_slist_next (languages);
}
return NULL;
ensure_languages (lm);
return g_hash_table_lookup (lm->priv->language_ids, id);
}
static GSList *

View File

@ -63,9 +63,6 @@ const GSList *gtk_source_languages_manager_get_available_languages (GtkSourceLan
GtkSourceLanguage *gtk_source_languages_manager_get_language_by_id (GtkSourceLanguagesManager *lm,
const gchar *id);
GtkSourceLanguage *gtk_source_languages_manager_get_language_for_mime_type
(GtkSourceLanguagesManager *lm,
const gchar *mime_type);
/* Property */
const GSList *gtk_source_languages_manager_get_lang_files_dirs (GtkSourceLanguagesManager *lm);

View File

@ -25,7 +25,7 @@ gtk_source_style_get_type (void)
{
static GType type;
if (type == 0)
if (G_UNLIKELY (type == 0))
type = g_boxed_type_register_static ("GtkSourceStyle",
(GBoxedCopyFunc) gtk_source_style_copy,
(GBoxedFreeFunc) gtk_source_style_free);
@ -33,6 +33,15 @@ gtk_source_style_get_type (void)
return type;
}
/**
* gtk_source_style_new:
* @mask: a #GtkSourceStyleMask which defines what fields will be used.
*
* Returns: newly allocated #GtkSourceStyle structure, free with
* gtk_source_style_free().
*
* Since: 2.0
*/
GtkSourceStyle *
gtk_source_style_new (GtkSourceStyleMask mask)
{
@ -41,18 +50,46 @@ gtk_source_style_new (GtkSourceStyleMask mask)
return style;
}
/**
* gtk_source_style_copy:
* @style: a #GtkSourceStyle structure to copy.
*
* Returns: copy of @style, free it with gtk_source_style_free().
*
* Since: 2.0
*/
GtkSourceStyle *
gtk_source_style_copy (const GtkSourceStyle *style)
{
return g_memdup (style, sizeof (GtkSourceStyle));
}
/**
* gtk_source_style_free:
* @style: a #GtkSourceStyle structure to free.
*
* Frees #GtkSourceStyle structure allocated with gtk_source_style_new() or
* gtk_source_style_copy().
*
* Since: 2.0
*/
void
gtk_source_style_free (GtkSourceStyle *style)
{
g_free (style);
}
/**
* _gtk_source_style_apply:
* @style: a #GtkSourceStyle to apply.
* @tag: a #GtkTextTag to apply styles to.
*
* Applies text styles set in @style if it's not %NULL, or
* unsets style fields in @tag set with _gtk_source_style_apply()
* if @style is %NULL.
*
* Since: 2.0
*/
void
_gtk_source_style_apply (const GtkSourceStyle *style,
GtkTextTag *tag)

View File

@ -130,6 +130,14 @@ gtk_source_style_scheme_class_init (GtkSourceStyleSchemeClass *klass)
object_class->set_property = gtk_source_style_scheme_set_property;
object_class->get_property = gtk_source_style_scheme_get_property;
/**
* GtkSourceStyleScheme:id:
*
* Style scheme id, a unique string used to identify the style scheme
* in #GtkSourceStyleManager.
*
* Since: 2.0
*/
g_object_class_install_property (object_class,
PROP_ID,
g_param_spec_string ("id",
@ -138,6 +146,13 @@ gtk_source_style_scheme_class_init (GtkSourceStyleSchemeClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/**
* GtkSourceStyleScheme:name:
*
* Style scheme name, a translatable string to present to user.
*
* Since: 2.0
*/
g_object_class_install_property (object_class,
PROP_NAME,
g_param_spec_string ("name",
@ -158,6 +173,14 @@ gtk_source_style_scheme_init (GtkSourceStyleScheme *scheme)
(GDestroyNotify) gtk_source_style_free);
}
/**
* gtk_source_style_scheme_get_id:
* @scheme: a #GtkSourceStyleScheme.
*
* Returns: @scheme id.
*
* Since: 2.0
*/
const gchar *
gtk_source_style_scheme_get_id (GtkSourceStyleScheme *scheme)
{
@ -166,6 +189,14 @@ gtk_source_style_scheme_get_id (GtkSourceStyleScheme *scheme)
return scheme->priv->id;
}
/**
* gtk_source_style_scheme_get_name:
* @scheme: a #GtkSourceStyleScheme.
*
* Returns: @scheme name.
*
* Since: 2.0
*/
const gchar *
gtk_source_style_scheme_get_name (GtkSourceStyleScheme *scheme)
{
@ -174,6 +205,15 @@ gtk_source_style_scheme_get_name (GtkSourceStyleScheme *scheme)
return scheme->priv->name;
}
/**
* _gtk_source_style_scheme_new:
* @id: scheme id.
* @name: scheme name.
*
* Returns: new empty #GtkSourceStyleScheme.
*
* Since: 2.0
*/
GtkSourceStyleScheme *
_gtk_source_style_scheme_new (const gchar *id,
const gchar *name)
@ -189,6 +229,17 @@ _gtk_source_style_scheme_new (const gchar *id,
return scheme;
}
/**
* gtk_source_style_scheme_get_style:
* @scheme: a #GtkSourceStyleScheme.
* @style_name: style name to find.
*
* Returns: style which corresponds to @style_name in the @scheme,
* or %NULL when no style with this name found. Free it with
* gtk_source_style_free().
*
* Since: 2.0
*/
GtkSourceStyle *
gtk_source_style_scheme_get_style (GtkSourceStyleScheme *scheme,
const gchar *style_name)
@ -210,6 +261,14 @@ gtk_source_style_scheme_get_style (GtkSourceStyleScheme *scheme,
return NULL;
}
/**
* gtk_source_style_scheme_set_style:
* @scheme: a #GtkSourceStyleScheme.
* @name: style name.
* @style: style to set or %NULL.
*
* Since: 2.0
*/
void
gtk_source_style_scheme_set_style (GtkSourceStyleScheme *scheme,
const gchar *name,
@ -225,6 +284,15 @@ gtk_source_style_scheme_set_style (GtkSourceStyleScheme *scheme,
g_hash_table_remove (scheme->priv->styles, name);
}
/**
* gtk_source_style_scheme_get_matching_brackets_style:
* @scheme: a #GtkSourceStyleScheme.
*
* Returns: style which corresponds to "bracket-match" name, to use
* in an editor. Free it with gtk_source_style_free().
*
* Since: 2.0
*/
GtkSourceStyle *
gtk_source_style_scheme_get_matching_brackets_style (GtkSourceStyleScheme *scheme)
{
@ -232,6 +300,16 @@ gtk_source_style_scheme_get_matching_brackets_style (GtkSourceStyleScheme *schem
return gtk_source_style_scheme_get_style (scheme, STYLE_BRACKET_MATCH);
}
/**
* gtk_source_style_scheme_get_current_line_color:
* @scheme: a #GtkSourceStyleScheme.
* @color: a #GdkColor structure to fill.
*
* Returns: %TRUE if @scheme has style for current line set, or %FALSE
* otherwise.
*
* Since: 2.0
*/
gboolean
gtk_source_style_scheme_get_current_line_color (GtkSourceStyleScheme *scheme,
GdkColor *color)
@ -290,6 +368,15 @@ set_cursor_color (GtkWidget *widget,
g_print ("implement me\n");
}
/**
* _gtk_source_style_scheme_apply:
* @scheme: a #GtkSourceStyleScheme.
* @widget: a #GtkWidget to apply styles to.
*
* Sets text colors from @scheme in the @widget.
*
* Since: 2.0
*/
void
_gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
GtkWidget *widget)
@ -575,6 +662,15 @@ end_element (G_GNUC_UNUSED GMarkupParseContext *context,
data->done = TRUE;
}
/**
* _gtk_source_style_scheme_new_from_file:
* @filename: file to parse.
*
* Returns: new #GtkSourceStyleScheme created from file, or
* %NULL on error.
*
* Since: 2.0
*/
GtkSourceStyleScheme *
_gtk_source_style_scheme_new_from_file (const gchar *filename)
{
@ -615,6 +711,14 @@ _gtk_source_style_scheme_new_from_file (const gchar *filename)
return data.scheme;
}
/**
* _gtk_source_style_scheme_get_parent_id:
* @scheme: a #GtkSourceStyleScheme.
*
* Returns: parent style scheme id or %NULL.
*
* Since: 2.0
*/
const gchar *
_gtk_source_style_scheme_get_parent_id (GtkSourceStyleScheme *scheme)
{
@ -622,6 +726,17 @@ _gtk_source_style_scheme_get_parent_id (GtkSourceStyleScheme *scheme)
return scheme->priv->parent_id;
}
/**
* _gtk_source_style_scheme_set_parent:
* @scheme: a #GtkSourceStyleScheme.
* @parent_scheme: parent #GtkSourceStyleScheme for @scheme.
*
* Sets @parent_scheme as parent scheme for @scheme, @scheme will
* look for styles in @parent_scheme if it doesn't have style set
* for given name.
*
* Since: 2.0
*/
void
_gtk_source_style_scheme_set_parent (GtkSourceStyleScheme *scheme,
GtkSourceStyleScheme *parent_scheme)
@ -636,6 +751,13 @@ _gtk_source_style_scheme_set_parent (GtkSourceStyleScheme *scheme,
scheme->priv->parent = parent_scheme;
}
/**
* _gtk_source_style_scheme_default_new:
*
* Returns: new default style scheme. Not clear what it means though.
*
* Since: 2.0
*/
GtkSourceStyleScheme *
_gtk_source_style_scheme_default_new (void)
{

View File

@ -58,7 +58,7 @@ const gchar *gtk_source_style_scheme_get_name (GtkSourceStyleS
/* Return value must be freed with gtk_source_style_free */
GtkSourceStyle *gtk_source_style_scheme_get_style (GtkSourceStyleScheme *scheme,
const gchar *style);
const gchar *style_name);
GtkSourceStyle *gtk_source_style_scheme_get_matching_brackets_style
(GtkSourceStyleScheme *scheme);
gboolean gtk_source_style_scheme_get_current_line_color

View File

@ -1,3 +1,4 @@
#!/bin/sh
# -%- strip: true; indent-width: 2 -%-
if test -z "$1"; then

View File

@ -61,7 +61,7 @@
<context id="comment" style-ref="comment" end-at-line-end="true">
<start>\/\/</start>
<include>
<context ref="def:line-comment"/>
<context ref="def:in-line-comment"/>
</include>
</context>
@ -69,7 +69,7 @@
<start>\/\*</start>
<end>\*\/</end>
<include>
<context ref="def:comment:*"/>
<context ref="def:in-comment"/>
</include>
</context>
@ -89,6 +89,7 @@
<end>\%{preproc-start}endif\b</end>
<include>
<context ref="if-in-if0"/>
<context ref="def:in-comment"/>
</include>
</context>
</include>
@ -97,7 +98,7 @@
<context id="include" style-ref="preprocessor">
<match extended="true">
\%{preproc-start}
include\s*
(include|import)\s*
(".*?"|&lt;.*&gt;)
</match>
<include>

View File

@ -68,7 +68,7 @@
<keyword>__cplusplus</keyword>
</context>
<context ref="c:c:*"/>
<context ref="c:c"/>
</include>
</context>

View File

@ -77,7 +77,7 @@
\%] # separator
</define-regex>
<context id="comment">
<context id="in-comment">
<include>
<context id="net-address" extend-parent="false" style-ref="net-address-in-comment">
<match>\%{net-address}</match>
@ -98,10 +98,10 @@
<!-- this is intended to be used from line comments starting not with #,
see shell-like-comment below -->
<context id="line-comment">
<context id="in-line-comment">
<include>
<context ref="line-continue" ignore-style="true"/>
<context ref="comment"/>
<context ref="in-comment"/>
</include>
</context>
@ -109,7 +109,7 @@
<context id="shell-like-comment" style-ref="comment" end-at-line-end="true">
<start>#</start>
<include>
<context ref="line-comment"/>
<context ref="in-line-comment"/>
</include>
</context>

View File

@ -23,7 +23,7 @@
<context id="line-comment" style-ref="comment" end-at-line-end="true">
<start>#</start>
<include>
<context ref="def:comment:*"/>
<context ref="def:in-comment"/>
</include>
</context>
@ -119,7 +119,7 @@
<include>
<context ref="line-comment"/>
<context ref="group"/>
<context ref="key:*"/>
<context ref="key"/>
<context id="lang-and-value" end-at-line-end="true">
<start>(\[[a-zA-Z_]+\])?\s*=\s*</start>
<include>

View File

@ -42,7 +42,6 @@
<start>^((@@)|[0-9]|\*\*\*\*)</start>
<include>
<context ref="def:escape"/>
<context ref="def:line-continue"/>
</include>
</context>

View File

@ -10,6 +10,7 @@
<style id="type" _name="property-name" map-to="def:keyword"/>
<style id="function" _name="property-name" map-to="def:keyword"/>
<style id="return" _name="property-name" map-to="def:keyword"/>
<style id="since" _name="property-name" map-to="def:keyword"/>
</styles>
<definitions>
@ -20,7 +21,7 @@
<context id="inline-docs-body">
<include>
<context ref="skip-asterisk"/>
<context ref="def:comment"/>
<context ref="def:in-comment"/>
<context style-ref="parameter">
<match>\@[\w_]+</match>
</context>
@ -34,13 +35,16 @@
<match>[\w_]+\(\s*\)</match>
</context>
<context style-ref="return">
<match>Returns\:</match>
<match>(Returns|Return value)\:</match>
</context>
<context style-ref="since">
<match>Since\:</match>
</context>
</include>
</context>
<context id="inline-docs" style-ref="inline-docs">
<start>\/\*\*</start>
<start>\/\*\*(?!\S)</start>
<end>\*\/</end>
<include>
<context ref="skip-asterisk"/>

View File

@ -88,7 +88,7 @@
<start>&lt;!--</start>
<end>--&gt;</end>
<include>
<context ref="def:comment:*"/>
<context ref="def:in-comment"/>
</include>
</context>
@ -106,12 +106,12 @@
<include>
<context sub-pattern="0" where="start" style-ref="tag"/>
<context sub-pattern="0" where="end" style-ref="tag"/>
<context ref="generic-tag:*"/>
<context ref="generic-tag"/>
<context id="js-code" extend-parent="false">
<start>&gt;</start>
<include>
<context sub-pattern="0" where="start" style-ref="tag"/>
<context ref="js:js:*"/>
<context ref="js:js"/>
</include>
</context>
</include>
@ -123,7 +123,7 @@
<include>
<context sub-pattern="0" where="start" style-ref="tag"/>
<context sub-pattern="0" where="end" style-ref="tag"/>
<context ref="generic-tag:*"/>
<context ref="generic-tag"/>
</include>
</context>

View File

@ -46,7 +46,7 @@
<context id="comment-continue">
<match>\\\n</match>
</context>
<context ref="def:comment:*"/>
<context ref="def:in-comment"/>
</include>
</context>
@ -54,7 +54,7 @@
<start>\/\*</start>
<end>\*\/</end>
<include>
<context ref="def:comment:*"/>
<context ref="def:in-comment"/>
</include>
</context>

View File

@ -9,7 +9,7 @@
<style name="Others 3" foreground="#008000"/>
<style name="def:string" foreground="#DD0000"/>
<style name="def:comment" foreground="#808080" italic="true"/>
<style name="def:comment" foreground="#808080" italic="true" bold="false"/>
<style name="def:base-n-integer" foreground="#008080"/>
<style name="def:complex" use-style="def:base-n-integer"/>
<style name="def:keyword" bold="true"/>
@ -52,8 +52,13 @@
<style name="mooscript:special-vars" use-style="c:preprocessor"/>
<style name="latex:math" foreground="#008000"/>
<style name="latex:inline-math" foreground="#008000"/>
<style name="latex:display-math" background="#C0FFC0"/>
<style name="latex:inline-math" foreground="DarkGreen"/>
<style name="latex:math-bound" bold="true"/>
<style name="latex:common-commands" foreground="#800000"/>
<style name="latex:command" foreground="#7000DF"/>
<style name="latex:structure" bold="true"/>
<style name="latex:section" foreground="#7000DF" bold="true"/>
<style name="changelog:release" foreground="#0095ff" bold="true"/>

View File

@ -184,6 +184,11 @@
<ref name="boolean-value"/>
</attribute>
</optional>
<optional>
<attribute name="end-parent">
<ref name="boolean-value"/>
</attribute>
</optional>
<optional>
<attribute name="first-line-only">
<ref name="boolean-value"/>
@ -236,11 +241,21 @@
<ref name="id-type"/>
</attribute>
</optional>
<optional>
<attribute name="style-inside">
<ref name="boolean-value"/>
</attribute>
</optional>
<optional>
<attribute name="extend-parent">
<ref name="boolean-value"/>
</attribute>
</optional>
<optional>
<attribute name="end-parent">
<ref name="boolean-value"/>
</attribute>
</optional>
<optional>
<attribute name="end-at-line-end">
<ref name="boolean-value"/>

View File

@ -1,23 +1,247 @@
<?xml version="1.0"?>
<language id="latex" _name="LaTeX" version="2.0" _section="Markup">
<metadata>
<property name="mimetypes">text/x-tex</property>
<property name="globs">*.tex;*.ltx;*.sty;*.cls;*.dtx;*.ins</property>
<property name="line-comment-start">%</property>
</metadata>
<metadata>
<property name="mimetypes">text/x-tex</property>
<property name="globs">*.tex;*.ltx;*.sty;*.cls;*.dtx;*.ins</property>
<property name="line-comment-start">%</property>
</metadata>
<styles>
<style id="comment" _name="Comment" map-to="def:comment"/>
<style id="inline-math" _name="Inline Math Mode"/>
<style id="math" _name="Math Mode"/>
<style id="include" _name="Include" map-to="def:keyword"/>
<style id="most-used-commands" _name="Command" map-to="def:keyword"/>
<style id="command" _name="Command" map-to="def:keyword"/>
<style id="verbatim" _name="Verbatim" map-to="def:comment"/>
</styles>
<styles>
<style id="comment" _name="Comment" map-to="def:comment"/>
<style id="documentclass" _name="Comment" map-to="def:keyword"/>
<style id="usepackage" _name="Comment" map-to="def:keyword"/>
<style id="newcommand" _name="Comment" map-to="def:keyword"/>
<style id="display-math" _name="Math Mode"/>
<style id="inline-math" _name="Inline Math Mode" map-to="latex:display-math"/>
<style id="structure" _name="Inline Math Mode"/>
<style id="section" _name="Inline Math Mode"/>
<definitions>
<context id="most-used-commands" style-ref="most-used-commands">
<!-- <style id="math" _name="Math Mode"/>-->
<!-- <style id="inline-math" _name="Inline Math Mode" map-to="latex:math"/>-->
<!-- <style id="math-bound" _name="math-bound"/>-->
<!-- <style id="include" _name="Include" map-to="def:keyword"/>-->
<!-- <style id="common-commands" _name="Command" map-to="def:keyword"/>-->
<!-- <style id="command" _name="Command" map-to="def:keyword"/>-->
<!-- <style id="verbatim" _name="Verbatim" map-to="def:comment"/>-->
</styles>
<definitions>
<context id="comment" style-ref="comment" end-at-line-end="true">
<start>%</start>
<include>
<context ref="def:in-comment"/>
</include>
</context>
<context id="documentclass">
<start>\\documentclass\b</start>
<end>(?=\S)</end>
<include>
<context sub-pattern="0" where="start" style-ref="documentclass"/>
<context ref="comment"/>
<context once-only="true">
<start>\[</start>
<end>\]</end>
<include>
<context sub-pattern="0" where="start" style-ref="documentclass"/>
<context sub-pattern="0" where="end" style-ref="documentclass"/>
<context ref="comment"/>
<context extend-parent="false" style-ref="documentclass">
<match>[^%]+</match>
</context>
</include>
</context>
<context end-parent="true" end-at-line-end="true">
<start>\{</start>
<end>\}</end>
<include>
<context sub-pattern="0" where="start" style-ref="documentclass"/>
<context sub-pattern="0" where="end" style-ref="documentclass"/>
<context ref="comment"/>
<context extend-parent="false" style-ref="documentclass">
<match>[^%]+</match>
</context>
</include>
</context>
<context end-parent="true">
<match>(?=\S)</match>
</context>
</include>
</context>
<context id="usepackage">
<start>\\usepackage\b</start>
<end>(?=\S)</end>
<include>
<context sub-pattern="0" where="start" style-ref="usepackage"/>
<context ref="comment"/>
<context once-only="true" style-ref="usepackage">
<start>\[</start>
<end>\]</end>
<include>
<context sub-pattern="0" where="start" style-ref="usepackage"/>
<context sub-pattern="0" where="end" style-ref="usepackage"/>
<context ref="comment"/>
<context extend-parent="false" style-ref="usepackage">
<match>[^%]+</match>
</context>
</include>
</context>
<context end-parent="true">
<start>\{</start>
<end>\}</end>
<include>
<context sub-pattern="0" where="start" style-ref="usepackage"/>
<context sub-pattern="0" where="end" style-ref="usepackage"/>
<context ref="comment"/>
<context extend-parent="false" style-ref="usepackage">
<match>[^%]+</match>
</context>
</include>
</context>
<context end-parent="true">
<match>(?=\S)</match>
</context>
</include>
</context>
<context id="newcommand">
<start>\\(re)?newcommand\b</start>
<include>
<context sub-pattern="0" where="start" style-ref="newcommand"/>
<context sub-pattern="0" where="end" style-ref="def:error"/>
<context ref="comment"/>
<context once-only="true" end-at-line-end="true">
<start>\{</start>
<end>\}</end>
<include>
<context sub-pattern="0" where="start" style-ref="newcommand"/>
<context sub-pattern="0" where="end" style-ref="newcommand"/>
<context ref="comment"/>
<context style-ref="newcommand">
<match>\\[a-zA-Z]*</match>
</context>
<context extend-parent="false" style-ref="def:error">
<match>\S</match>
</context>
</include>
</context>
<context once-only="true" end-at-line-end="true">
<start>\[</start>
<end>\]</end>
<include>
<context sub-pattern="0" where="start" style-ref="newcommand"/>
<context sub-pattern="0" where="end" style-ref="newcommand"/>
<context ref="comment"/>
<context extend-parent="false" style-ref="newcommand">
<match>[^%]+</match>
</context>
</include>
</context>
<context end-parent="true">
<start>\{</start>
<end>\}</end>
<include>
<context sub-pattern="0" where="start" style-ref="newcommand"/>
<context sub-pattern="0" where="end" style-ref="newcommand"/>
<context ref="comment"/>
<context ref="latex-text-mode"/>
<context ref="latex-math-mode"/>
</include>
</context>
<context end-parent="true">
<match>(?=\S)</match>
</context>
</include>
</context>
<context id="preamble">
<include>
<context ref="comment"/>
</include>
</context>
<context id="structure">
<include>
<context ref="comment"/>
<context style-ref="structure">
<match>(\\(begin|end)\{)(document)(\})</match>
<include>
<context sub-pattern="3" style-ref="section"/>
</include>
</context>
<context style-ref="structure">
<start>\\(sub)*section\*?</start>
<include>
<context ref="comment"/>
<context end-parent="true" style-ref="section" style-inside="true">
<start>\{</start>
<end>\}</end>
<include>
<context ref="latex-text-mode"/>
</include>
</context>
<context end-parent="true" style-ref="section">
<match>\S</match>
</context>
</include>
</context>
</include>
</context>
<context id="environment">
<start>\\begin\b</start>
<include>
<context ref="comment"/>
<context once-only="true">
<start>\{</start>
<end>\}</end>
<include>
<context ref="comment"/>
</include>
</context>
</include>
</context>
<context id="latex-text-mode">
<include>
<context ref="comment"/>
<context id="display-math" style-ref="display-math">
<start>\$\$</start>
<end>\$\$</end>
<include>
<context ref="latex-math-mode"/>
</include>
</context>
<context id="inline-math" style-ref="inline-math">
<start>\$</start>
<end>\$</end>
<include>
<context ref="latex-math-mode"/>
</include>
</context>
</include>
</context>
<context id="latex-math-mode">
<include>
<context ref="comment"/>
</include>
</context>
<context id="latex">
<include>
<context ref="comment"/>
<context ref="documentclass"/>
<context ref="usepackage"/>
<context ref="newcommand"/>
<context ref="preamble"/>
<context ref="structure"/>
<context ref="latex-text-mode"/>
</include>
</context>
<!-- <context id="common-commands" style-ref="common-commands">
<prefix>\\</prefix>
<keyword>begin</keyword>
@ -80,7 +304,7 @@
<start>%</start>
<end>$</end>
<include>
<context ref="def:comment:*"/>
<context ref="def:in-comment"/>
</include>
</context>
@ -88,7 +312,7 @@
<start>\\begin\{comment\}</start>
<end>\\end\{comment\}</end>
<include>
<context ref="def:comment:*"/>
<context ref="def:in-comment"/>
</include>
</context>
@ -96,7 +320,9 @@
<start>\$\$</start>
<end>\$\$</end>
<include>
<context ref="most-used-commands"/>
<context sub-pattern="0" where="start" style-ref="math-bound"/>
<context sub-pattern="0" where="end" style-ref="math-bound"/>
<context ref="common-commands"/>
<context ref="specials-symbol"/>
<context ref="command"/>
</include>
@ -106,7 +332,9 @@
<start>\$</start>
<end>\$</end>
<include>
<context ref="most-used-commands"/>
<context sub-pattern="0" where="start" style-ref="math-bound"/>
<context sub-pattern="0" where="end" style-ref="math-bound"/>
<context ref="common-commands"/>
<context ref="specials-symbol"/>
<context ref="command"/>
</include>
@ -141,10 +369,10 @@
<keyword>usepackage</keyword>
</context>
<context ref="most-used-commands"/>
<context ref="common-commands"/>
<context ref="specials-symbol"/>
<context ref="command"/>
</include>
</context>
</definitions>
</context>-->
</definitions>
</language>

View File

@ -40,7 +40,7 @@
<context id="m4-comment" style-ref="m4-comment" end-at-line-end="true">
<start>dnl</start>
<include>
<context ref="def:line-comment"/>
<context ref="def:in-line-comment"/>
</include>
</context>
@ -153,7 +153,7 @@
</context>
<context id="func-mmss">
<start>\b(AC_ARG_ENABLE|AC_ARG_WITH|PKG_CHECK_MODULES)\s*(\()</start>
<start>\b(AC_ARG_ENABLE|AC_ARG_WITH|AC_TRY_LINK|AC_TRY_COMPILE|AC_CHECK_LIB|PKG_CHECK_MODULES|)\s*(\()</start>
<end>\)</end>
<include>
<context sub-pattern="1" where="start" style-ref="ac-macro"/>
@ -164,7 +164,7 @@
</context>
<context id="func-mss">
<start>\b(AC_ENABLE|AC_WITH)\s*(\()</start>
<start>\b(AC_CONFIG_COMMANDS|AC_ENABLE|AC_WITH|AC_TRY_CPP|AC_CHECK_HEADER)\s*(\()</start>
<end>\)</end>
<include>
<context sub-pattern="1" where="start" style-ref="ac-macro"/>

View File

@ -11,7 +11,7 @@
<start>^(>>>|\.\.\.)\ </start>
<include>
<context sub-pattern="1" where="start" style-ref="ps"/>
<context ref="python:python:*"/>
<context ref="python:python"/>
</include>
</context>
</include>

View File

@ -109,7 +109,7 @@
<start>`</start>
<end>`</end>
<include>
<context ref="python:*"/>
<context ref="python"/>
</include>
</context>

View File

@ -34,20 +34,8 @@
</context>
<context id="attribute" style-ref="attribute-value">
<start>((\%{prefix}:)?\%{name}\s*=\s*)"</start>
<end>"</end>
<include>
<context sub-pattern="1" where="start" style-ref="attribute-name" />
<context sub-pattern="2" where="start" style-ref="namespace" />
<context ref="entity"/>
<context ref="unallowed-chars"/>
</include>
</context>
<!-- FIXME: having almost identical "attribute" and "attribute2" is not nice -->
<context id="attribute2" style-ref="attribute-value">
<start>((\%{prefix}:)?\%{name}\s*=\s*)'</start>
<end>'</end>
<start>((\%{prefix}:)?\%{name}\s*=\s*)(["'])</start>
<end>\%{3@start}</end>
<include>
<context sub-pattern="1" where="start" style-ref="attribute-name" />
<context sub-pattern="2" where="start" style-ref="namespace" />
@ -63,7 +51,7 @@
<context style-ref="error" extend-parent="false">
<match>--+</match>
</context>
<context ref="def:comment:*"/>
<context ref="def:in-comment"/>
</include>
</context>
@ -117,7 +105,6 @@
<context sub-pattern="0" where="start" style-ref="processing-instruction"/>
<context sub-pattern="0" where="end" style-ref="processing-instruction"/>
<context ref="attribute"/>
<context ref="attribute2"/>
</include>
</context>
@ -145,7 +132,6 @@
<context sub-pattern="0" where="end" style-ref="tags" />
<context ref="attribute"/>
<context ref="attribute2"/>
<context id="tag-internal">
<!-- This matches the internal portion

View File

@ -21,7 +21,7 @@
<include>
<context sub-pattern="0" where="start" style-ref="inline-c" />
<context sub-pattern="0" where="end" style-ref="inline-c" />
<context ref="c:c:*"/>
<context ref="c:c"/>
</include>
</context>

View File

@ -26,19 +26,19 @@
(gtype-id "MOO_TYPE_INDENTER")
)
;; (define-object LangMgr
;; (in-module "Moo")
;; (parent "GObject")
;; (c-name "MooLangMgr")
;; (gtype-id "MOO_TYPE_LANG_MGR")
;; )
;;
;; (define-object Lang
;; (in-module "Moo")
;; (parent "GObject")
;; (c-name "MooLangMgr")
;; (gtype-id "MOO_TYPE_LANG_MGR")
;; )
(define-object LangMgr
(in-module "Moo")
(parent "GObject")
(c-name "MooLangMgr")
(gtype-id "MOO_TYPE_LANG_MGR")
)
(define-object Lang
(in-module "Moo")
(parent "GObject")
(c-name "MooLang")
(gtype-id "MOO_TYPE_LANG")
)
(define-object TextBuffer
(in-module "Moo")
@ -687,23 +687,23 @@
)
)
(define-method get_lang_for_filename
(of-object "MooLangMgr")
(c-name "moo_lang_mgr_get_lang_for_filename")
(return-type "MooLang*")
(parameters
'("const-char*" "filename")
)
)
(define-method get_lang_for_mime_type
(of-object "MooLangMgr")
(c-name "moo_lang_mgr_get_lang_for_mime_type")
(return-type "MooLang*")
(parameters
'("const-char*" "mime_type")
)
)
; (define-method get_lang_for_filename
; (of-object "MooLangMgr")
; (c-name "moo_lang_mgr_get_lang_for_filename")
; (return-type "MooLang*")
; (parameters
; '("const-char*" "filename")
; )
; )
;
; (define-method get_lang_for_mime_type
; (of-object "MooLangMgr")
; (c-name "moo_lang_mgr_get_lang_for_mime_type")
; (return-type "MooLang*")
; (parameters
; '("const-char*" "mime_type")
; )
; )
(define-method get_lang
(of-object "MooLangMgr")