summaryrefslogtreecommitdiff
path: root/3rdparty/libconfig/extra/gen
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/libconfig/extra/gen')
-rw-r--r--3rdparty/libconfig/extra/gen/grammar.y72
-rw-r--r--3rdparty/libconfig/extra/gen/scanner.l82
2 files changed, 152 insertions, 2 deletions
diff --git a/3rdparty/libconfig/extra/gen/grammar.y b/3rdparty/libconfig/extra/gen/grammar.y
index 5d9f02c2d..a59fcc354 100644
--- a/3rdparty/libconfig/extra/gen/grammar.y
+++ b/3rdparty/libconfig/extra/gen/grammar.y
@@ -90,8 +90,8 @@ void libconfig_yyerror(void *scanner, struct parse_context *ctx,
char *sval;
}
-%token <ival> TOK_BOOLEAN TOK_INTEGER TOK_HEX
-%token <llval> TOK_INTEGER64 TOK_HEX64
+%token <ival> TOK_BOOLEAN TOK_INTEGER TOK_HEX TOK_BIN TOK_OCT
+%token <llval> TOK_INTEGER64 TOK_HEX64 TOK_BIN64 TOK_OCT64
%token <fval> TOK_FLOAT
%token <sval> 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
@@ -310,6 +310,74 @@ simple_value:
config_setting_set_format(ctx->setting, CONFIG_FORMAT_HEX);
}
}
+ | TOK_BIN
+ {
+ if (IN_ARRAY() || IN_LIST()) {
+ struct 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_BIN);
+ CAPTURE_PARSE_POS(e);
+ }
+ } else {
+ config_setting_set_int(ctx->setting, $1);
+ config_setting_set_format(ctx->setting, CONFIG_FORMAT_BIN);
+ }
+ }
+ | TOK_BIN64
+ {
+ if (IN_ARRAY() || IN_LIST()) {
+ struct 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_BIN);
+ CAPTURE_PARSE_POS(e);
+ }
+ } else {
+ config_setting_set_int64(ctx->setting, $1);
+ config_setting_set_format(ctx->setting, CONFIG_FORMAT_BIN);
+ }
+ }
+ | TOK_OCT
+ {
+ if (IN_ARRAY() || IN_LIST()) {
+ struct 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_OCT);
+ CAPTURE_PARSE_POS(e);
+ }
+ } else {
+ config_setting_set_int(ctx->setting, $1);
+ config_setting_set_format(ctx->setting, CONFIG_FORMAT_OCT);
+ }
+ }
+ | TOK_OCT64
+ {
+ if (IN_ARRAY() || IN_LIST()) {
+ struct 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_OCT);
+ CAPTURE_PARSE_POS(e);
+ }
+ } else {
+ config_setting_set_int64(ctx->setting, $1);
+ config_setting_set_format(ctx->setting, CONFIG_FORMAT_OCT);
+ }
+ }
| TOK_FLOAT
{
if(IN_ARRAY() || IN_LIST())
diff --git a/3rdparty/libconfig/extra/gen/scanner.l b/3rdparty/libconfig/extra/gen/scanner.l
index f57e1c275..f75bf67f6 100644
--- a/3rdparty/libconfig/extra/gen/scanner.l
+++ b/3rdparty/libconfig/extra/gen/scanner.l
@@ -84,6 +84,68 @@ static unsigned long long fromhex(const char *s)
#endif /* __MINGW32__ */
}
+static unsigned long long frombin (const char *s)
+{
+#ifdef __MINGW32__
+
+ /* same problem as fromhex(): MinGW's strtoull() is broken */
+
+ const char *p = s;
+ unsigned long long val = 0;
+
+ if (*p != '0')
+ return(0);
+
+ ++p;
+
+ if (*p != 'b' && *p != 'B')
+ return(0);
+
+ for (++p; *p == '0' || *p == '1'; ++p) {
+ val <<= 1;
+ val |= *p == '0' ? 0 : 1;
+ }
+
+ return val;
+
+#else /* ! __MINGW32__ */
+
+ return strtoull(s + 2, NULL, 2);
+
+#endif /* __MINGW32__ */
+}
+
+static unsigned long long fromoct (const char *s)
+{
+#ifdef __MINGW32__
+
+ /* same problem as fromhex(): MinGW's strtoull() is broken */
+
+ const char *p = s;
+ unsigned long long val = 0;
+
+ if (*p != '0')
+ return(0);
+
+ ++p;
+
+ if (*p != 'o' && *p != 'O')
+ return(0);
+
+ for (++p; *p >= '0' && *p <= '7'; ++p) {
+ val <<= 3;
+ val |= *p & 0xF;
+ }
+
+ return val;
+
+#else /* ! __MINGW32__ */
+
+ return strtoull(s + 2, NULL, 8);
+
+#endif /* __MINGW32__ */
+}
+
%}
true [Tt][Rr][Uu][Ee]
@@ -93,6 +155,10 @@ integer [-+]?[0-9]+
integer64 [-+]?[0-9]+L(L)?
hex 0[Xx][0-9A-Fa-f]+
hex64 0[Xx][0-9A-Fa-f]+L(L)?
+bin 0[Bb][01]+
+bin64 0[Bb][01]+L(L)?
+oct 0[Oo][0-7]+
+oct64 0[Oo][0-7]+L(L)?
hexchar \\[Xx][0-9A-Fa-f]{2}
float ([-+]?([0-9]*)?\.[0-9]*([eE][-+]?[0-9]+)?)|([-+]?([0-9]+)(\.[0-9]*)?[eE][-+]?[0-9]+)
comment (#|\/\/).*$
@@ -196,6 +262,22 @@ include_open ^[ \t]*@include[ \t]+\"
return(TOK_HEX);
}
{hex64} { yylval->llval = fromhex(yytext); return(TOK_HEX64); }
+{bin} {
+ unsigned long ulval = strtoul(yytext + 2, NULL, 2);
+ if (ulval > INT32_MAX)
+ ulval &= INT32_MAX;
+ yylval->ival = (int)ulval;
+ return TOK_BIN;
+ }
+{bin64} { yylval->llval = frombin(yytext); return TOK_BIN64; }
+{oct} {
+ unsigned long ulval = strtoul(yytext + 2, NULL, 8);
+ if (ulval > INT32_MAX)
+ ulval &= INT32_MAX;
+ yylval->ival = (int)ulval;
+ return TOK_OCT;
+ }
+{oct64} { yylval->llval = fromoct(yytext); return TOK_OCT64; }
{name} { yylval->sval = yytext; return(TOK_NAME); }
\[ { return(TOK_ARRAY_START); }
\] { return(TOK_ARRAY_END); }