2 * Copyright © 2009, 2010 Codethink Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Author: Ryan Lortie <desrt@desrt.ca>
31 #include "gstrfuncs.h"
32 #include "gtestutils.h"
34 #include "gvarianttype.h"
38 * designed by ryan lortie and william hua
39 * designed in itb-229 and at ghazi's, 2009.
43 * G_VARIANT_PARSE_ERROR:
45 * Error domain for GVariant text format parsing. Specific error codes
46 * are not currently defined for this domain. See #GError for
47 * information on error domains.
51 * @G_VARIANT_PARSE_ERROR_FAILED: generic error (unused)
52 * @G_VARIANT_PARSE_ERROR_BASIC_TYPE_EXPECTED: a non-basic #GVariantType was given where a basic type was expected
53 * @G_VARIANT_PARSE_ERROR_CANNOT_INFER_TYPE: cannot infer the #GVariantType
54 * @G_VARIANT_PARSE_ERROR_DEFINITE_TYPE_EXPECTED: an indefinite #GVariantType was given where a definite type was expected
55 * @G_VARIANT_PARSE_ERROR_INPUT_NOT_AT_END: extra data after parsing finished
56 * @G_VARIANT_PARSE_ERROR_INVALID_CHARACTER: invalid character in number or unicode escape
57 * @G_VARIANT_PARSE_ERROR_INVALID_FORMAT_STRING: not a valid #GVariant format string
58 * @G_VARIANT_PARSE_ERROR_INVALID_OBJECT_PATH: not a valid object path
59 * @G_VARIANT_PARSE_ERROR_INVALID_SIGNATURE: not a valid type signature
60 * @G_VARIANT_PARSE_ERROR_INVALID_TYPE_STRING: not a valid #GVariant type string
61 * @G_VARIANT_PARSE_ERROR_NO_COMMON_TYPE: could not find a common type for array entries
62 * @G_VARIANT_PARSE_ERROR_NUMBER_OUT_OF_RANGE: the numerical value is out of range of the given type
63 * @G_VARIANT_PARSE_ERROR_NUMBER_TOO_BIG: the numerical value is out of range for any type
64 * @G_VARIANT_PARSE_ERROR_TYPE_ERROR: cannot parse as variant of the specified type
65 * @G_VARIANT_PARSE_ERROR_UNEXPECTED_TOKEN: an unexpected token was encountered
66 * @G_VARIANT_PARSE_ERROR_UNKNOWN_KEYWORD: an unknown keyword was encountered
67 * @G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT: unterminated string constant
68 * @G_VARIANT_PARSE_ERROR_VALUE_EXPECTED: no value given
70 * Error codes returned by parsing text-format GVariants.
73 g_variant_parser_get_error_quark (void)
75 static GQuark the_quark;
78 the_quark = g_quark_from_static_string ("g-variant-parse-error-quark");
89 parser_set_error_va (GError **error,
96 GString *msg = g_string_new (NULL);
98 if (location->start == location->end)
99 g_string_append_printf (msg, "%d", location->start);
101 g_string_append_printf (msg, "%d-%d", location->start, location->end);
105 g_assert (other->start != other->end);
106 g_string_append_printf (msg, ",%d-%d", other->start, other->end);
108 g_string_append_c (msg, ':');
110 g_string_append_vprintf (msg, format, ap);
111 g_set_error_literal (error, G_VARIANT_PARSE_ERROR, code, msg->str);
112 g_string_free (msg, TRUE);
116 parser_set_error (GError **error,
125 va_start (ap, format);
126 parser_set_error_va (error, location, other, code, format, ap);
141 token_stream_set_error (TokenStream *stream,
151 ref.start = stream->this - stream->start;
154 ref.end = stream->stream - stream->start;
158 va_start (ap, format);
159 parser_set_error_va (error, &ref, NULL, code, format, ap);
164 token_stream_prepare (TokenStream *stream)
169 if (stream->this != NULL)
172 while (stream->stream != stream->end && g_ascii_isspace (*stream->stream))
175 if (stream->stream == stream->end || *stream->stream == '\0')
177 stream->this = stream->stream;
181 switch (stream->stream[0])
183 case '-': case '+': case '.': case '0': case '1': case '2':
184 case '3': case '4': case '5': case '6': case '7': case '8':
186 for (end = stream->stream; end != stream->end; end++)
187 if (!g_ascii_isalnum (*end) &&
188 *end != '-' && *end != '+' && *end != '.')
193 if (stream->stream[1] == '\'' || stream->stream[1] == '"')
195 for (end = stream->stream + 2; end != stream->end; end++)
196 if (*end == stream->stream[1] || *end == '\0' ||
197 (*end == '\\' && (++end == stream->end || *end == '\0')))
200 if (end != stream->end && *end)
207 case 'a': /* 'b' */ case 'c': case 'd': case 'e': case 'f':
208 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
209 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
210 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
212 for (end = stream->stream; end != stream->end; end++)
213 if (!g_ascii_isalnum (*end))
218 for (end = stream->stream + 1; end != stream->end; end++)
219 if (*end == stream->stream[0] || *end == '\0' ||
220 (*end == '\\' && (++end == stream->end || *end == '\0')))
223 if (end != stream->end && *end)
228 /* stop at the first space, comma, colon or unmatched bracket.
229 * deals nicely with cases like (%i, %i) or {%i: %i}.
231 for (end = stream->stream + 1;
232 end != stream->end && *end != ',' &&
233 *end != ':' && *end != '>' && !g_ascii_isspace (*end);
236 if (*end == '(' || *end == '{')
239 else if ((*end == ')' || *end == '}') && !brackets--)
245 end = stream->stream + 1;
249 stream->this = stream->stream;
250 stream->stream = end;
256 token_stream_next (TokenStream *stream)
262 token_stream_peek (TokenStream *stream,
265 if (!token_stream_prepare (stream))
268 return stream->this[0] == first_char;
272 token_stream_peek2 (TokenStream *stream,
276 if (!token_stream_prepare (stream))
279 return stream->this[0] == first_char &&
280 stream->this[1] == second_char;
284 token_stream_is_keyword (TokenStream *stream)
286 if (!token_stream_prepare (stream))
289 return g_ascii_isalpha (stream->this[0]) &&
290 g_ascii_isalpha (stream->this[1]);
294 token_stream_is_numeric (TokenStream *stream)
296 if (!token_stream_prepare (stream))
299 return (g_ascii_isdigit (stream->this[0]) ||
300 stream->this[0] == '-' ||
301 stream->this[0] == '+' ||
302 stream->this[0] == '.');
306 token_stream_peek_string (TokenStream *stream,
309 gint length = strlen (token);
311 return token_stream_prepare (stream) &&
312 stream->stream - stream->this == length &&
313 memcmp (stream->this, token, length) == 0;
317 token_stream_consume (TokenStream *stream,
320 if (!token_stream_peek_string (stream, token))
323 token_stream_next (stream);
328 token_stream_require (TokenStream *stream,
330 const gchar *purpose,
334 if (!token_stream_consume (stream, token))
336 token_stream_set_error (stream, error, FALSE,
337 G_VARIANT_PARSE_ERROR_UNEXPECTED_TOKEN,
338 "expected `%s'%s", token, purpose);
346 token_stream_assert (TokenStream *stream,
349 gboolean correct_token;
351 correct_token = token_stream_consume (stream, token);
352 g_assert (correct_token);
356 token_stream_get (TokenStream *stream)
360 if (!token_stream_prepare (stream))
363 result = g_strndup (stream->this, stream->stream - stream->this);
369 token_stream_start_ref (TokenStream *stream,
372 token_stream_prepare (stream);
373 ref->start = stream->this - stream->start;
377 token_stream_end_ref (TokenStream *stream,
380 ref->end = stream->stream - stream->start;
384 pattern_copy (gchar **out,
389 while (**in == 'a' || **in == 'm' || **in == 'M')
390 *(*out)++ = *(*in)++;
394 if (**in == '(' || **in == '{')
397 else if (**in == ')' || **in == '}')
400 *(*out)++ = *(*in)++;
406 pattern_coalesce (const gchar *left,
412 /* the length of the output is loosely bound by the sum of the input
413 * lengths, not simply the greater of the two lengths.
415 * (*(iii)) + ((iii)*) ((iii)(iii))
419 out = result = g_malloc (strlen (left) + strlen (right));
421 while (*left && *right)
431 const gchar **one = &left, **the_other = &right;
434 if (**one == '*' && **the_other != ')')
436 pattern_copy (&out, the_other);
440 else if (**one == 'M' && **the_other == 'm')
442 *out++ = *(*the_other)++;
445 else if (**one == 'M' && **the_other != 'm')
450 else if (**one == 'N' && strchr ("ynqiuxthd", **the_other))
452 *out++ = *(*the_other)++;
456 else if (**one == 'S' && strchr ("sog", **the_other))
458 *out++ = *(*the_other)++;
462 else if (one == &left)
464 one = &right, the_other = &left;
484 typedef struct _AST AST;
485 typedef gchar * (*get_pattern_func) (AST *ast,
487 typedef GVariant * (*get_value_func) (AST *ast,
488 const GVariantType *type,
490 typedef GVariant * (*get_base_value_func) (AST *ast,
491 const GVariantType *type,
493 typedef void (*free_func) (AST *ast);
497 gchar * (* get_pattern) (AST *ast,
499 GVariant * (* get_value) (AST *ast,
500 const GVariantType *type,
502 GVariant * (* get_base_value) (AST *ast,
503 const GVariantType *type,
505 void (* free) (AST *ast);
510 const ASTClass *class;
511 SourceRef source_ref;
515 ast_get_pattern (AST *ast,
518 return ast->class->get_pattern (ast, error);
522 ast_get_value (AST *ast,
523 const GVariantType *type,
526 return ast->class->get_value (ast, type, error);
532 ast->class->free (ast);
536 ast_set_error (AST *ast,
545 va_start (ap, format);
546 parser_set_error_va (error, &ast->source_ref,
547 other_ast ? & other_ast->source_ref : NULL,
554 ast_type_error (AST *ast,
555 const GVariantType *type,
560 typestr = g_variant_type_dup_string (type);
561 ast_set_error (ast, error, NULL,
562 G_VARIANT_PARSE_ERROR_TYPE_ERROR,
563 "can not parse as value of type `%s'",
571 ast_resolve (AST *ast,
578 pattern = ast_get_pattern (ast, error);
583 /* choose reasonable defaults
585 * 1) favour non-maybe values where possible
586 * 2) default type for strings is 's'
587 * 3) default type for integers is 'i'
589 for (i = 0; pattern[i]; i++)
593 ast_set_error (ast, error, NULL,
594 G_VARIANT_PARSE_ERROR_CANNOT_INFER_TYPE,
595 "unable to infer type");
611 pattern[j++] = pattern[i];
616 value = ast_get_value (ast, G_VARIANT_TYPE (pattern), error);
623 static AST *parse (TokenStream *stream,
628 ast_array_append (AST ***array,
632 if ((*n_items & (*n_items - 1)) == 0)
633 *array = g_renew (AST *, *array, *n_items ? 2 ** n_items : 1);
635 (*array)[(*n_items)++] = ast;
639 ast_array_free (AST **array,
644 for (i = 0; i < n_items; i++)
650 ast_array_get_pattern (AST **array,
657 pattern = ast_get_pattern (array[0], error);
662 for (i = 1; i < n_items; i++)
666 tmp = ast_get_pattern (array[i], error);
674 merged = pattern_coalesce (pattern, tmp);
679 /* set coalescence implies pairwise coalescence (i think).
680 * we should therefore be able to trace the failure to a single
691 /* if 'j' reaches 'i' then we failed to find the pair */
694 tmp2 = ast_get_pattern (array[j], NULL);
695 g_assert (tmp2 != NULL);
697 m = pattern_coalesce (tmp, tmp2);
703 /* we found a conflict between 'i' and 'j'.
705 * report the error. note: 'j' is first.
707 ast_set_error (array[j], error, array[i],
708 G_VARIANT_PARSE_ERROR_NO_COMMON_TYPE,
709 "unable to find a common type");
733 maybe_get_pattern (AST *ast,
736 Maybe *maybe = (Maybe *) ast;
738 if (maybe->child != NULL)
740 gchar *child_pattern;
743 child_pattern = ast_get_pattern (maybe->child, error);
745 if (child_pattern == NULL)
748 pattern = g_strdup_printf ("m%s", child_pattern);
749 g_free (child_pattern);
754 return g_strdup ("m*");
758 maybe_get_value (AST *ast,
759 const GVariantType *type,
762 Maybe *maybe = (Maybe *) ast;
765 if (!g_variant_type_is_maybe (type))
766 return ast_type_error (ast, type, error);
768 type = g_variant_type_element (type);
772 value = ast_get_value (maybe->child, type, error);
780 return g_variant_new_maybe (type, value);
784 maybe_free (AST *ast)
786 Maybe *maybe = (Maybe *) ast;
788 if (maybe->child != NULL)
789 ast_free (maybe->child);
791 g_slice_free (Maybe, maybe);
795 maybe_parse (TokenStream *stream,
799 static const ASTClass maybe_class = {
801 maybe_get_value, NULL,
807 if (token_stream_consume (stream, "just"))
809 child = parse (stream, app, error);
814 else if (!token_stream_consume (stream, "nothing"))
816 token_stream_set_error (stream, error, TRUE,
817 G_VARIANT_PARSE_ERROR_UNKNOWN_KEYWORD,
822 maybe = g_slice_new (Maybe);
823 maybe->ast.class = &maybe_class;
824 maybe->child = child;
826 return (AST *) maybe;
830 maybe_wrapper (AST *ast,
831 const GVariantType *type,
834 const GVariantType *t;
838 for (depth = 0, t = type;
839 g_variant_type_is_maybe (t);
840 depth++, t = g_variant_type_element (t));
842 value = ast->class->get_base_value (ast, t, error);
848 value = g_variant_new_maybe (NULL, value);
862 array_get_pattern (AST *ast,
865 Array *array = (Array *) ast;
869 if (array->n_children == 0)
870 return g_strdup ("Ma*");
872 pattern = ast_array_get_pattern (array->children, array->n_children, error);
877 result = g_strdup_printf ("Ma%s", pattern);
884 array_get_value (AST *ast,
885 const GVariantType *type,
888 Array *array = (Array *) ast;
889 const GVariantType *childtype;
890 GVariantBuilder builder;
893 if (!g_variant_type_is_array (type))
894 return ast_type_error (ast, type, error);
896 g_variant_builder_init (&builder, type);
897 childtype = g_variant_type_element (type);
899 for (i = 0; i < array->n_children; i++)
903 if (!(child = ast_get_value (array->children[i], childtype, error)))
905 g_variant_builder_clear (&builder);
909 g_variant_builder_add_value (&builder, child);
912 return g_variant_builder_end (&builder);
916 array_free (AST *ast)
918 Array *array = (Array *) ast;
920 ast_array_free (array->children, array->n_children);
921 g_slice_free (Array, array);
925 array_parse (TokenStream *stream,
929 static const ASTClass array_class = {
931 maybe_wrapper, array_get_value,
934 gboolean need_comma = FALSE;
937 array = g_slice_new (Array);
938 array->ast.class = &array_class;
939 array->children = NULL;
940 array->n_children = 0;
942 token_stream_assert (stream, "[");
943 while (!token_stream_consume (stream, "]"))
948 !token_stream_require (stream, ",",
949 " or `]' to follow array element",
953 child = parse (stream, app, error);
958 ast_array_append (&array->children, &array->n_children, child);
962 return (AST *) array;
965 ast_array_free (array->children, array->n_children);
966 g_slice_free (Array, array);
980 tuple_get_pattern (AST *ast,
983 Tuple *tuple = (Tuple *) ast;
984 gchar *result = NULL;
988 parts = g_new (gchar *, tuple->n_children + 4);
989 parts[tuple->n_children + 1] = (gchar *) ")";
990 parts[tuple->n_children + 2] = NULL;
991 parts[0] = (gchar *) "M(";
993 for (i = 0; i < tuple->n_children; i++)
994 if (!(parts[i + 1] = ast_get_pattern (tuple->children[i], error)))
997 if (i == tuple->n_children)
998 result = g_strjoinv ("", parts);
1000 /* parts[0] should not be freed */
1002 g_free (parts[i--]);
1009 tuple_get_value (AST *ast,
1010 const GVariantType *type,
1013 Tuple *tuple = (Tuple *) ast;
1014 const GVariantType *childtype;
1015 GVariantBuilder builder;
1018 if (!g_variant_type_is_tuple (type))
1019 return ast_type_error (ast, type, error);
1021 g_variant_builder_init (&builder, type);
1022 childtype = g_variant_type_first (type);
1024 for (i = 0; i < tuple->n_children; i++)
1028 if (childtype == NULL)
1030 g_variant_builder_clear (&builder);
1031 return ast_type_error (ast, type, error);
1034 if (!(child = ast_get_value (tuple->children[i], childtype, error)))
1036 g_variant_builder_clear (&builder);
1040 g_variant_builder_add_value (&builder, child);
1041 childtype = g_variant_type_next (childtype);
1044 if (childtype != NULL)
1046 g_variant_builder_clear (&builder);
1047 return ast_type_error (ast, type, error);
1050 return g_variant_builder_end (&builder);
1054 tuple_free (AST *ast)
1056 Tuple *tuple = (Tuple *) ast;
1058 ast_array_free (tuple->children, tuple->n_children);
1059 g_slice_free (Tuple, tuple);
1063 tuple_parse (TokenStream *stream,
1067 static const ASTClass tuple_class = {
1069 maybe_wrapper, tuple_get_value,
1072 gboolean need_comma = FALSE;
1073 gboolean first = TRUE;
1076 tuple = g_slice_new (Tuple);
1077 tuple->ast.class = &tuple_class;
1078 tuple->children = NULL;
1079 tuple->n_children = 0;
1081 token_stream_assert (stream, "(");
1082 while (!token_stream_consume (stream, ")"))
1087 !token_stream_require (stream, ",",
1088 " or `)' to follow tuple element",
1092 child = parse (stream, app, error);
1097 ast_array_append (&tuple->children, &tuple->n_children, child);
1099 /* the first time, we absolutely require a comma, so grab it here
1100 * and leave need_comma = FALSE so that the code above doesn't
1101 * require a second comma.
1103 * the second and remaining times, we set need_comma = TRUE.
1107 if (!token_stream_require (stream, ",",
1108 " after first tuple element", error))
1117 return (AST *) tuple;
1120 ast_array_free (tuple->children, tuple->n_children);
1121 g_slice_free (Tuple, tuple);
1134 variant_get_pattern (AST *ast,
1137 return g_strdup ("Mv");
1141 variant_get_value (AST *ast,
1142 const GVariantType *type,
1145 Variant *variant = (Variant *) ast;
1148 g_assert (g_variant_type_equal (type, G_VARIANT_TYPE_VARIANT));
1149 child = ast_resolve (variant->value, error);
1154 return g_variant_new_variant (child);
1158 variant_free (AST *ast)
1160 Variant *variant = (Variant *) ast;
1162 ast_free (variant->value);
1163 g_slice_free (Variant, variant);
1167 variant_parse (TokenStream *stream,
1171 static const ASTClass variant_class = {
1172 variant_get_pattern,
1173 maybe_wrapper, variant_get_value,
1179 token_stream_assert (stream, "<");
1180 value = parse (stream, app, error);
1185 if (!token_stream_require (stream, ">", " to follow variant value", error))
1191 variant = g_slice_new (Variant);
1192 variant->ast.class = &variant_class;
1193 variant->value = value;
1195 return (AST *) variant;
1208 dictionary_get_pattern (AST *ast,
1211 Dictionary *dict = (Dictionary *) ast;
1212 gchar *value_pattern;
1217 if (dict->n_children == 0)
1218 return g_strdup ("Ma{**}");
1220 key_pattern = ast_array_get_pattern (dict->keys,
1221 abs (dict->n_children),
1224 if (key_pattern == NULL)
1227 /* we can not have maybe keys */
1228 if (key_pattern[0] == 'M')
1229 key_char = key_pattern[1];
1231 key_char = key_pattern[0];
1233 g_free (key_pattern);
1236 * plus undetermined number type and undetermined string type.
1238 if (!strchr ("bynqiuxthdsogNS", key_char))
1240 ast_set_error (ast, error, NULL,
1241 G_VARIANT_PARSE_ERROR_BASIC_TYPE_EXPECTED,
1242 "dictionary keys must have basic types");
1246 value_pattern = ast_get_pattern (dict->values[0], error);
1248 if (value_pattern == NULL)
1251 result = g_strdup_printf ("M%s{%c%s}",
1252 dict->n_children > 0 ? "a" : "",
1253 key_char, value_pattern);
1254 g_free (value_pattern);
1260 dictionary_get_value (AST *ast,
1261 const GVariantType *type,
1264 Dictionary *dict = (Dictionary *) ast;
1266 if (dict->n_children == -1)
1268 const GVariantType *subtype;
1269 GVariantBuilder builder;
1272 if (!g_variant_type_is_dict_entry (type))
1273 return ast_type_error (ast, type, error);
1275 g_variant_builder_init (&builder, type);
1277 subtype = g_variant_type_key (type);
1278 if (!(subvalue = ast_get_value (dict->keys[0], subtype, error)))
1280 g_variant_builder_clear (&builder);
1283 g_variant_builder_add_value (&builder, subvalue);
1285 subtype = g_variant_type_value (type);
1286 if (!(subvalue = ast_get_value (dict->values[0], subtype, error)))
1288 g_variant_builder_clear (&builder);
1291 g_variant_builder_add_value (&builder, subvalue);
1293 return g_variant_builder_end (&builder);
1297 const GVariantType *entry, *key, *val;
1298 GVariantBuilder builder;
1301 if (!g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_DICTIONARY))
1302 return ast_type_error (ast, type, error);
1304 entry = g_variant_type_element (type);
1305 key = g_variant_type_key (entry);
1306 val = g_variant_type_value (entry);
1308 g_variant_builder_init (&builder, type);
1310 for (i = 0; i < dict->n_children; i++)
1314 g_variant_builder_open (&builder, entry);
1316 if (!(subvalue = ast_get_value (dict->keys[i], key, error)))
1318 g_variant_builder_clear (&builder);
1321 g_variant_builder_add_value (&builder, subvalue);
1323 if (!(subvalue = ast_get_value (dict->values[i], val, error)))
1325 g_variant_builder_clear (&builder);
1328 g_variant_builder_add_value (&builder, subvalue);
1329 g_variant_builder_close (&builder);
1332 return g_variant_builder_end (&builder);
1337 dictionary_free (AST *ast)
1339 Dictionary *dict = (Dictionary *) ast;
1342 if (dict->n_children > -1)
1343 n_children = dict->n_children;
1347 ast_array_free (dict->keys, n_children);
1348 ast_array_free (dict->values, n_children);
1349 g_slice_free (Dictionary, dict);
1353 dictionary_parse (TokenStream *stream,
1357 static const ASTClass dictionary_class = {
1358 dictionary_get_pattern,
1359 maybe_wrapper, dictionary_get_value,
1362 gint n_keys, n_values;
1367 dict = g_slice_new (Dictionary);
1368 dict->ast.class = &dictionary_class;
1370 dict->values = NULL;
1371 n_keys = n_values = 0;
1373 token_stream_assert (stream, "{");
1375 if (token_stream_consume (stream, "}"))
1377 dict->n_children = 0;
1378 return (AST *) dict;
1381 if ((first = parse (stream, app, error)) == NULL)
1384 ast_array_append (&dict->keys, &n_keys, first);
1386 only_one = token_stream_consume (stream, ",");
1388 !token_stream_require (stream, ":",
1389 " or `,' to follow dictionary entry key",
1393 if ((first = parse (stream, app, error)) == NULL)
1396 ast_array_append (&dict->values, &n_values, first);
1400 if (!token_stream_require (stream, "}", " at end of dictionary entry",
1404 g_assert (n_keys == 1 && n_values == 1);
1405 dict->n_children = -1;
1407 return (AST *) dict;
1410 while (!token_stream_consume (stream, "}"))
1414 if (!token_stream_require (stream, ",",
1415 " or `}' to follow dictionary entry", error))
1418 child = parse (stream, app, error);
1423 ast_array_append (&dict->keys, &n_keys, child);
1425 if (!token_stream_require (stream, ":",
1426 " to follow dictionary entry key", error))
1429 child = parse (stream, app, error);
1434 ast_array_append (&dict->values, &n_values, child);
1437 g_assert (n_keys == n_values);
1438 dict->n_children = n_keys;
1440 return (AST *) dict;
1443 ast_array_free (dict->keys, n_keys);
1444 ast_array_free (dict->values, n_values);
1445 g_slice_free (Dictionary, dict);
1457 string_get_pattern (AST *ast,
1460 return g_strdup ("MS");
1464 string_get_value (AST *ast,
1465 const GVariantType *type,
1468 String *string = (String *) ast;
1470 if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
1471 return g_variant_new_string (string->string);
1473 else if (g_variant_type_equal (type, G_VARIANT_TYPE_OBJECT_PATH))
1475 if (!g_variant_is_object_path (string->string))
1477 ast_set_error (ast, error, NULL,
1478 G_VARIANT_PARSE_ERROR_INVALID_OBJECT_PATH,
1479 "not a valid object path");
1483 return g_variant_new_object_path (string->string);
1486 else if (g_variant_type_equal (type, G_VARIANT_TYPE_SIGNATURE))
1488 if (!g_variant_is_signature (string->string))
1490 ast_set_error (ast, error, NULL,
1491 G_VARIANT_PARSE_ERROR_INVALID_SIGNATURE,
1492 "not a valid signature");
1496 return g_variant_new_signature (string->string);
1500 return ast_type_error (ast, type, error);
1504 string_free (AST *ast)
1506 String *string = (String *) ast;
1508 g_free (string->string);
1509 g_slice_free (String, string);
1513 unicode_unescape (const gchar *src,
1527 g_assert (length < sizeof (buffer));
1528 strncpy (buffer, src + *src_ofs, length);
1529 buffer[length] = '\0';
1531 value = g_ascii_strtoull (buffer, &end, 0x10);
1533 if (value == 0 || end != buffer + length)
1535 parser_set_error (error, ref, NULL,
1536 G_VARIANT_PARSE_ERROR_INVALID_CHARACTER,
1537 "invalid %d-character unicode escape", length);
1541 g_assert (value <= G_MAXUINT32);
1543 *dest_ofs += g_unichar_to_utf8 (value, dest + *dest_ofs);
1550 string_parse (TokenStream *stream,
1554 static const ASTClass string_class = {
1556 maybe_wrapper, string_get_value,
1567 token_stream_start_ref (stream, &ref);
1568 token = token_stream_get (stream);
1569 token_stream_end_ref (stream, &ref);
1570 length = strlen (token);
1573 str = g_malloc (length);
1574 g_assert (quote == '"' || quote == '\'');
1577 while (token[i] != quote)
1581 parser_set_error (error, &ref, NULL,
1582 G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
1583 "unterminated string constant");
1592 parser_set_error (error, &ref, NULL,
1593 G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
1594 "unterminated string constant");
1600 if (!unicode_unescape (token, &i, str, &j, 4, &ref, error))
1609 if (!unicode_unescape (token, &i, str, &j, 8, &ref, error))
1617 case 'a': str[j++] = '\a'; i++; continue;
1618 case 'b': str[j++] = '\b'; i++; continue;
1619 case 'f': str[j++] = '\f'; i++; continue;
1620 case 'n': str[j++] = '\n'; i++; continue;
1621 case 'r': str[j++] = '\r'; i++; continue;
1622 case 't': str[j++] = '\t'; i++; continue;
1623 case 'v': str[j++] = '\v'; i++; continue;
1624 case '\n': i++; continue;
1628 str[j++] = token[i++];
1633 string = g_slice_new (String);
1634 string->ast.class = &string_class;
1635 string->string = str;
1637 token_stream_next (stream);
1639 return (AST *) string;
1649 bytestring_get_pattern (AST *ast,
1652 return g_strdup ("May");
1656 bytestring_get_value (AST *ast,
1657 const GVariantType *type,
1660 ByteString *string = (ByteString *) ast;
1662 g_assert (g_variant_type_equal (type, G_VARIANT_TYPE_BYTESTRING));
1664 return g_variant_new_bytestring (string->string);
1668 bytestring_free (AST *ast)
1670 ByteString *string = (ByteString *) ast;
1672 g_free (string->string);
1673 g_slice_free (ByteString, string);
1677 bytestring_parse (TokenStream *stream,
1681 static const ASTClass bytestring_class = {
1682 bytestring_get_pattern,
1683 maybe_wrapper, bytestring_get_value,
1694 token_stream_start_ref (stream, &ref);
1695 token = token_stream_get (stream);
1696 token_stream_end_ref (stream, &ref);
1697 g_assert (token[0] == 'b');
1698 length = strlen (token);
1701 str = g_malloc (length);
1702 g_assert (quote == '"' || quote == '\'');
1705 while (token[i] != quote)
1709 parser_set_error (error, &ref, NULL,
1710 G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
1711 "unterminated string constant");
1719 parser_set_error (error, &ref, NULL,
1720 G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
1721 "unterminated string constant");
1725 case '0': case '1': case '2': case '3':
1726 case '4': case '5': case '6': case '7':
1728 /* up to 3 characters */
1729 guchar val = token[i++] - '0';
1731 if ('0' <= token[i] && token[i] < '8')
1732 val = (val << 3) | (token[i++] - '0');
1734 if ('0' <= token[i] && token[i] < '8')
1735 val = (val << 3) | (token[i++] - '0');
1741 case 'a': str[j++] = '\a'; i++; continue;
1742 case 'b': str[j++] = '\b'; i++; continue;
1743 case 'f': str[j++] = '\f'; i++; continue;
1744 case 'n': str[j++] = '\n'; i++; continue;
1745 case 'r': str[j++] = '\r'; i++; continue;
1746 case 't': str[j++] = '\t'; i++; continue;
1747 case 'v': str[j++] = '\v'; i++; continue;
1748 case '\n': i++; continue;
1752 str[j++] = token[i++];
1757 string = g_slice_new (ByteString);
1758 string->ast.class = &bytestring_class;
1759 string->string = str;
1761 token_stream_next (stream);
1763 return (AST *) string;
1774 number_get_pattern (AST *ast,
1777 Number *number = (Number *) ast;
1779 if (strchr (number->token, '.') ||
1780 (!g_str_has_prefix (number->token, "0x") && strchr (number->token, 'e')) ||
1781 strstr (number->token, "inf") ||
1782 strstr (number->token, "nan"))
1783 return g_strdup ("Md");
1785 return g_strdup ("MN");
1789 number_overflow (AST *ast,
1790 const GVariantType *type,
1793 ast_set_error (ast, error, NULL,
1794 G_VARIANT_PARSE_ERROR_NUMBER_OUT_OF_RANGE,
1795 "number out of range for type `%c'",
1796 g_variant_type_peek_string (type)[0]);
1801 number_get_value (AST *ast,
1802 const GVariantType *type,
1805 Number *number = (Number *) ast;
1813 token = number->token;
1815 if (g_variant_type_equal (type, G_VARIANT_TYPE_DOUBLE))
1820 dbl_val = g_ascii_strtod (token, &end);
1821 if (dbl_val != 0.0 && errno == ERANGE)
1823 ast_set_error (ast, error, NULL,
1824 G_VARIANT_PARSE_ERROR_NUMBER_TOO_BIG,
1825 "number too big for any type");
1829 /* silence uninitialised warnings... */
1836 negative = token[0] == '-';
1837 if (token[0] == '-')
1841 abs_val = g_ascii_strtoull (token, &end, 0);
1842 if (abs_val == G_MAXUINT64 && errno == ERANGE)
1844 ast_set_error (ast, error, NULL,
1845 G_VARIANT_PARSE_ERROR_NUMBER_TOO_BIG,
1846 "integer too big for any type");
1853 /* silence uninitialised warning... */
1861 ref = ast->source_ref;
1862 ref.start += end - number->token;
1863 ref.end = ref.start + 1;
1865 parser_set_error (error, &ref, NULL,
1866 G_VARIANT_PARSE_ERROR_INVALID_CHARACTER,
1867 "invalid character in number");
1872 return g_variant_new_double (dbl_val);
1874 switch (*g_variant_type_peek_string (type))
1877 if (negative || abs_val > G_MAXUINT8)
1878 return number_overflow (ast, type, error);
1879 return g_variant_new_byte (abs_val);
1882 if (abs_val - negative > G_MAXINT16)
1883 return number_overflow (ast, type, error);
1884 return g_variant_new_int16 (negative ? -abs_val : abs_val);
1887 if (negative || abs_val > G_MAXUINT16)
1888 return number_overflow (ast, type, error);
1889 return g_variant_new_uint16 (abs_val);
1892 if (abs_val - negative > G_MAXINT32)
1893 return number_overflow (ast, type, error);
1894 return g_variant_new_int32 (negative ? -abs_val : abs_val);
1897 if (negative || abs_val > G_MAXUINT32)
1898 return number_overflow (ast, type, error);
1899 return g_variant_new_uint32 (abs_val);
1902 if (abs_val - negative > G_MAXINT64)
1903 return number_overflow (ast, type, error);
1904 return g_variant_new_int64 (negative ? -abs_val : abs_val);
1908 return number_overflow (ast, type, error);
1909 return g_variant_new_uint64 (abs_val);
1912 if (abs_val - negative > G_MAXINT32)
1913 return number_overflow (ast, type, error);
1914 return g_variant_new_handle (negative ? -abs_val : abs_val);
1917 return ast_type_error (ast, type, error);
1922 number_free (AST *ast)
1924 Number *number = (Number *) ast;
1926 g_free (number->token);
1927 g_slice_free (Number, number);
1931 number_parse (TokenStream *stream,
1935 static const ASTClass number_class = {
1937 maybe_wrapper, number_get_value,
1942 number = g_slice_new (Number);
1943 number->ast.class = &number_class;
1944 number->token = token_stream_get (stream);
1945 token_stream_next (stream);
1947 return (AST *) number;
1957 boolean_get_pattern (AST *ast,
1960 return g_strdup ("Mb");
1964 boolean_get_value (AST *ast,
1965 const GVariantType *type,
1968 Boolean *boolean = (Boolean *) ast;
1970 if (!g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
1971 return ast_type_error (ast, type, error);
1973 return g_variant_new_boolean (boolean->value);
1977 boolean_free (AST *ast)
1979 Boolean *boolean = (Boolean *) ast;
1981 g_slice_free (Boolean, boolean);
1985 boolean_new (gboolean value)
1987 static const ASTClass boolean_class = {
1988 boolean_get_pattern,
1989 maybe_wrapper, boolean_get_value,
1994 boolean = g_slice_new (Boolean);
1995 boolean->ast.class = &boolean_class;
1996 boolean->value = value;
1998 return (AST *) boolean;
2009 positional_get_pattern (AST *ast,
2012 Positional *positional = (Positional *) ast;
2014 return g_strdup (g_variant_get_type_string (positional->value));
2018 positional_get_value (AST *ast,
2019 const GVariantType *type,
2022 Positional *positional = (Positional *) ast;
2025 g_assert (positional->value != NULL);
2027 if G_UNLIKELY (!g_variant_is_of_type (positional->value, type))
2028 return ast_type_error (ast, type, error);
2030 /* NOTE: if _get is called more than once then
2031 * things get messed up with respect to floating refs.
2033 * fortunately, this function should only ever get called once.
2035 g_assert (positional->value != NULL);
2036 value = positional->value;
2037 positional->value = NULL;
2043 positional_free (AST *ast)
2045 Positional *positional = (Positional *) ast;
2047 /* if positional->value is set, just leave it.
2048 * memory management doesn't matter in case of programmer error.
2050 g_slice_free (Positional, positional);
2054 positional_parse (TokenStream *stream,
2058 static const ASTClass positional_class = {
2059 positional_get_pattern,
2060 positional_get_value, NULL,
2063 Positional *positional;
2064 const gchar *endptr;
2067 token = token_stream_get (stream);
2068 g_assert (token[0] == '%');
2070 positional = g_slice_new (Positional);
2071 positional->ast.class = &positional_class;
2072 positional->value = g_variant_new_va (token + 1, &endptr, app);
2074 if (*endptr || positional->value == NULL)
2076 token_stream_set_error (stream, error, TRUE,
2077 G_VARIANT_PARSE_ERROR_INVALID_FORMAT_STRING,
2078 "invalid GVariant format string");
2079 /* memory management doesn't matter in case of programmer error. */
2083 token_stream_next (stream);
2086 return (AST *) positional;
2098 typedecl_get_pattern (AST *ast,
2101 TypeDecl *decl = (TypeDecl *) ast;
2103 return g_variant_type_dup_string (decl->type);
2107 typedecl_get_value (AST *ast,
2108 const GVariantType *type,
2111 TypeDecl *decl = (TypeDecl *) ast;
2113 return ast_get_value (decl->child, type, error);
2117 typedecl_free (AST *ast)
2119 TypeDecl *decl = (TypeDecl *) ast;
2121 ast_free (decl->child);
2122 g_variant_type_free (decl->type);
2123 g_slice_free (TypeDecl, decl);
2127 typedecl_parse (TokenStream *stream,
2131 static const ASTClass typedecl_class = {
2132 typedecl_get_pattern,
2133 typedecl_get_value, NULL,
2140 if (token_stream_peek (stream, '@'))
2144 token = token_stream_get (stream);
2146 if (!g_variant_type_string_is_valid (token + 1))
2148 token_stream_set_error (stream, error, TRUE,
2149 G_VARIANT_PARSE_ERROR_INVALID_TYPE_STRING,
2150 "invalid type declaration");
2156 type = g_variant_type_new (token + 1);
2158 if (!g_variant_type_is_definite (type))
2160 token_stream_set_error (stream, error, TRUE,
2161 G_VARIANT_PARSE_ERROR_DEFINITE_TYPE_EXPECTED,
2162 "type declarations must be definite");
2163 g_variant_type_free (type);
2169 token_stream_next (stream);
2174 if (token_stream_consume (stream, "boolean"))
2175 type = g_variant_type_copy (G_VARIANT_TYPE_BOOLEAN);
2177 else if (token_stream_consume (stream, "byte"))
2178 type = g_variant_type_copy (G_VARIANT_TYPE_BYTE);
2180 else if (token_stream_consume (stream, "int16"))
2181 type = g_variant_type_copy (G_VARIANT_TYPE_INT16);
2183 else if (token_stream_consume (stream, "uint16"))
2184 type = g_variant_type_copy (G_VARIANT_TYPE_UINT16);
2186 else if (token_stream_consume (stream, "int32"))
2187 type = g_variant_type_copy (G_VARIANT_TYPE_INT32);
2189 else if (token_stream_consume (stream, "handle"))
2190 type = g_variant_type_copy (G_VARIANT_TYPE_HANDLE);
2192 else if (token_stream_consume (stream, "uint32"))
2193 type = g_variant_type_copy (G_VARIANT_TYPE_UINT32);
2195 else if (token_stream_consume (stream, "int64"))
2196 type = g_variant_type_copy (G_VARIANT_TYPE_INT64);
2198 else if (token_stream_consume (stream, "uint64"))
2199 type = g_variant_type_copy (G_VARIANT_TYPE_UINT64);
2201 else if (token_stream_consume (stream, "double"))
2202 type = g_variant_type_copy (G_VARIANT_TYPE_DOUBLE);
2204 else if (token_stream_consume (stream, "string"))
2205 type = g_variant_type_copy (G_VARIANT_TYPE_STRING);
2207 else if (token_stream_consume (stream, "objectpath"))
2208 type = g_variant_type_copy (G_VARIANT_TYPE_OBJECT_PATH);
2210 else if (token_stream_consume (stream, "signature"))
2211 type = g_variant_type_copy (G_VARIANT_TYPE_SIGNATURE);
2215 token_stream_set_error (stream, error, TRUE,
2216 G_VARIANT_PARSE_ERROR_UNKNOWN_KEYWORD,
2222 if ((child = parse (stream, app, error)) == NULL)
2224 g_variant_type_free (type);
2228 decl = g_slice_new (TypeDecl);
2229 decl->ast.class = &typedecl_class;
2231 decl->child = child;
2233 return (AST *) decl;
2237 parse (TokenStream *stream,
2241 SourceRef source_ref;
2244 token_stream_prepare (stream);
2245 token_stream_start_ref (stream, &source_ref);
2247 if (token_stream_peek (stream, '['))
2248 result = array_parse (stream, app, error);
2250 else if (token_stream_peek (stream, '('))
2251 result = tuple_parse (stream, app, error);
2253 else if (token_stream_peek (stream, '<'))
2254 result = variant_parse (stream, app, error);
2256 else if (token_stream_peek (stream, '{'))
2257 result = dictionary_parse (stream, app, error);
2259 else if (app && token_stream_peek (stream, '%'))
2260 result = positional_parse (stream, app, error);
2262 else if (token_stream_consume (stream, "true"))
2263 result = boolean_new (TRUE);
2265 else if (token_stream_consume (stream, "false"))
2266 result = boolean_new (FALSE);
2268 else if (token_stream_is_numeric (stream) ||
2269 token_stream_peek_string (stream, "inf") ||
2270 token_stream_peek_string (stream, "nan"))
2271 result = number_parse (stream, app, error);
2273 else if (token_stream_peek (stream, 'n') ||
2274 token_stream_peek (stream, 'j'))
2275 result = maybe_parse (stream, app, error);
2277 else if (token_stream_peek (stream, '@') ||
2278 token_stream_is_keyword (stream))
2279 result = typedecl_parse (stream, app, error);
2281 else if (token_stream_peek (stream, '\'') ||
2282 token_stream_peek (stream, '"'))
2283 result = string_parse (stream, app, error);
2285 else if (token_stream_peek2 (stream, 'b', '\'') ||
2286 token_stream_peek2 (stream, 'b', '"'))
2287 result = bytestring_parse (stream, app, error);
2291 token_stream_set_error (stream, error, FALSE,
2292 G_VARIANT_PARSE_ERROR_VALUE_EXPECTED,
2299 token_stream_end_ref (stream, &source_ref);
2300 result->source_ref = source_ref;
2308 * @type: a #GVariantType, or %NULL
2309 * @text: a string containing a GVariant in text form
2310 * @limit: a pointer to the end of @text, or %NULL
2311 * @endptr: a location to store the end pointer, or %NULL
2312 * @error: a pointer to a %NULL #GError pointer, or %NULL
2313 * @Returns: a reference to a #GVariant, or %NULL
2315 * Parses a #GVariant from a text representation.
2317 * A single #GVariant is parsed from the content of @text.
2319 * The format is described <link linkend='gvariant-text'>here</link>.
2321 * The memory at @limit will never be accessed and the parser behaves as
2322 * if the character at @limit is the nul terminator. This has the
2323 * effect of bounding @text.
2325 * If @endptr is non-%NULL then @text is permitted to contain data
2326 * following the value that this function parses and @endptr will be
2327 * updated to point to the first character past the end of the text
2328 * parsed by this function. If @endptr is %NULL and there is extra data
2329 * then an error is returned.
2331 * If @type is non-%NULL then the value will be parsed to have that
2332 * type. This may result in additional parse errors (in the case that
2333 * the parsed value doesn't fit the type) but may also result in fewer
2334 * errors (in the case that the type would have been ambiguous, such as
2335 * with empty arrays).
2337 * In the event that the parsing is successful, the resulting #GVariant
2340 * In case of any error, %NULL will be returned. If @error is non-%NULL
2341 * then it will be set to reflect the error that occurred.
2343 * Officially, the language understood by the parser is "any string
2344 * produced by g_variant_print()".
2347 g_variant_parse (const GVariantType *type,
2350 const gchar **endptr,
2353 TokenStream stream = { 0, };
2354 GVariant *result = NULL;
2357 g_return_val_if_fail (text != NULL, NULL);
2358 g_return_val_if_fail (text == limit || text != NULL, NULL);
2360 stream.start = text;
2361 stream.stream = text;
2364 if ((ast = parse (&stream, NULL, error)))
2367 result = ast_resolve (ast, error);
2369 result = ast_get_value (ast, type, error);
2373 g_variant_ref_sink (result);
2377 while (stream.stream != limit &&
2378 g_ascii_isspace (*stream.stream))
2381 if (stream.stream != limit && *stream.stream != '\0')
2383 SourceRef ref = { stream.stream - text,
2384 stream.stream - text };
2386 parser_set_error (error, &ref, NULL,
2387 G_VARIANT_PARSE_ERROR_INPUT_NOT_AT_END,
2388 "expected end of input");
2389 g_variant_unref (result);
2395 *endptr = stream.stream;
2405 * g_variant_new_parsed_va:
2406 * @format: a text format #GVariant
2407 * @app: a pointer to a #va_list
2408 * @returns: a new, usually floating, #GVariant
2410 * Parses @format and returns the result.
2412 * This is the version of g_variant_new_parsed() intended to be used
2415 * The return value will be floating if it was a newly created GVariant
2416 * instance. In the case that @format simply specified the collection
2417 * of a #GVariant pointer (eg: @format was "%*") then the collected
2418 * #GVariant pointer will be returned unmodified, without adding any
2419 * additional references.
2421 * In order to behave correctly in all cases it is necessary for the
2422 * calling function to g_variant_ref_sink() the return result before
2423 * returning control to the user that originally provided the pointer.
2424 * At this point, the caller will have their own full reference to the
2425 * result. This can also be done by adding the result to a container,
2426 * or by passing it to another g_variant_new() call.
2429 g_variant_new_parsed_va (const gchar *format,
2432 TokenStream stream = { 0, };
2433 GVariant *result = NULL;
2434 GError *error = NULL;
2437 g_return_val_if_fail (format != NULL, NULL);
2438 g_return_val_if_fail (app != NULL, NULL);
2440 stream.start = format;
2441 stream.stream = format;
2444 if ((ast = parse (&stream, app, &error)))
2446 result = ast_resolve (ast, &error);
2451 g_error ("g_variant_new_parsed: %s", error->message);
2454 g_error ("g_variant_new_parsed: trailing text after value");
2460 * g_variant_new_parsed:
2461 * @format: a text format #GVariant
2462 * @...: arguments as per @format
2463 * @returns: a new floating #GVariant instance
2465 * Parses @format and returns the result.
2467 * @format must be a text format #GVariant with one extension: at any
2468 * point that a value may appear in the text, a '%' character followed
2469 * by a GVariant format string (as per g_variant_new()) may appear. In
2470 * that case, the same arguments are collected from the argument list as
2471 * g_variant_new() would have collected.
2473 * Consider this simple example:
2475 * <informalexample><programlisting>
2476 * g_variant_new_parsed ("[('one', 1), ('two', %i), (%s, 3)]", 2, "three");
2477 * </programlisting></informalexample>
2479 * In the example, the variable argument parameters are collected and
2480 * filled in as if they were part of the original string to produce the
2481 * result of <code>[('one', 1), ('two', 2), ('three', 3)]</code>.
2483 * This function is intended only to be used with @format as a string
2484 * literal. Any parse error is fatal to the calling process. If you
2485 * want to parse data from untrusted sources, use g_variant_parse().
2487 * You may not use this function to return, unmodified, a single
2488 * #GVariant pointer from the argument list. ie: @format may not solely
2489 * be anything along the lines of "%*", "%?", "%r", or anything starting
2493 g_variant_new_parsed (const gchar *format,
2499 va_start (ap, format);
2500 result = g_variant_new_parsed_va (format, &ap);
2507 * g_variant_builder_add_parsed:
2508 * @builder: a #GVariantBuilder
2509 * @format: a text format #GVariant
2510 * @...: arguments as per @format
2512 * Adds to a #GVariantBuilder.
2514 * This call is a convenience wrapper that is exactly equivalent to
2515 * calling g_variant_new_parsed() followed by
2516 * g_variant_builder_add_value().
2518 * This function might be used as follows:
2522 * make_pointless_dictionary (void)
2524 * GVariantBuilder *builder;
2527 * builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
2528 * g_variant_builder_add_parsed (builder, "{'width', <%i>}", 600);
2529 * g_variant_builder_add_parsed (builder, "{'title', <%s>}", "foo");
2530 * g_variant_builder_add_parsed (builder, "{'transparency', <0.5>}");
2531 * return g_variant_builder_end (builder);
2538 g_variant_builder_add_parsed (GVariantBuilder *builder,
2539 const gchar *format,
2544 va_start (ap, format);
2545 g_variant_builder_add_value (builder, g_variant_new_parsed_va (format, &ap));