/* syntax_highlight.c generated by valac 0.56.19, the Vala compiler
 * generated from syntax_highlight.vala, do not modify */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gobject/gvaluecollector.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

typedef enum  {
	DC_CODE_THEME_ADAPTIVE = 0,
	DC_CODE_THEME_SOLARIZED = 1,
	DC_CODE_THEME_MONOKAI = 2,
	DC_CODE_THEME_NORD = 3,
	DC_CODE_THEME_NONE = 4
} DcCodeTheme;

#define DC_TYPE_CODE_THEME (dc_code_theme_get_type ())

#define DC_TYPE_SYNTAX_HIGHLIGHT (dc_syntax_highlight_get_type ())
#define DC_SYNTAX_HIGHLIGHT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_SYNTAX_HIGHLIGHT, DcSyntaxHighlight))
#define DC_SYNTAX_HIGHLIGHT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_SYNTAX_HIGHLIGHT, DcSyntaxHighlightClass))
#define DC_IS_SYNTAX_HIGHLIGHT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_SYNTAX_HIGHLIGHT))
#define DC_IS_SYNTAX_HIGHLIGHT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_SYNTAX_HIGHLIGHT))
#define DC_SYNTAX_HIGHLIGHT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_SYNTAX_HIGHLIGHT, DcSyntaxHighlightClass))

typedef struct _DcSyntaxHighlight DcSyntaxHighlight;
typedef struct _DcSyntaxHighlightClass DcSyntaxHighlightClass;
typedef struct _DcSyntaxHighlightPrivate DcSyntaxHighlightPrivate;

#define DC_SYNTAX_HIGHLIGHT_TYPE_PALETTE (dc_syntax_highlight_palette_get_type ())
typedef struct _DcSyntaxHighlightPalette DcSyntaxHighlightPalette;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
typedef struct _DcParamSpecSyntaxHighlight DcParamSpecSyntaxHighlight;

struct _DcSyntaxHighlight {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DcSyntaxHighlightPrivate * priv;
};

struct _DcSyntaxHighlightClass {
	GTypeClass parent_class;
	void (*finalize) (DcSyntaxHighlight *self);
};

struct _DcSyntaxHighlightPalette {
	gchar* keyword;
	gchar* type;
	gchar* func;
	gchar* str;
	gchar* num;
	gchar* comment;
	gchar* constant;
};

struct _DcParamSpecSyntaxHighlight {
	GParamSpec parent_instance;
};

static gpointer dc_syntax_highlight_parent_class = NULL;
VALA_EXTERN DcCodeTheme dc_syntax_highlight_theme;
DcCodeTheme dc_syntax_highlight_theme = DC_CODE_THEME_ADAPTIVE;
VALA_EXTERN gboolean dc_syntax_highlight_dark_mode;
gboolean dc_syntax_highlight_dark_mode = FALSE;

VALA_EXTERN GType dc_code_theme_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gpointer dc_syntax_highlight_ref (gpointer instance);
VALA_EXTERN void dc_syntax_highlight_unref (gpointer instance);
VALA_EXTERN GParamSpec* dc_param_spec_syntax_highlight (const gchar* name,
                                            const gchar* nick,
                                            const gchar* blurb,
                                            GType object_type,
                                            GParamFlags flags);
VALA_EXTERN void dc_value_set_syntax_highlight (GValue* value,
                                    gpointer v_object);
VALA_EXTERN void dc_value_take_syntax_highlight (GValue* value,
                                     gpointer v_object);
VALA_EXTERN gpointer dc_value_get_syntax_highlight (const GValue* value);
VALA_EXTERN GType dc_syntax_highlight_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcSyntaxHighlight, dc_syntax_highlight_unref)
VALA_EXTERN gchar* dc_syntax_highlight_highlight (const gchar* code);
static GType dc_syntax_highlight_palette_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static DcSyntaxHighlightPalette* dc_syntax_highlight_palette_dup (const DcSyntaxHighlightPalette* self);
static void dc_syntax_highlight_palette_free (DcSyntaxHighlightPalette* self);
static void dc_syntax_highlight_palette_copy (const DcSyntaxHighlightPalette* self,
                                       DcSyntaxHighlightPalette* dest);
static void dc_syntax_highlight_palette_destroy (DcSyntaxHighlightPalette* self);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (DcSyntaxHighlightPalette, dc_syntax_highlight_palette_destroy)
static void dc_syntax_highlight_current_palette (DcSyntaxHighlightPalette* result);
static gint dc_syntax_highlight_line_end (const gchar* code,
                                   gint start);
static gint dc_syntax_highlight_scan_string (const gchar* code,
                                      gint start);
static gboolean dc_syntax_highlight_is_digit (gchar c);
static gboolean dc_syntax_highlight_is_ident_char_at (const gchar* code,
                                               gint index);
static gint dc_syntax_highlight_scan_number (const gchar* code,
                                      gint start);
static gboolean dc_syntax_highlight_is_ident_start (gchar c);
static gboolean dc_syntax_highlight_is_ident_char (gchar c);
static gchar* dc_syntax_highlight_classify (const gchar* word,
                                     const gchar* code,
                                     gint end,
                                     DcSyntaxHighlightPalette* pal);
static void dc_syntax_highlight_append_span (GString* sb,
                                      const gchar* text,
                                      const gchar* color,
                                      gboolean italic);
static gboolean dc_syntax_highlight_is_alnum (gchar c);
VALA_EXTERN DcSyntaxHighlight* dc_syntax_highlight_new (void);
VALA_EXTERN DcSyntaxHighlight* dc_syntax_highlight_construct (GType object_type);
static void dc_syntax_highlight_finalize (DcSyntaxHighlight * obj);
static GType dc_syntax_highlight_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const gchar* DC_SYNTAX_HIGHLIGHT_KEYWORDS[105] = {"if", "else", "elif", "for", "while", "do", "switch", "case", "default", "break", "continue", "return", "goto", "new", "delete", "try", "catch", "finally", "throw", "throws", "class", "struct", "enum", "union", "interface", "protocol", "extension", "impl", "trait", "func", "function", "def", "fn", "var", "let", "const", "static", "public", "private", "protected", "internal", "open", "import", "export", "from", "package", "namespace", "using", "typedef", "sizeof", "typeof", "instanceof", "in", "of", "is", "as", "not", "and", "or", "async", "await", "yield", "lambda", "pass", "raise", "with", "except", "match", "guard", "defer", "init", "deinit", "override", "virtual", "abstract", "final", "extends", "implements", "module", "require", "global", "nonlocal", "assert", "del", "inline", "extern", "volatile", "register", "constexpr", "auto", "operator", "template", "ref", "out", "weak", "owned", "unowned", "construct", "mut", "pub", "unsafe", "where", "go", "chan", NULL};
static const gchar* DC_SYNTAX_HIGHLIGHT_TYPES[53] = {"void", "bool", "boolean", "char", "short", "int", "long", "float", "double", "byte", "unsigned", "signed", "string", "str", "object", "size_t", "ssize_t", "wchar_t", "uint", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "int8_t", "int16_t", "int32_t", "int64_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t", "i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", "f32", "f64", "usize", "isize", "number", "bigint", "any", "never", "unknown", NULL};
static const gchar* DC_SYNTAX_HIGHLIGHT_CONSTANTS[16] = {"true", "false", "True", "False", "null", "nullptr", "nil", "None", "NULL", "undefined", "NaN", "self", "this", "super", "Self", NULL};

/** Selectable palette family for code-block syntax highlighting. */
static GType
dc_code_theme_get_type_once (void)
{
	static const GEnumValue values[] = {{DC_CODE_THEME_ADAPTIVE, "DC_CODE_THEME_ADAPTIVE", "adaptive"}, {DC_CODE_THEME_SOLARIZED, "DC_CODE_THEME_SOLARIZED", "solarized"}, {DC_CODE_THEME_MONOKAI, "DC_CODE_THEME_MONOKAI", "monokai"}, {DC_CODE_THEME_NORD, "DC_CODE_THEME_NORD", "nord"}, {DC_CODE_THEME_NONE, "DC_CODE_THEME_NONE", "none"}, {0, NULL, NULL}};
	GType dc_code_theme_type_id;
	dc_code_theme_type_id = g_enum_register_static ("DcCodeTheme", values);
	return dc_code_theme_type_id;
}

GType
dc_code_theme_get_type (void)
{
	static volatile gsize dc_code_theme_type_id__once = 0;
	if (g_once_init_enter (&dc_code_theme_type_id__once)) {
		GType dc_code_theme_type_id;
		dc_code_theme_type_id = dc_code_theme_get_type_once ();
		g_once_init_leave (&dc_code_theme_type_id__once, dc_code_theme_type_id);
	}
	return dc_code_theme_type_id__once;
}

/**
         * Highlight raw (unescaped) code and return Pango markup. Every
         * emitted chunk is markup-escaped here, so callers must not escape
         * the result again.
         */
static gchar
string_get (const gchar* self,
            glong index)
{
	gchar _tmp0_;
	gchar result;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = ((gchar*) self)[index];
	result = _tmp0_;
	return result;
}

static gint
string_index_of (const gchar* self,
                 const gchar* needle,
                 gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = strstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

gchar*
dc_syntax_highlight_highlight (const gchar* code)
{
	DcSyntaxHighlightPalette pal = {0};
	DcSyntaxHighlightPalette _tmp1_ = {0};
	GString* sb = NULL;
	GString* _tmp2_;
	gint len = 0;
	gint _tmp3_;
	gint _tmp4_;
	gint plain_start = 0;
	gint i = 0;
	GString* _tmp50_;
	const gchar* _tmp51_;
	gchar* _tmp52_;
	gchar* result;
	g_return_val_if_fail (code != NULL, NULL);
	if (dc_syntax_highlight_theme == DC_CODE_THEME_NONE) {
		gchar* _tmp0_;
		_tmp0_ = g_markup_escape_text (code, (gssize) -1);
		result = _tmp0_;
		return result;
	}
	dc_syntax_highlight_current_palette (&_tmp1_);
	pal = _tmp1_;
	_tmp2_ = g_string_new ("");
	sb = _tmp2_;
	_tmp3_ = strlen (code);
	_tmp4_ = _tmp3_;
	len = _tmp4_;
	plain_start = 0;
	i = 0;
	while (TRUE) {
		gchar c = '\0';
		gint token_end = 0;
		gchar* color = NULL;
		gboolean italic = FALSE;
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		if (!(i < len)) {
			break;
		}
		c = string_get (code, (glong) i);
		token_end = -1;
		color = NULL;
		italic = FALSE;
		if (c == '/') {
			_tmp6_ = (i + 1) < len;
		} else {
			_tmp6_ = FALSE;
		}
		if (_tmp6_) {
			_tmp5_ = string_get (code, (glong) (i + 1)) == '/';
		} else {
			_tmp5_ = FALSE;
		}
		if (_tmp5_) {
			DcSyntaxHighlightPalette _tmp7_;
			const gchar* _tmp8_;
			gchar* _tmp9_;
			token_end = dc_syntax_highlight_line_end (code, i);
			_tmp7_ = pal;
			_tmp8_ = _tmp7_.comment;
			_tmp9_ = g_strdup (_tmp8_);
			_g_free0 (color);
			color = _tmp9_;
			italic = TRUE;
		} else {
			gboolean _tmp10_ = FALSE;
			gboolean _tmp11_ = FALSE;
			if (c == '/') {
				_tmp11_ = (i + 1) < len;
			} else {
				_tmp11_ = FALSE;
			}
			if (_tmp11_) {
				_tmp10_ = string_get (code, (glong) (i + 1)) == '*';
			} else {
				_tmp10_ = FALSE;
			}
			if (_tmp10_) {
				gint close = 0;
				gint _tmp12_ = 0;
				DcSyntaxHighlightPalette _tmp13_;
				const gchar* _tmp14_;
				gchar* _tmp15_;
				close = string_index_of (code, "*/", i + 2);
				if (close < 0) {
					_tmp12_ = len;
				} else {
					_tmp12_ = close + 2;
				}
				token_end = _tmp12_;
				_tmp13_ = pal;
				_tmp14_ = _tmp13_.comment;
				_tmp15_ = g_strdup (_tmp14_);
				_g_free0 (color);
				color = _tmp15_;
				italic = TRUE;
			} else {
				if (c == '#') {
					DcSyntaxHighlightPalette _tmp16_;
					const gchar* _tmp17_;
					gchar* _tmp18_;
					token_end = dc_syntax_highlight_line_end (code, i);
					_tmp16_ = pal;
					_tmp17_ = _tmp16_.comment;
					_tmp18_ = g_strdup (_tmp17_);
					_g_free0 (color);
					color = _tmp18_;
					italic = TRUE;
				} else {
					gboolean _tmp19_ = FALSE;
					gboolean _tmp20_ = FALSE;
					if (c == '"') {
						_tmp20_ = TRUE;
					} else {
						_tmp20_ = c == '\'';
					}
					if (_tmp20_) {
						_tmp19_ = TRUE;
					} else {
						_tmp19_ = c == '`';
					}
					if (_tmp19_) {
						DcSyntaxHighlightPalette _tmp21_;
						const gchar* _tmp22_;
						gchar* _tmp23_;
						token_end = dc_syntax_highlight_scan_string (code, i);
						_tmp21_ = pal;
						_tmp22_ = _tmp21_.str;
						_tmp23_ = g_strdup (_tmp22_);
						_g_free0 (color);
						color = _tmp23_;
					} else {
						gboolean _tmp24_ = FALSE;
						if (dc_syntax_highlight_is_digit (c)) {
							_tmp24_ = !dc_syntax_highlight_is_ident_char_at (code, i - 1);
						} else {
							_tmp24_ = FALSE;
						}
						if (_tmp24_) {
							DcSyntaxHighlightPalette _tmp25_;
							const gchar* _tmp26_;
							gchar* _tmp27_;
							token_end = dc_syntax_highlight_scan_number (code, i);
							_tmp25_ = pal;
							_tmp26_ = _tmp25_.num;
							_tmp27_ = g_strdup (_tmp26_);
							_g_free0 (color);
							color = _tmp27_;
						} else {
							if (dc_syntax_highlight_is_ident_start (c)) {
								gint end = 0;
								gchar* word = NULL;
								gchar* _tmp30_;
								const gchar* _tmp31_;
								DcSyntaxHighlightPalette _tmp32_;
								gchar* _tmp33_;
								const gchar* _tmp34_;
								end = i + 1;
								while (TRUE) {
									gboolean _tmp28_ = FALSE;
									gint _tmp29_;
									if (end < len) {
										_tmp28_ = dc_syntax_highlight_is_ident_char (string_get (code, (glong) end));
									} else {
										_tmp28_ = FALSE;
									}
									if (!_tmp28_) {
										break;
									}
									_tmp29_ = end;
									end = _tmp29_ + 1;
								}
								_tmp30_ = string_substring (code, (glong) i, (glong) (end - i));
								word = _tmp30_;
								_tmp31_ = word;
								_tmp32_ = pal;
								_tmp33_ = dc_syntax_highlight_classify (_tmp31_, code, end, &_tmp32_);
								_g_free0 (color);
								color = _tmp33_;
								_tmp34_ = color;
								if (_tmp34_ != NULL) {
									token_end = end;
								} else {
									i = end - 1;
								}
								_g_free0 (word);
							}
						}
					}
				}
			}
		}
		if (token_end > i) {
			GString* _tmp40_;
			gchar* _tmp41_;
			gchar* _tmp42_;
			const gchar* _tmp43_;
			if (plain_start < i) {
				GString* _tmp35_;
				gchar* _tmp36_;
				gchar* _tmp37_;
				gchar* _tmp38_;
				gchar* _tmp39_;
				_tmp35_ = sb;
				_tmp36_ = string_substring (code, (glong) plain_start, (glong) (i - plain_start));
				_tmp37_ = _tmp36_;
				_tmp38_ = g_markup_escape_text (_tmp37_, (gssize) -1);
				_tmp39_ = _tmp38_;
				g_string_append (_tmp35_, _tmp39_);
				_g_free0 (_tmp39_);
				_g_free0 (_tmp37_);
			}
			_tmp40_ = sb;
			_tmp41_ = string_substring (code, (glong) i, (glong) (token_end - i));
			_tmp42_ = _tmp41_;
			_tmp43_ = color;
			dc_syntax_highlight_append_span (_tmp40_, _tmp42_, _tmp43_, italic);
			_g_free0 (_tmp42_);
			i = token_end;
			plain_start = i;
		} else {
			gint _tmp44_;
			_tmp44_ = i;
			i = _tmp44_ + 1;
		}
		_g_free0 (color);
	}
	if (plain_start < len) {
		GString* _tmp45_;
		gchar* _tmp46_;
		gchar* _tmp47_;
		gchar* _tmp48_;
		gchar* _tmp49_;
		_tmp45_ = sb;
		_tmp46_ = string_substring (code, (glong) plain_start, (glong) (len - plain_start));
		_tmp47_ = _tmp46_;
		_tmp48_ = g_markup_escape_text (_tmp47_, (gssize) -1);
		_tmp49_ = _tmp48_;
		g_string_append (_tmp45_, _tmp49_);
		_g_free0 (_tmp49_);
		_g_free0 (_tmp47_);
	}
	_tmp50_ = sb;
	_tmp51_ = _tmp50_->str;
	_tmp52_ = g_strdup (_tmp51_);
	result = _tmp52_;
	_g_string_free0 (sb);
	dc_syntax_highlight_palette_destroy (&pal);
	return result;
}

static void
dc_syntax_highlight_current_palette (DcSyntaxHighlightPalette* result)
{
	switch (dc_syntax_highlight_theme) {
		case DC_CODE_THEME_SOLARIZED:
		{
			DcSyntaxHighlightPalette _tmp0_ = {0};
			DcSyntaxHighlightPalette _tmp17_;
			if (dc_syntax_highlight_dark_mode) {
				gchar* _tmp1_;
				gchar* _tmp2_;
				gchar* _tmp3_;
				gchar* _tmp4_;
				gchar* _tmp5_;
				gchar* _tmp6_;
				gchar* _tmp7_;
				DcSyntaxHighlightPalette _tmp8_ = {0};
				_tmp1_ = g_strdup ("#859900");
				_tmp2_ = g_strdup ("#b58900");
				_tmp3_ = g_strdup ("#268bd2");
				_tmp4_ = g_strdup ("#2aa198");
				_tmp5_ = g_strdup ("#d33682");
				_tmp6_ = g_strdup ("#586e75");
				_tmp7_ = g_strdup ("#cb4b16");
				memset (&_tmp8_, 0, sizeof (DcSyntaxHighlightPalette));
				_g_free0 (_tmp8_.keyword);
				_tmp8_.keyword = _tmp1_;
				_g_free0 (_tmp8_.type);
				_tmp8_.type = _tmp2_;
				_g_free0 (_tmp8_.func);
				_tmp8_.func = _tmp3_;
				_g_free0 (_tmp8_.str);
				_tmp8_.str = _tmp4_;
				_g_free0 (_tmp8_.num);
				_tmp8_.num = _tmp5_;
				_g_free0 (_tmp8_.comment);
				_tmp8_.comment = _tmp6_;
				_g_free0 (_tmp8_.constant);
				_tmp8_.constant = _tmp7_;
				dc_syntax_highlight_palette_destroy (&_tmp0_);
				_tmp0_ = _tmp8_;
			} else {
				gchar* _tmp9_;
				gchar* _tmp10_;
				gchar* _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				DcSyntaxHighlightPalette _tmp16_ = {0};
				_tmp9_ = g_strdup ("#859900");
				_tmp10_ = g_strdup ("#b58900");
				_tmp11_ = g_strdup ("#268bd2");
				_tmp12_ = g_strdup ("#2aa198");
				_tmp13_ = g_strdup ("#d33682");
				_tmp14_ = g_strdup ("#93a1a1");
				_tmp15_ = g_strdup ("#cb4b16");
				memset (&_tmp16_, 0, sizeof (DcSyntaxHighlightPalette));
				_g_free0 (_tmp16_.keyword);
				_tmp16_.keyword = _tmp9_;
				_g_free0 (_tmp16_.type);
				_tmp16_.type = _tmp10_;
				_g_free0 (_tmp16_.func);
				_tmp16_.func = _tmp11_;
				_g_free0 (_tmp16_.str);
				_tmp16_.str = _tmp12_;
				_g_free0 (_tmp16_.num);
				_tmp16_.num = _tmp13_;
				_g_free0 (_tmp16_.comment);
				_tmp16_.comment = _tmp14_;
				_g_free0 (_tmp16_.constant);
				_tmp16_.constant = _tmp15_;
				dc_syntax_highlight_palette_destroy (&_tmp0_);
				_tmp0_ = _tmp16_;
			}
			_tmp17_ = _tmp0_;
			memset (&_tmp0_, 0, sizeof (DcSyntaxHighlightPalette));
			*result = _tmp17_;
			dc_syntax_highlight_palette_destroy (&_tmp0_);
			return;
		}
		case DC_CODE_THEME_MONOKAI:
		{
			DcSyntaxHighlightPalette _tmp18_ = {0};
			DcSyntaxHighlightPalette _tmp35_;
			if (dc_syntax_highlight_dark_mode) {
				gchar* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				gchar* _tmp22_;
				gchar* _tmp23_;
				gchar* _tmp24_;
				gchar* _tmp25_;
				DcSyntaxHighlightPalette _tmp26_ = {0};
				_tmp19_ = g_strdup ("#f92672");
				_tmp20_ = g_strdup ("#66d9ef");
				_tmp21_ = g_strdup ("#a6e22e");
				_tmp22_ = g_strdup ("#e6db74");
				_tmp23_ = g_strdup ("#ae81ff");
				_tmp24_ = g_strdup ("#75715e");
				_tmp25_ = g_strdup ("#ae81ff");
				memset (&_tmp26_, 0, sizeof (DcSyntaxHighlightPalette));
				_g_free0 (_tmp26_.keyword);
				_tmp26_.keyword = _tmp19_;
				_g_free0 (_tmp26_.type);
				_tmp26_.type = _tmp20_;
				_g_free0 (_tmp26_.func);
				_tmp26_.func = _tmp21_;
				_g_free0 (_tmp26_.str);
				_tmp26_.str = _tmp22_;
				_g_free0 (_tmp26_.num);
				_tmp26_.num = _tmp23_;
				_g_free0 (_tmp26_.comment);
				_tmp26_.comment = _tmp24_;
				_g_free0 (_tmp26_.constant);
				_tmp26_.constant = _tmp25_;
				dc_syntax_highlight_palette_destroy (&_tmp18_);
				_tmp18_ = _tmp26_;
			} else {
				gchar* _tmp27_;
				gchar* _tmp28_;
				gchar* _tmp29_;
				gchar* _tmp30_;
				gchar* _tmp31_;
				gchar* _tmp32_;
				gchar* _tmp33_;
				DcSyntaxHighlightPalette _tmp34_ = {0};
				_tmp27_ = g_strdup ("#d81b60");
				_tmp28_ = g_strdup ("#0277bd");
				_tmp29_ = g_strdup ("#558b2e");
				_tmp30_ = g_strdup ("#b26500");
				_tmp31_ = g_strdup ("#6f42c1");
				_tmp32_ = g_strdup ("#8d8574");
				_tmp33_ = g_strdup ("#6f42c1");
				memset (&_tmp34_, 0, sizeof (DcSyntaxHighlightPalette));
				_g_free0 (_tmp34_.keyword);
				_tmp34_.keyword = _tmp27_;
				_g_free0 (_tmp34_.type);
				_tmp34_.type = _tmp28_;
				_g_free0 (_tmp34_.func);
				_tmp34_.func = _tmp29_;
				_g_free0 (_tmp34_.str);
				_tmp34_.str = _tmp30_;
				_g_free0 (_tmp34_.num);
				_tmp34_.num = _tmp31_;
				_g_free0 (_tmp34_.comment);
				_tmp34_.comment = _tmp32_;
				_g_free0 (_tmp34_.constant);
				_tmp34_.constant = _tmp33_;
				dc_syntax_highlight_palette_destroy (&_tmp18_);
				_tmp18_ = _tmp34_;
			}
			_tmp35_ = _tmp18_;
			memset (&_tmp18_, 0, sizeof (DcSyntaxHighlightPalette));
			*result = _tmp35_;
			dc_syntax_highlight_palette_destroy (&_tmp18_);
			return;
		}
		case DC_CODE_THEME_NORD:
		{
			DcSyntaxHighlightPalette _tmp36_ = {0};
			DcSyntaxHighlightPalette _tmp53_;
			if (dc_syntax_highlight_dark_mode) {
				gchar* _tmp37_;
				gchar* _tmp38_;
				gchar* _tmp39_;
				gchar* _tmp40_;
				gchar* _tmp41_;
				gchar* _tmp42_;
				gchar* _tmp43_;
				DcSyntaxHighlightPalette _tmp44_ = {0};
				_tmp37_ = g_strdup ("#81a1c1");
				_tmp38_ = g_strdup ("#8fbcbb");
				_tmp39_ = g_strdup ("#88c0d0");
				_tmp40_ = g_strdup ("#a3be8c");
				_tmp41_ = g_strdup ("#b48ead");
				_tmp42_ = g_strdup ("#7b88a1");
				_tmp43_ = g_strdup ("#d08770");
				memset (&_tmp44_, 0, sizeof (DcSyntaxHighlightPalette));
				_g_free0 (_tmp44_.keyword);
				_tmp44_.keyword = _tmp37_;
				_g_free0 (_tmp44_.type);
				_tmp44_.type = _tmp38_;
				_g_free0 (_tmp44_.func);
				_tmp44_.func = _tmp39_;
				_g_free0 (_tmp44_.str);
				_tmp44_.str = _tmp40_;
				_g_free0 (_tmp44_.num);
				_tmp44_.num = _tmp41_;
				_g_free0 (_tmp44_.comment);
				_tmp44_.comment = _tmp42_;
				_g_free0 (_tmp44_.constant);
				_tmp44_.constant = _tmp43_;
				dc_syntax_highlight_palette_destroy (&_tmp36_);
				_tmp36_ = _tmp44_;
			} else {
				gchar* _tmp45_;
				gchar* _tmp46_;
				gchar* _tmp47_;
				gchar* _tmp48_;
				gchar* _tmp49_;
				gchar* _tmp50_;
				gchar* _tmp51_;
				DcSyntaxHighlightPalette _tmp52_ = {0};
				_tmp45_ = g_strdup ("#4f6d9c");
				_tmp46_ = g_strdup ("#3f7d7b");
				_tmp47_ = g_strdup ("#3a7f96");
				_tmp48_ = g_strdup ("#61803f");
				_tmp49_ = g_strdup ("#8a5f88");
				_tmp50_ = g_strdup ("#8b95a7");
				_tmp51_ = g_strdup ("#ad5f2b");
				memset (&_tmp52_, 0, sizeof (DcSyntaxHighlightPalette));
				_g_free0 (_tmp52_.keyword);
				_tmp52_.keyword = _tmp45_;
				_g_free0 (_tmp52_.type);
				_tmp52_.type = _tmp46_;
				_g_free0 (_tmp52_.func);
				_tmp52_.func = _tmp47_;
				_g_free0 (_tmp52_.str);
				_tmp52_.str = _tmp48_;
				_g_free0 (_tmp52_.num);
				_tmp52_.num = _tmp49_;
				_g_free0 (_tmp52_.comment);
				_tmp52_.comment = _tmp50_;
				_g_free0 (_tmp52_.constant);
				_tmp52_.constant = _tmp51_;
				dc_syntax_highlight_palette_destroy (&_tmp36_);
				_tmp36_ = _tmp52_;
			}
			_tmp53_ = _tmp36_;
			memset (&_tmp36_, 0, sizeof (DcSyntaxHighlightPalette));
			*result = _tmp53_;
			dc_syntax_highlight_palette_destroy (&_tmp36_);
			return;
		}
		default:
		{
			DcSyntaxHighlightPalette _tmp54_ = {0};
			DcSyntaxHighlightPalette _tmp71_;
			if (dc_syntax_highlight_dark_mode) {
				gchar* _tmp55_;
				gchar* _tmp56_;
				gchar* _tmp57_;
				gchar* _tmp58_;
				gchar* _tmp59_;
				gchar* _tmp60_;
				gchar* _tmp61_;
				DcSyntaxHighlightPalette _tmp62_ = {0};
				_tmp55_ = g_strdup ("#ff7b72");
				_tmp56_ = g_strdup ("#ffa657");
				_tmp57_ = g_strdup ("#d2a8ff");
				_tmp58_ = g_strdup ("#a5d6ff");
				_tmp59_ = g_strdup ("#79c0ff");
				_tmp60_ = g_strdup ("#8b949e");
				_tmp61_ = g_strdup ("#79c0ff");
				memset (&_tmp62_, 0, sizeof (DcSyntaxHighlightPalette));
				_g_free0 (_tmp62_.keyword);
				_tmp62_.keyword = _tmp55_;
				_g_free0 (_tmp62_.type);
				_tmp62_.type = _tmp56_;
				_g_free0 (_tmp62_.func);
				_tmp62_.func = _tmp57_;
				_g_free0 (_tmp62_.str);
				_tmp62_.str = _tmp58_;
				_g_free0 (_tmp62_.num);
				_tmp62_.num = _tmp59_;
				_g_free0 (_tmp62_.comment);
				_tmp62_.comment = _tmp60_;
				_g_free0 (_tmp62_.constant);
				_tmp62_.constant = _tmp61_;
				dc_syntax_highlight_palette_destroy (&_tmp54_);
				_tmp54_ = _tmp62_;
			} else {
				gchar* _tmp63_;
				gchar* _tmp64_;
				gchar* _tmp65_;
				gchar* _tmp66_;
				gchar* _tmp67_;
				gchar* _tmp68_;
				gchar* _tmp69_;
				DcSyntaxHighlightPalette _tmp70_ = {0};
				_tmp63_ = g_strdup ("#cf222e");
				_tmp64_ = g_strdup ("#953800");
				_tmp65_ = g_strdup ("#8250df");
				_tmp66_ = g_strdup ("#0a3069");
				_tmp67_ = g_strdup ("#0550ae");
				_tmp68_ = g_strdup ("#6e7781");
				_tmp69_ = g_strdup ("#0550ae");
				memset (&_tmp70_, 0, sizeof (DcSyntaxHighlightPalette));
				_g_free0 (_tmp70_.keyword);
				_tmp70_.keyword = _tmp63_;
				_g_free0 (_tmp70_.type);
				_tmp70_.type = _tmp64_;
				_g_free0 (_tmp70_.func);
				_tmp70_.func = _tmp65_;
				_g_free0 (_tmp70_.str);
				_tmp70_.str = _tmp66_;
				_g_free0 (_tmp70_.num);
				_tmp70_.num = _tmp67_;
				_g_free0 (_tmp70_.comment);
				_tmp70_.comment = _tmp68_;
				_g_free0 (_tmp70_.constant);
				_tmp70_.constant = _tmp69_;
				dc_syntax_highlight_palette_destroy (&_tmp54_);
				_tmp54_ = _tmp70_;
			}
			_tmp71_ = _tmp54_;
			memset (&_tmp54_, 0, sizeof (DcSyntaxHighlightPalette));
			*result = _tmp71_;
			dc_syntax_highlight_palette_destroy (&_tmp54_);
			return;
		}
	}
}

static gchar*
dc_syntax_highlight_classify (const gchar* word,
                              const gchar* code,
                              gint end,
                              DcSyntaxHighlightPalette* pal)
{
	gchar first = '\0';
	gboolean _tmp9_ = FALSE;
	gint j = 0;
	gboolean _tmp29_ = FALSE;
	gint _tmp30_;
	gint _tmp31_;
	gchar* result;
	g_return_val_if_fail (word != NULL, NULL);
	g_return_val_if_fail (code != NULL, NULL);
	g_return_val_if_fail (pal != NULL, NULL);
	if (g_strv_contains (DC_SYNTAX_HIGHLIGHT_KEYWORDS, word)) {
		DcSyntaxHighlightPalette _tmp0_;
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp0_ = *pal;
		_tmp1_ = _tmp0_.keyword;
		_tmp2_ = g_strdup (_tmp1_);
		result = _tmp2_;
		return result;
	}
	if (g_strv_contains (DC_SYNTAX_HIGHLIGHT_TYPES, word)) {
		DcSyntaxHighlightPalette _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp3_ = *pal;
		_tmp4_ = _tmp3_.type;
		_tmp5_ = g_strdup (_tmp4_);
		result = _tmp5_;
		return result;
	}
	if (g_strv_contains (DC_SYNTAX_HIGHLIGHT_CONSTANTS, word)) {
		DcSyntaxHighlightPalette _tmp6_;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		_tmp6_ = *pal;
		_tmp7_ = _tmp6_.constant;
		_tmp8_ = g_strdup (_tmp7_);
		result = _tmp8_;
		return result;
	}
	first = string_get (word, (glong) 0);
	if (first >= 'A') {
		_tmp9_ = first <= 'Z';
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		const gchar* _tmp18_ = NULL;
		gint _tmp19_;
		gint _tmp20_;
		gchar* _tmp23_;
		{
			gint i = 0;
			i = 1;
			{
				gboolean _tmp10_ = FALSE;
				_tmp10_ = TRUE;
				while (TRUE) {
					gint _tmp12_;
					gint _tmp13_;
					gchar c = '\0';
					gboolean _tmp14_ = FALSE;
					if (!_tmp10_) {
						gint _tmp11_;
						_tmp11_ = i;
						i = _tmp11_ + 1;
					}
					_tmp10_ = FALSE;
					_tmp12_ = strlen (word);
					_tmp13_ = _tmp12_;
					if (!(i < _tmp13_)) {
						break;
					}
					c = string_get (word, (glong) i);
					if (c >= 'a') {
						_tmp14_ = c <= 'z';
					} else {
						_tmp14_ = FALSE;
					}
					if (_tmp14_) {
						DcSyntaxHighlightPalette _tmp15_;
						const gchar* _tmp16_;
						gchar* _tmp17_;
						_tmp15_ = *pal;
						_tmp16_ = _tmp15_.type;
						_tmp17_ = g_strdup (_tmp16_);
						result = _tmp17_;
						return result;
					}
				}
			}
		}
		_tmp19_ = strlen (word);
		_tmp20_ = _tmp19_;
		if (_tmp20_ > 1) {
			DcSyntaxHighlightPalette _tmp21_;
			const gchar* _tmp22_;
			_tmp21_ = *pal;
			_tmp22_ = _tmp21_.constant;
			_tmp18_ = _tmp22_;
		} else {
			_tmp18_ = NULL;
		}
		_tmp23_ = g_strdup (_tmp18_);
		result = _tmp23_;
		return result;
	}
	j = end;
	while (TRUE) {
		gboolean _tmp24_ = FALSE;
		gint _tmp25_;
		gint _tmp26_;
		gint _tmp28_;
		_tmp25_ = strlen (code);
		_tmp26_ = _tmp25_;
		if (j < _tmp26_) {
			gboolean _tmp27_ = FALSE;
			if (string_get (code, (glong) j) == ' ') {
				_tmp27_ = TRUE;
			} else {
				_tmp27_ = string_get (code, (glong) j) == '\t';
			}
			_tmp24_ = _tmp27_;
		} else {
			_tmp24_ = FALSE;
		}
		if (!_tmp24_) {
			break;
		}
		_tmp28_ = j;
		j = _tmp28_ + 1;
	}
	_tmp30_ = strlen (code);
	_tmp31_ = _tmp30_;
	if (j < _tmp31_) {
		_tmp29_ = string_get (code, (glong) j) == '(';
	} else {
		_tmp29_ = FALSE;
	}
	if (_tmp29_) {
		DcSyntaxHighlightPalette _tmp32_;
		const gchar* _tmp33_;
		gchar* _tmp34_;
		_tmp32_ = *pal;
		_tmp33_ = _tmp32_.func;
		_tmp34_ = g_strdup (_tmp33_);
		result = _tmp34_;
		return result;
	}
	result = NULL;
	return result;
}

static void
dc_syntax_highlight_append_span (GString* sb,
                                 const gchar* text,
                                 const gchar* color,
                                 gboolean italic)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (sb != NULL);
	g_return_if_fail (text != NULL);
	g_string_append (sb, "<span foreground=\"");
	g_string_append (sb, color);
	g_string_append_c (sb, '"');
	if (italic) {
		g_string_append (sb, " style=\"italic\"");
	}
	g_string_append_c (sb, '>');
	_tmp0_ = g_markup_escape_text (text, (gssize) -1);
	_tmp1_ = _tmp0_;
	g_string_append (sb, _tmp1_);
	_g_free0 (_tmp1_);
	g_string_append (sb, "</span>");
}

static gint
string_index_of_char (const gchar* self,
                      gunichar c,
                      gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_strchr (((gchar*) self) + start_index, (gssize) -1, c);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gint
dc_syntax_highlight_line_end (const gchar* code,
                              gint start)
{
	gint nl = 0;
	gint _tmp0_ = 0;
	gint result;
	g_return_val_if_fail (code != NULL, -1);
	nl = string_index_of_char (code, (gunichar) '\n', start);
	if (nl < 0) {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (code);
		_tmp2_ = _tmp1_;
		_tmp0_ = _tmp2_;
	} else {
		_tmp0_ = nl;
	}
	result = _tmp0_;
	return result;
}

static gint
dc_syntax_highlight_scan_string (const gchar* code,
                                 gint start)
{
	gchar quote = '\0';
	gint len = 0;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	gint i = 0;
	gint result;
	g_return_val_if_fail (code != NULL, -1);
	quote = string_get (code, (glong) start);
	_tmp0_ = strlen (code);
	_tmp1_ = _tmp0_;
	len = _tmp1_;
	if (quote != '`') {
		_tmp4_ = (start + 2) < len;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		_tmp3_ = string_get (code, (glong) (start + 1)) == quote;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		_tmp2_ = string_get (code, (glong) (start + 2)) == quote;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		gchar* fence = NULL;
		gchar* _tmp5_;
		gint close = 0;
		const gchar* _tmp6_;
		gint _tmp7_ = 0;
		_tmp5_ = string_substring (code, (glong) start, (glong) 3);
		fence = _tmp5_;
		_tmp6_ = fence;
		close = string_index_of (code, _tmp6_, start + 3);
		if (close < 0) {
			_tmp7_ = len;
		} else {
			_tmp7_ = close + 3;
		}
		result = _tmp7_;
		_g_free0 (fence);
		return result;
	}
	i = start + 1;
	while (TRUE) {
		gchar c = '\0';
		gboolean _tmp8_ = FALSE;
		gint _tmp9_;
		if (!(i < len)) {
			break;
		}
		c = string_get (code, (glong) i);
		if (c == '\\') {
			i += 2;
			continue;
		}
		if (c == quote) {
			result = i + 1;
			return result;
		}
		if (c == '\n') {
			_tmp8_ = quote != '`';
		} else {
			_tmp8_ = FALSE;
		}
		if (_tmp8_) {
			result = i;
			return result;
		}
		_tmp9_ = i;
		i = _tmp9_ + 1;
	}
	result = len;
	return result;
}

static gint
dc_syntax_highlight_scan_number (const gchar* code,
                                 gint start)
{
	gint len = 0;
	gint _tmp0_;
	gint _tmp1_;
	gint i = 0;
	gint result;
	g_return_val_if_fail (code != NULL, -1);
	_tmp0_ = strlen (code);
	_tmp1_ = _tmp0_;
	len = _tmp1_;
	i = start;
	while (TRUE) {
		gchar c = '\0';
		gboolean _tmp2_ = FALSE;
		gboolean _tmp3_ = FALSE;
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		if (!(i < len)) {
			break;
		}
		c = string_get (code, (glong) i);
		if (dc_syntax_highlight_is_alnum (c)) {
			_tmp3_ = TRUE;
		} else {
			_tmp3_ = c == '_';
		}
		if (_tmp3_) {
			_tmp2_ = TRUE;
		} else {
			_tmp2_ = c == '.';
		}
		if (_tmp2_) {
			gint _tmp4_;
			_tmp4_ = i;
			i = _tmp4_ + 1;
			continue;
		}
		if (c == '+') {
			_tmp6_ = TRUE;
		} else {
			_tmp6_ = c == '-';
		}
		if (_tmp6_) {
			_tmp5_ = i > start;
		} else {
			_tmp5_ = FALSE;
		}
		if (_tmp5_) {
			gchar prev = '\0';
			gboolean _tmp7_ = FALSE;
			gboolean _tmp8_ = FALSE;
			gboolean _tmp9_ = FALSE;
			prev = string_get (code, (glong) (i - 1));
			if (prev == 'e') {
				_tmp9_ = TRUE;
			} else {
				_tmp9_ = prev == 'E';
			}
			if (_tmp9_) {
				_tmp8_ = TRUE;
			} else {
				_tmp8_ = prev == 'p';
			}
			if (_tmp8_) {
				_tmp7_ = TRUE;
			} else {
				_tmp7_ = prev == 'P';
			}
			if (_tmp7_) {
				gint _tmp10_;
				_tmp10_ = i;
				i = _tmp10_ + 1;
				continue;
			}
		}
		break;
	}
	result = i;
	return result;
}

static gboolean
dc_syntax_highlight_is_digit (gchar c)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	if (c >= '0') {
		_tmp0_ = c <= '9';
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static gboolean
dc_syntax_highlight_is_alnum (gchar c)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	if (dc_syntax_highlight_is_digit (c)) {
		_tmp1_ = TRUE;
	} else {
		gboolean _tmp2_ = FALSE;
		if (c >= 'a') {
			_tmp2_ = c <= 'z';
		} else {
			_tmp2_ = FALSE;
		}
		_tmp1_ = _tmp2_;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp3_ = FALSE;
		if (c >= 'A') {
			_tmp3_ = c <= 'Z';
		} else {
			_tmp3_ = FALSE;
		}
		_tmp0_ = _tmp3_;
	}
	result = _tmp0_;
	return result;
}

static gboolean
dc_syntax_highlight_is_ident_start (gchar c)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean result;
	if (c >= 'a') {
		_tmp2_ = c <= 'z';
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		gboolean _tmp3_ = FALSE;
		if (c >= 'A') {
			_tmp3_ = c <= 'Z';
		} else {
			_tmp3_ = FALSE;
		}
		_tmp1_ = _tmp3_;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = c == '_';
	}
	result = _tmp0_;
	return result;
}

static gboolean
dc_syntax_highlight_is_ident_char (gchar c)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	if (dc_syntax_highlight_is_ident_start (c)) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = dc_syntax_highlight_is_digit (c);
	}
	result = _tmp0_;
	return result;
}

static gboolean
dc_syntax_highlight_is_ident_char_at (const gchar* code,
                                      gint index)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (code != NULL, FALSE);
	if (index >= 0) {
		_tmp0_ = dc_syntax_highlight_is_ident_char (string_get (code, (glong) index));
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

DcSyntaxHighlight*
dc_syntax_highlight_construct (GType object_type)
{
	DcSyntaxHighlight* self = NULL;
	self = (DcSyntaxHighlight*) g_type_create_instance (object_type);
	return self;
}

DcSyntaxHighlight*
dc_syntax_highlight_new (void)
{
	return dc_syntax_highlight_construct (DC_TYPE_SYNTAX_HIGHLIGHT);
}

static void
dc_syntax_highlight_palette_copy (const DcSyntaxHighlightPalette* self,
                                  DcSyntaxHighlightPalette* dest)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	_tmp0_ = (*self).keyword;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 ((*dest).keyword);
	(*dest).keyword = _tmp1_;
	_tmp2_ = (*self).type;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 ((*dest).type);
	(*dest).type = _tmp3_;
	_tmp4_ = (*self).func;
	_tmp5_ = g_strdup (_tmp4_);
	_g_free0 ((*dest).func);
	(*dest).func = _tmp5_;
	_tmp6_ = (*self).str;
	_tmp7_ = g_strdup (_tmp6_);
	_g_free0 ((*dest).str);
	(*dest).str = _tmp7_;
	_tmp8_ = (*self).num;
	_tmp9_ = g_strdup (_tmp8_);
	_g_free0 ((*dest).num);
	(*dest).num = _tmp9_;
	_tmp10_ = (*self).comment;
	_tmp11_ = g_strdup (_tmp10_);
	_g_free0 ((*dest).comment);
	(*dest).comment = _tmp11_;
	_tmp12_ = (*self).constant;
	_tmp13_ = g_strdup (_tmp12_);
	_g_free0 ((*dest).constant);
	(*dest).constant = _tmp13_;
}

static void
dc_syntax_highlight_palette_destroy (DcSyntaxHighlightPalette* self)
{
	_g_free0 ((*self).keyword);
	_g_free0 ((*self).type);
	_g_free0 ((*self).func);
	_g_free0 ((*self).str);
	_g_free0 ((*self).num);
	_g_free0 ((*self).comment);
	_g_free0 ((*self).constant);
}

static DcSyntaxHighlightPalette*
dc_syntax_highlight_palette_dup (const DcSyntaxHighlightPalette* self)
{
	DcSyntaxHighlightPalette* dup;
	dup = g_new0 (DcSyntaxHighlightPalette, 1);
	dc_syntax_highlight_palette_copy (self, dup);
	return dup;
}

static void
dc_syntax_highlight_palette_free (DcSyntaxHighlightPalette* self)
{
	dc_syntax_highlight_palette_destroy (self);
	g_free (self);
}

static GType
dc_syntax_highlight_palette_get_type_once (void)
{
	GType dc_syntax_highlight_palette_type_id;
	dc_syntax_highlight_palette_type_id = g_boxed_type_register_static ("DcSyntaxHighlightPalette", (GBoxedCopyFunc) dc_syntax_highlight_palette_dup, (GBoxedFreeFunc) dc_syntax_highlight_palette_free);
	return dc_syntax_highlight_palette_type_id;
}

static GType
dc_syntax_highlight_palette_get_type (void)
{
	static volatile gsize dc_syntax_highlight_palette_type_id__once = 0;
	if (g_once_init_enter (&dc_syntax_highlight_palette_type_id__once)) {
		GType dc_syntax_highlight_palette_type_id;
		dc_syntax_highlight_palette_type_id = dc_syntax_highlight_palette_get_type_once ();
		g_once_init_leave (&dc_syntax_highlight_palette_type_id__once, dc_syntax_highlight_palette_type_id);
	}
	return dc_syntax_highlight_palette_type_id__once;
}

static void
dc_value_syntax_highlight_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dc_value_syntax_highlight_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dc_syntax_highlight_unref (value->data[0].v_pointer);
	}
}

static void
dc_value_syntax_highlight_copy_value (const GValue* src_value,
                                      GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dc_syntax_highlight_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dc_value_syntax_highlight_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dc_value_syntax_highlight_collect_value (GValue* value,
                                         guint n_collect_values,
                                         GTypeCValue* collect_values,
                                         guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DcSyntaxHighlight * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dc_syntax_highlight_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dc_value_syntax_highlight_lcopy_value (const GValue* value,
                                       guint n_collect_values,
                                       GTypeCValue* collect_values,
                                       guint collect_flags)
{
	DcSyntaxHighlight ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dc_syntax_highlight_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dc_param_spec_syntax_highlight (const gchar* name,
                                const gchar* nick,
                                const gchar* blurb,
                                GType object_type,
                                GParamFlags flags)
{
	DcParamSpecSyntaxHighlight* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DC_TYPE_SYNTAX_HIGHLIGHT), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dc_value_get_syntax_highlight (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_SYNTAX_HIGHLIGHT), NULL);
	return value->data[0].v_pointer;
}

void
dc_value_set_syntax_highlight (GValue* value,
                               gpointer v_object)
{
	DcSyntaxHighlight * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_SYNTAX_HIGHLIGHT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_TYPE_SYNTAX_HIGHLIGHT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dc_syntax_highlight_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_syntax_highlight_unref (old);
	}
}

void
dc_value_take_syntax_highlight (GValue* value,
                                gpointer v_object)
{
	DcSyntaxHighlight * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_SYNTAX_HIGHLIGHT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_TYPE_SYNTAX_HIGHLIGHT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_syntax_highlight_unref (old);
	}
}

static void
dc_syntax_highlight_class_init (DcSyntaxHighlightClass * klass,
                                gpointer klass_data)
{
	dc_syntax_highlight_parent_class = g_type_class_peek_parent (klass);
	((DcSyntaxHighlightClass *) klass)->finalize = dc_syntax_highlight_finalize;
}

static void
dc_syntax_highlight_instance_init (DcSyntaxHighlight * self,
                                   gpointer klass)
{
	self->ref_count = 1;
}

static void
dc_syntax_highlight_finalize (DcSyntaxHighlight * obj)
{
	DcSyntaxHighlight * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_SYNTAX_HIGHLIGHT, DcSyntaxHighlight);
	g_signal_handlers_destroy (self);
}

/**
     * Generic, language-agnostic syntax highlighter for fenced code blocks.
     * A single tokenizer colors comments, strings, numbers and a keyword set
     * shared across C-family, Python, Java, TypeScript, Swift, Rust, Go and
     * Vala, so unknown or untagged languages still look reasonable. Emits
     * Pango markup with colors from small light/dark palettes.
     *
     * GLib-only on purpose: the app owns `theme` and `dark_mode` (set from
     * SettingsManager and Adw.StyleManager), keeping this file linkable from
     * the unit tests without initializing GTK.
     */
static GType
dc_syntax_highlight_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dc_value_syntax_highlight_init, dc_value_syntax_highlight_free_value, dc_value_syntax_highlight_copy_value, dc_value_syntax_highlight_peek_pointer, "p", dc_value_syntax_highlight_collect_value, "p", dc_value_syntax_highlight_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DcSyntaxHighlightClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_syntax_highlight_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcSyntaxHighlight), 0, (GInstanceInitFunc) dc_syntax_highlight_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dc_syntax_highlight_type_id;
	dc_syntax_highlight_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DcSyntaxHighlight", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return dc_syntax_highlight_type_id;
}

GType
dc_syntax_highlight_get_type (void)
{
	static volatile gsize dc_syntax_highlight_type_id__once = 0;
	if (g_once_init_enter (&dc_syntax_highlight_type_id__once)) {
		GType dc_syntax_highlight_type_id;
		dc_syntax_highlight_type_id = dc_syntax_highlight_get_type_once ();
		g_once_init_leave (&dc_syntax_highlight_type_id__once, dc_syntax_highlight_type_id);
	}
	return dc_syntax_highlight_type_id__once;
}

gpointer
dc_syntax_highlight_ref (gpointer instance)
{
	DcSyntaxHighlight * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dc_syntax_highlight_unref (gpointer instance)
{
	DcSyntaxHighlight * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DC_SYNTAX_HIGHLIGHT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

