Add --strip-comments option
This commit is contained in:
1 parent
b2e7eaff99
commit
80e9bea3a8
5 files changed
+25
-8
No files matched your search
+3
-2
@@ -132,7 +132,7 @@ endif
|
|||||||
|
|
||||||
### Tests (make check)
|
### Tests (make check)
|
||||||
|
|
||||||
TESTS = tests/optionaltest tests/mantest tests/jqtest tests/onigtest tests/shtest tests/utf8test tests/base64test
|
TESTS = tests/optionaltest tests/mantest tests/jqtest tests/onigtest tests/shtest tests/utf8test tests/base64test tests/commenttest
|
||||||
TESTS_ENVIRONMENT = NO_VALGRIND=$(NO_VALGRIND)
|
TESTS_ENVIRONMENT = NO_VALGRIND=$(NO_VALGRIND)
|
||||||
|
|
||||||
# This is a magic make variable that causes it to treat tests/man.test as a
|
# This is a magic make variable that causes it to treat tests/man.test as a
|
||||||
@@ -215,7 +215,8 @@ EXTRA_DIST = $(DOC_FILES) $(man_MANS) $(TESTS) $(TEST_LOG_COMPILER) \
|
|||||||
tests/optional.test tests/optionaltest \
|
tests/optional.test tests/optionaltest \
|
||||||
tests/utf8-truncate.jq tests/utf8test \
|
tests/utf8-truncate.jq tests/utf8test \
|
||||||
tests/base64.test tests/base64test \
|
tests/base64.test tests/base64test \
|
||||||
tests/jq-f-test.sh tests/shtest
|
tests/jq-f-test.sh tests/shtest \
|
||||||
|
tests/commenttest
|
||||||
|
|
||||||
DISTCHECK_CONFIGURE_FLAGS=--disable-maintainer-mode --with-oniguruma=builtin
|
DISTCHECK_CONFIGURE_FLAGS=--disable-maintainer-mode --with-oniguruma=builtin
|
||||||
|
|
||||||
|
|||||||
@@ -223,6 +223,7 @@ enum {
|
|||||||
JV_PARSE_SEQ = 1,
|
JV_PARSE_SEQ = 1,
|
||||||
JV_PARSE_STREAMING = 2,
|
JV_PARSE_STREAMING = 2,
|
||||||
JV_PARSE_STREAM_ERRORS = 4,
|
JV_PARSE_STREAM_ERRORS = 4,
|
||||||
|
JV_PARSE_STRIP_COMMENTS = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
jv jv_parse(const char* string);
|
jv jv_parse(const char* string);
|
||||||
|
|||||||
+1
-6
@@ -626,7 +626,6 @@ static pfunc scan_line_comment(struct jv_parser* p, char ch, jv* out) {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static pfunc scan_c_comment_close(struct jv_parser* p, char ch, jv* out) {
|
static pfunc scan_c_comment_close(struct jv_parser* p, char ch, jv* out) {
|
||||||
if(ch == '/') {
|
if(ch == '/') {
|
||||||
p->scan = scan_json;
|
p->scan = scan_json;
|
||||||
@@ -676,11 +675,7 @@ static pfunc scan_json(struct jv_parser* p, char ch, jv* out) {
|
|||||||
presult answer = 0;
|
presult answer = 0;
|
||||||
p->last_ch_was_ws = 0;
|
p->last_ch_was_ws = 0;
|
||||||
if (p->st == JV_PARSER_NORMAL) {
|
if (p->st == JV_PARSER_NORMAL) {
|
||||||
if(ch == '#') {
|
if(ch == '/' && (p->flags & JV_PARSE_STRIP_COMMENTS)) {
|
||||||
p->scan = scan_line_comment;
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
if(ch == '/') {
|
|
||||||
p->scan = scan_slash_comment;
|
p->scan = scan_slash_comment;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ static void usage(int code, int keep_it_short) {
|
|||||||
" -M monochrome (don't colorize JSON);\n"
|
" -M monochrome (don't colorize JSON);\n"
|
||||||
" -S sort keys of objects on output;\n"
|
" -S sort keys of objects on output;\n"
|
||||||
" --tab use tabs for indentation;\n"
|
" --tab use tabs for indentation;\n"
|
||||||
|
" --strip-comments accept and strip comments from input;\n"
|
||||||
" --arg a v set variable $a to value <v>;\n"
|
" --arg a v set variable $a to value <v>;\n"
|
||||||
" --argjson a v set variable $a to JSON value <v>;\n"
|
" --argjson a v set variable $a to JSON value <v>;\n"
|
||||||
" --slurpfile a f set variable $a to an array of JSON texts read from <f>;\n"
|
" --slurpfile a f set variable $a to an array of JSON texts read from <f>;\n"
|
||||||
@@ -454,6 +455,10 @@ int main(int argc, char* argv[]) {
|
|||||||
parser_flags |= JV_PARSE_STREAMING;
|
parser_flags |= JV_PARSE_STREAMING;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isoption(argv[i], 0, "strip-comments", &short_opts)) {
|
||||||
|
parser_flags |= JV_PARSE_STRIP_COMMENTS;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (isoption(argv[i], 0, "stream-errors", &short_opts)) {
|
if (isoption(argv[i], 0, "stream-errors", &short_opts)) {
|
||||||
parser_flags |= JV_PARSE_STREAM_ERRORS;
|
parser_flags |= JV_PARSE_STREAM_ERRORS;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Executable
+15
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. "${0%/*}/setup" "$@"
|
||||||
|
|
||||||
|
if [ "$(echo '{"hi":"there"/*comment*/}' | $VALGRIND $Q $JQ --strip-comments '.hi')" != '"there"' ]; then
|
||||||
|
echo "C-style comment test failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$(printf '{"hi"://comment\n"there"}' | $VALGRIND $Q $JQ --strip-comments '.hi')" != '"there"' ]; then
|
||||||
|
echo "C++-style comment test failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
Reference in new issue
Block a user