Add example/json* -input-jwcc and -jwcc flags

This commit is contained in:
Nigel Tao committed 2021-02-22 12:29:14 +11:00
1 parent 773994c3f6
commit 041267957c
3 files changed
+68 -1

No files matched your search

+24
View File
@@ -79,6 +79,8 @@ static const char* g_usage =
" -input-allow-comments\n"
" -input-allow-extra-comma\n"
" -input-allow-inf-nan-numbers\n"
" -input-jwcc\n"
" -jwcc\n"
"\n"
"The input.json filename is optional. If absent, it reads from stdin.\n"
"\n"
@@ -107,6 +109,16 @@ static const char* g_usage =
"The -input-allow-inf-nan-numbers flag allows non-finite floating point\n"
"numbers (infinities and not-a-numbers) within JSON input.\n"
"\n"
"Combining some of those flags results in speaking JWCC (JSON With Commas\n"
"and Comments), not plain JSON. For convenience, the -input-jwcc or -jwcc\n"
"flags enables all of:\n"
" -input-allow-comments\n"
" -input-allow-extra-comma\n"
"\n"
#if defined(WUFFS_EXAMPLE_SPEAK_JWCC_NOT_JSON)
"This program was configured at compile time to always use -jwcc.\n"
"\n"
#endif
"----\n"
"\n"
"The JSON specification permits implementations to set their own maximum\n"
@@ -130,6 +142,12 @@ struct {
std::string //
parse_flags(int argc, char** argv) {
#if defined(WUFFS_EXAMPLE_SPEAK_JWCC_NOT_JSON)
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
#endif
int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name.
for (; c < argc; c++) {
char* arg = argv[c];
@@ -163,6 +181,12 @@ parse_flags(int argc, char** argv) {
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS);
continue;
}
if (!strcmp(arg, "input-jwcc") || !strcmp(arg, "jwcc")) {
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
continue;
}
return g_usage;
}
+24
View File
@@ -113,6 +113,8 @@ static const char* g_usage =
" -input-allow-comments\n"
" -input-allow-extra-comma\n"
" -input-allow-inf-nan-numbers\n"
" -input-jwcc\n"
" -jwcc\n"
" -only-parse-dont-output\n"
" -strict-json-pointer-syntax\n"
"\n"
@@ -167,6 +169,16 @@ static const char* g_usage =
"The -input-allow-inf-nan-numbers flag allows non-finite floating point\n"
"numbers (infinities and not-a-numbers) within JSON input.\n"
"\n"
"Combining some of those flags results in speaking JWCC (JSON With Commas\n"
"and Comments), not plain JSON. For convenience, the -input-jwcc or -jwcc\n"
"flags enables all of:\n"
" -input-allow-comments\n"
" -input-allow-extra-comma\n"
"\n"
#if defined(WUFFS_EXAMPLE_SPEAK_JWCC_NOT_JSON)
"This program was configured at compile time to always use -jwcc.\n"
"\n"
#endif
"----\n"
"\n"
"The -only-parse-dont-output flag means to write nothing to stdout. An\n"
@@ -220,6 +232,12 @@ std::string //
parse_flags(int argc, char** argv) {
g_flags.max_output_depth = 0xFFFFFFFF;
#if defined(WUFFS_EXAMPLE_SPEAK_JWCC_NOT_JSON)
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
#endif
int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name.
for (; c < argc; c++) {
char* arg = argv[c];
@@ -269,6 +287,12 @@ parse_flags(int argc, char** argv) {
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS);
continue;
}
if (!strcmp(arg, "input-jwcc") || !strcmp(arg, "jwcc")) {
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
continue;
}
if (!strncmp(arg, "q=", 2) || !strncmp(arg, "query=", 6)) {
while (*arg++ != '=') {
}
+20 -1
View File
@@ -161,6 +161,7 @@ static const char* g_usage =
" -input-allow-comments\n"
" -input-allow-extra-comma\n"
" -input-allow-inf-nan-numbers\n"
" -input-jwcc\n"
" -jwcc\n"
" -output-comments\n"
" -output-extra-comma\n"
@@ -209,12 +210,18 @@ static const char* g_usage =
"and they can produce simpler line-based diffs. This flag is ignored when\n"
"-compact-output is set.\n"
"\n"
"The -jwcc flag (JSON With Commas and Comments) enables all of:\n"
"Combining some of those flags results in speaking JWCC (JSON With Commas\n"
"and Comments), not plain JSON. For convenience, the -input-jwcc or -jwcc\n"
"flags enables the first two or all four of:\n"
" -input-allow-comments\n"
" -input-allow-extra-comma\n"
" -output-comments\n"
" -output-extra-comma\n"
"\n"
#if defined(WUFFS_EXAMPLE_SPEAK_JWCC_NOT_JSON)
"This program was configured at compile time to always use -jwcc.\n"
"\n"
#endif
"----\n"
"\n"
"The -q=STR or -query=STR flag gives an optional JSON Pointer query, to\n"
@@ -775,6 +782,13 @@ parse_flags(int argc, char** argv) {
g_flags.spaces = 4;
g_flags.max_output_depth = 0xFFFFFFFF;
#if defined(WUFFS_EXAMPLE_SPEAK_JWCC_NOT_JSON)
g_flags.input_allow_comments = true;
g_flags.input_allow_extra_comma = true;
g_flags.output_comments = true;
g_flags.output_extra_comma = true;
#endif
int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name.
for (; c < argc; c++) {
char* arg = argv[c];
@@ -831,6 +845,11 @@ parse_flags(int argc, char** argv) {
g_flags.input_allow_inf_nan_numbers = true;
continue;
}
if (!strcmp(arg, "input-jwcc")) {
g_flags.input_allow_comments = true;
g_flags.input_allow_extra_comma = true;
continue;
}
if (!strcmp(arg, "jwcc")) {
g_flags.input_allow_comments = true;
g_flags.input_allow_extra_comma = true;