TOK_STRING TOK_NAME
%token TOK_EQUALS TOK_NEWLINE TOK_ARRAY_START TOK_ARRAY_END TOK_LIST_START TOK_LIST_END TOK_COMMA TOK_GROUP_START TOK_GROUP_END TOK_SEMICOLON TOK_GARBAGE TOK_ERROR
%%
configuration:
/* empty */
| setting_list
;
setting_list:
setting
| setting_list setting
;
setting_list_optional:
/* empty */
| setting_list
;
setting_terminator:
/* empty */
| TOK_SEMICOLON
| TOK_COMMA
;
setting:
TOK_NAME
{
ctx->setting = config_setting_add(ctx->parent, $1, CONFIG_TYPE_NONE);
if(ctx->setting == NULL)
{
libconfig_yyerror(scanner, ctx, scan_ctx, err_duplicate_setting);
YYABORT;
}
else
{
CAPTURE_PARSE_POS(ctx->setting);
}
}
TOK_EQUALS value setting_terminator
;
array:
TOK_ARRAY_START
{
if(IN_LIST())
{
ctx->parent = config_setting_add(ctx->parent, NULL, CONFIG_TYPE_ARRAY);
CAPTURE_PARSE_POS(ctx->parent);
}
else
{
ctx->setting->type = CONFIG_TYPE_ARRAY;
ctx->parent = ctx->setting;
ctx->setting = NULL;
}
}
simple_value_list_optional
TOK_ARRAY_END
{
if(ctx->parent)
ctx->parent = ctx->parent->parent;
}
;
list:
TOK_LIST_START
{
if(IN_LIST())
{
ctx->parent = config_setting_add(ctx->parent, NULL, CONFIG_TYPE_LIST);
CAPTURE_PARSE_POS(ctx->parent);
}
else
{
ctx->setting->type = CONFIG_TYPE_LIST;
ctx->parent = ctx->setting;
ctx->setting = NULL;
}
}
value_list_optional
TOK_LIST_END
{
if(ctx->parent)
ctx->parent = ctx->parent->parent;
}
;
value:
simple_value
| array
| list
| group
;
string:
TOK_STRING { parsectx_append_string(ctx, $1); free($1); }
| string TOK_STRING { parsectx_append_string(ctx, $2); free($2); }
;
simple_value:
TOK_BOOLEAN
{
if(IN_ARRAY() || IN_LIST())
{
config_setting_t *e = config_setting_set_bool_elem(ctx->parent, -1,
(int)$1);
if(! e)
{
libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type);
YYABORT;
}
else
{
CAPTURE_PARSE_POS(e);
}
}
else
config_setting_set_bool(ctx->setting, (int)$1);
}
| TOK_INTEGER
{
if(IN_ARRAY() || IN_LIST())
{
config_setting_t *e = config_setting_set_int_elem(ctx->parent, -1, $1);
if(! e)
{
libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type);
YYABORT;
}
else
{
config_setting_set_format(e, CONFIG_FORMAT_DEFAULT);
CAPTURE_PARSE_POS(e);
}
}
else
{
config_setting_set_int(ctx->setting, $1);
config_setting_set_format(ctx->setting, CONFIG_FORMAT_DEFAULT);
}
}
| TOK_INTEGER64
{
if(IN_ARRAY() || IN_LIST())
{
config_setting_t *e = config_setting_set_int64_elem(ctx->parent, -1, $1);
if(! e)
{
libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type);
YYABORT;
}
else
{
config_setting_set_format(e, CONFIG_FORMAT_DEFAULT);
CAPTURE_PARSE_POS(e);
}
}
else
{
config_setting_set_int64(ctx->setting, $1);
config_setting_set_format(ctx->setting, CONFIG_FORMAT_DEFAULT);
}
}
| TOK_HEX
{
if(IN_ARRAY() || IN_LIST())
{
config_setting_t *e = config_setting_set_int_elem(ctx->parent, -1, $1);
if(! e)
{
libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type);
YYABORT;
}
else
{
config_setting_set_format(e, CONFIG_FORMAT_HEX);
CAPTURE_PARSE_POS(e);
}
}
else
{
config_setting_set_int(ctx->setting, $1);
config_setting_set_format(ctx->setting, CONFIG_FORMAT_HEX);
}
}
| TOK_HEX64
{
if(IN_ARRAY() || IN_LIST())
{
config_setting_t *e = config_setting_set_int64_elem(ctx->parent, -1, $1);
if(! e)
{
libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type);
YYABORT;
}
else
{
config_setting_set_format(e, CONFIG_FORMAT_HEX);
CAPTURE_PARSE_POS(e);
}
}
else
{
config_setting_set_int64(ctx->setting, $1);
config_setting_set_format(ctx->setting, CONFIG_FORMAT_HEX);
}
}
| TOK_FLOAT
{
if(IN_ARRAY() || IN_LIST())
{
config_setting_t *e = config_setting_set_float_elem(ctx->parent, -1, $1);
if(! e)
{
libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type);
YYABORT;
}
else
{
CAPTURE_PARSE_POS(e);
}
}
else
config_setting_set_float(ctx->setting, $1);
}
| string
{
if(IN_ARRAY() || IN_LIST())
{
const char *s = parsectx_take_string(ctx);
config_setting_t *e = config_setting_set_string_elem(ctx->parent, -1, s);
_delete(s);
if(! e)
{
libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type);
YYABORT;
}
else
{
CAPTURE_PARSE_POS(e);
}
}
else
{
const char *s = parsectx_take_string(ctx);
config_setting_set_string(ctx->setting, s);
_delete(s);
}
}
;
value_list:
value
| value_list TOK_COMMA value
;
value_list_optional:
/* empty */
| value_list
;
simple_value_list:
simple_value
| simple_value_list TOK_COMMA simple_value
;
simple_value_list_optional:
/* empty */
| simple_value_list
;
group:
TOK_GROUP_START
{
if(IN_LIST())
{
ctx->parent = config_setting_add(ctx->parent, NULL, CONFIG_TYPE_GROUP);
CAPTURE_PARSE_POS(ctx->parent);
}
else
{
ctx->setting->type = CONFIG_TYPE_GROUP;
ctx->parent = ctx->setting;
ctx->setting = NULL;
}
}
setting_list_optional
TOK_GROUP_END
{
if(ctx->parent)
ctx->parent = ctx->parent->parent;
}
;
%%
version 0+git20140326.cfc2975upstream/0+git20140326.cfc2975Jonathan McCrohan | 118 | -656/+877 |
2014-01-16 | Release 0+git20140107.1850cf8-1debian/0+git20140107.1850cf8-1 | Jonathan McCrohan | 1 | -2/+2 |
2014-01-16 | Update Standards Version to 3.9.5 | Jonathan McCrohan | 2 | -1/+9 |