YAML-LibYAML-API
view release on metacpan or search on metacpan
LibYAML/scanner.c view on Meta::CPAN
yaml_parser_stale_simple_keys(yaml_parser_t *parser)
{
yaml_simple_key_t *simple_key;
/* Check for a potential simple key for each flow level. */
for (simple_key = parser->simple_keys.start;
simple_key != parser->simple_keys.top; simple_key ++)
{
/*
* The specification requires that a simple key
*
* - is limited to a single line,
* - is shorter than 1024 characters.
*/
if (simple_key->possible
&& (simple_key->mark.line < parser->mark.line
|| simple_key->mark.index+1024 < parser->mark.index)) {
/* Check if the potential simple key to be removed is required. */
if (simple_key->required) {
return yaml_parser_set_scanner_error(parser,
"while scanning a simple key", simple_key->mark,
"could not find expected ':'");
}
simple_key->possible = 0;
}
}
return 1;
}
/*
* Check if a simple key may start at the current position and add it if
* needed.
*/
static int
yaml_parser_save_simple_key(yaml_parser_t *parser)
{
/*
* A simple key is required at the current position if the scanner is in
* the block context and the current column coincides with the indentation
* level.
*/
int required = (!parser->flow_level
&& parser->indent == (ptrdiff_t)parser->mark.column);
/*
* If the current position may start a simple key, save it.
*/
if (parser->simple_key_allowed)
{
yaml_simple_key_t simple_key;
simple_key.possible = 1;
simple_key.required = required;
simple_key.token_number =
parser->tokens_parsed + (parser->tokens.tail - parser->tokens.head);
simple_key.mark = parser->mark;
if (!yaml_parser_remove_simple_key(parser)) return 0;
*(parser->simple_keys.top-1) = simple_key;
}
return 1;
}
/*
* Remove a potential simple key at the current flow level.
*/
static int
yaml_parser_remove_simple_key(yaml_parser_t *parser)
{
yaml_simple_key_t *simple_key = parser->simple_keys.top-1;
if (simple_key->possible)
{
/* If the key is required, it is an error. */
if (simple_key->required) {
return yaml_parser_set_scanner_error(parser,
"while scanning a simple key", simple_key->mark,
"could not find expected ':'");
}
}
/* Remove the key from the stack. */
simple_key->possible = 0;
return 1;
}
/*
* Increase the flow level and resize the simple key list if needed.
*/
static int
yaml_parser_increase_flow_level(yaml_parser_t *parser)
{
yaml_simple_key_t empty_simple_key = { 0, 0, 0, { 0, 0, 0 } };
/* Reset the simple key on the next level. */
if (!PUSH(parser, parser->simple_keys, empty_simple_key))
return 0;
/* Increase the flow level. */
if (parser->flow_level == INT_MAX) {
parser->error = YAML_MEMORY_ERROR;
return 0;
}
( run in 1.242 second using v1.01-cache-2.11-cpan-39bf76dae61 )