43 yaml_token_t * afw_yaml_parser_scan(
47 void afw_yaml_token_cleanup(
50 yaml_token_t *token = (yaml_token_t *)data;
52 yaml_token_delete(token);
58 yaml_token_t * afw_yaml_parser_scan(
66 rc = yaml_parser_scan(&parser->parser, token);
69 "Error: %s, near line %d, column %d",
70 parser->parser.problem, parser->parser.problem_mark.line,
71 parser->parser.problem_mark.column);
75 afw_yaml_token_cleanup, xctx);
88 switch (token->data.scalar.style) {
89 case YAML_PLAIN_SCALAR_STYLE:
90 case YAML_LITERAL_SCALAR_STYLE:
93 if (sscanf((
const char *)token->data.scalar.value,
"%lf", &number) > 0) {
95 }
else if (strcmp((
const char *)token->data.scalar.value,
"true") == 0) {
97 }
else if (strcmp((
const char *)token->data.scalar.value,
"false") == 0) {
99 }
else if (strcmp((
const char *)token->data.scalar.value,
"null") == 0) {
112 case YAML_ANY_SCALAR_STYLE:
113 case YAML_FOLDED_SCALAR_STYLE:
114 case YAML_SINGLE_QUOTED_SCALAR_STYLE:
115 case YAML_DOUBLE_QUOTED_SCALAR_STYLE:
139 value = afw_yaml_parse_value(parser, xctx);
164 parser->embedding_object,
165 parser->property_name,
166 false, parser->cede_p, parser->p, xctx);
176 saved_embedding_object = parser->embedding_object;
177 parser->embedding_object = object;
178 saved_property_name = parser->property_name;
179 parser->property_name = NULL;
180 default_path = (!saved_embedding_object) ? parser->path : NULL;
183 token = afw_yaml_parser_scan(parser, xctx);
185 if (token->type == YAML_FLOW_ENTRY_TOKEN)
188 if (token->type == YAML_KEY_TOKEN) {
189 v = afw_yaml_parse_value(parser, xctx);
192 parser->property_name = key;
194 }
else if (token->type == YAML_VALUE_TOKEN) {
195 v = afw_yaml_parse_value(parser, xctx);
216 }
else if (token->type != YAML_BLOCK_END_TOKEN &&
217 token->type != YAML_FLOW_MAPPING_END_TOKEN) {
219 "Unexpected token inside map, starting at line %d, column %d",
220 parser->parser.mark.line, parser->parser.mark.column);
223 done = (token->type == YAML_BLOCK_END_TOKEN ||
224 token->type == YAML_FLOW_MAPPING_END_TOKEN);
231 parser->embedding_object = saved_embedding_object;
232 parser->property_name = saved_property_name;
244 while (value == NULL) {
245 token = afw_yaml_parser_scan(parser, xctx);
247 switch (token->type) {
248 case YAML_SCALAR_TOKEN:
250 value = afw_yaml_parse_scalar(parser, token, xctx);
253 case YAML_BLOCK_MAPPING_START_TOKEN:
254 case YAML_FLOW_MAPPING_START_TOKEN:
256 obj = afw_yaml_parse_object(parser, xctx);
261 case YAML_FLOW_ENTRY_TOKEN:
262 case YAML_BLOCK_ENTRY_TOKEN:
265 case YAML_FLOW_SEQUENCE_START_TOKEN:
266 case YAML_BLOCK_SEQUENCE_START_TOKEN:
268 list = afw_yaml_parse_list(parser, xctx);
273 case YAML_BLOCK_END_TOKEN:
274 case YAML_FLOW_SEQUENCE_END_TOKEN:
279 case YAML_ANCHOR_TOKEN:
281 value = afw_yaml_parse_value(parser, xctx);
282 apr_hash_set(parser->anchors,
284 (
const char *)token->data.anchor.value),
285 APR_HASH_KEY_STRING, value);
289 case YAML_ALIAS_TOKEN:
291 value = apr_hash_get(parser->anchors, token->data.alias.value,
292 APR_HASH_KEY_STRING);
296 "Alias references undefined anchor, near line %d, column %d",
297 parser->parser.mark.line, parser->parser.mark.column);
301 case YAML_DOCUMENT_START_TOKEN:
302 if (parser->docStarted) {
305 "Multiple documents are not supported.", xctx);
315 case YAML_VERSION_DIRECTIVE_TOKEN:
319 case YAML_TAG_DIRECTIVE_TOKEN:
326 "Unexpected token type, starting at line %d, column %d",
327 parser->parser.mark.line, parser->parser.mark.column);
349 parser.embedding_object = NULL;
350 parser.property_name = NULL;
353 parser.cede_p =
false;
356 if (!yaml_parser_initialize(&parser.parser)) {
358 "Unable to initialize libyaml parser", xctx);
363 yaml_parser_set_input_string(&parser.parser, yaml->ptr, yaml->size);
366 token = afw_yaml_parser_scan(&parser, xctx);
367 if (token->type != YAML_STREAM_START_TOKEN) {
369 "Expected start of stream token", xctx);
373 value = afw_yaml_parse_value(&parser, xctx);
376 token = afw_yaml_parser_scan(&parser, xctx);
377 if (token->type != YAML_STREAM_END_TOKEN) {
379 "Expected end of stream token", xctx);
401 parser.embedding_object = NULL;
402 parser.property_name = NULL;
405 adaptor_id, object_type_id, object_id, parser.p, xctx);
408 return afw_yaml_parse_object(&parser, xctx);
Adaptive Framework Core API.
Header file for Adaptive Framework YAML.
afw_value_create_double(double internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type double value.
afw_value_create_list(const afw_list_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type list value.
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated object.
afw_value_create_object(const afw_object_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type object value.
afw_value_create_string(const afw_utf8_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type string value.
#define afw_value_is_string(A_VALUE)
Macro to determine if value is evaluated string.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
#define AFW_POSSIBLY_UNUSED_VARIABLE
Macro to avoid unused variable warning.
#define AFW_THROW_ERROR_RV_Z(code, rv_source_id, rv, message_z, xctx)
Macro used to set error and rv in xctx and throw it.
#define AFW_THROW_ERROR_RV_FZ(code, rv_source_id, rv, xctx, format_z,...)
Macro used to set error and rv in xctx and throw it.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
#define afw_list_create_generic(p, xctx)
Create an value list in memory.
afw_list_add_value(const afw_list_t *instance, const afw_value_t *value, afw_xctx_t *xctx)
Call method add_value of interface afw_list_setter.
afw_object_path_make(const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_pool_t *p, afw_xctx_t *xctx)
Construct an object path in a specified pool.
#define AFW_OBJECT_CREATE_ENTITY_OR_EMBEDDED(result, embedding_object, property_name, always_create_unmanaged, cede_p, entity_p, xctx)
Helper macro to create a new entity or embedded object.
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
#define afw_pool_get_apr_pool(instance)
Call method get_apr_pool of interface afw_pool.
#define afw_pool_register_cleanup_before(instance, data, data2, cleanup, xctx)
Call method register_cleanup_before of interface afw_pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
const afw_pool_t * afw_pool_create(const afw_pool_t *parent, afw_xctx_t *xctx)
Create a new pool.
#define afw_utf8_create_copy(s, len, p, xctx)
Make a utf-8 sting from chars in pool specified.
afw_boolean_t afw_utf8_equal(const afw_utf8_t *s1, const afw_utf8_t *s2)
Check to see if a string equals another string.
afw_value_as_utf8(const afw_value_t *value, const afw_pool_t *p, afw_xctx_t *xctx)
afw_value_false
Adaptive value false.
afw_value_null
Adaptive value null.
afw_value_true
Adaptive value true.
const afw_value_t * afw_yaml_to_value(const afw_memory_t *yaml, const afw_utf8_t *path, const afw_pool_t *p, afw_xctx_t *xctx)
Convert YAML to an adaptive value.
const afw_object_t * afw_yaml_to_object(const afw_memory_t *yaml, const afw_utf8_t *source_location, const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, afw_boolean_t cede_p, const afw_pool_t *p, afw_xctx_t *xctx)
Convert from YAML to adaptive object.
Interface afw_list public struct.
Struct for memory pointer and size.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
struct for data type object values.
Interface afw_value public struct.
Interface afw_xctx public struct.