Skip to content

Commit

Permalink
Sync jparse/ with jparse repo w/fixes
Browse files Browse the repository at this point in the history
A missing string in jparse.h/jparse.y was added.

Added extra sanity checks to jstrencode and jstrdecode (to do with NULL
pointers).

Comments in jparse.l were updated as well.

jparse.3 fixes and updates.
  • Loading branch information
xexyl committed Nov 1, 2024
1 parent db85805 commit 5ff60b1
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 96 deletions.
18 changes: 18 additions & 0 deletions jparse/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ subdirectories and the tools/directories under that (in other words under

Fixed comments in some tools.

Fix format/display issue in `jstrdecode -h`.

Add missing `const char *const jparse_utf8_version` (assigned to
`JPARSE_UTF8_VERSION`) and rename `json_parser_version` to
`jparse_library_version` to match the `#define`d macro name, which was changed a
while back.

Improve comments in `jparse.l`, at least for those who are forced to read the
generated code, perhaps in a torture chamber or something like that, or for
those who want hallucinations or nightmares :-) or simply those who are really
curious what flex does.

Add extra sanity checks to `jstrencode(1)` and `jstrdecode(1)` when freeing the
lists. The function `free_jstring_list()` now takes a `struct jstring
**jstring_list` and if not NULL it will set `*jstring_list` to NULL, after
freeing the list, in case the caller does something silly. Even so, the two
tools now set the list to NULL after calling the free function.


## Release 2.0.0 2024-10-31

Expand Down
3 changes: 2 additions & 1 deletion jparse/jparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@
/*
* globals
*/
extern const char *const json_parser_version; /* library version format: major.minor YYYY-MM-DD */
extern const char *const jparse_library_version; /* library version format: major.minor YYYY-MM-DD */
extern const char *const jparse_version; /* jparse version format: major.minor YYYY-MM-DD */
extern const char *const jparse_utf8_version; /* jparse utf8 version format: major.minor YYYY-MM-DD */
/* lexer and parser specific variables */
extern int jparse_debug;

Expand Down
52 changes: 51 additions & 1 deletion jparse/jparse.l
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ static YY_BUFFER_STATE bs;
* Section 1: Patterns (regular expressions) and actions.
*/

/*
* JSON_WS [ \t\r]+
*/
JSON_WS [ \t\r]+
/*
* JSON_NL \n+
*/
JSON_NL \n+
/*
* NOTE: on the subject of JSON_STRING one might ask the question about the
Expand All @@ -128,20 +134,63 @@ JSON_NL \n+
* interested, the old regexp was:
*
* \"([^\n"]|\\\")*\"
*
* ...and this is the current one:
*
* JSON_STRING \"([^"\x01-\x1f]|\\\")*\"
*/
JSON_STRING \"([^"\x01-\x1f]|\\\")*\"
/*
* JSON_INTEGER -?([1-9][0-9]*|0)
*/
JSON_INTEGER -?([1-9][0-9]*|0)
/*
* JSON_FRACTION "."[0-9]+
*/
JSON_FRACTION "."[0-9]+
/*
* JSON_EXPONENT [Ee][-+]?[0-9]+
*/
JSON_EXPONENT [Ee][-+]?[0-9]+
/*
* JSON_NUMBER ({JSON_INTEGER}|{JSON_INTEGER}{JSON_FRACTION}|{JSON_INTEGER}{JSON_FRACTION}{JSON_EXPONENT}|{JSON_INTEGER}{JSON_EXPONENT})
*/
JSON_NUMBER ({JSON_INTEGER}|{JSON_INTEGER}{JSON_FRACTION}|{JSON_INTEGER}{JSON_FRACTION}{JSON_EXPONENT}|{JSON_INTEGER}{JSON_EXPONENT})
/*
* JSON_TRUE "true"
*/
JSON_TRUE "true"
/*
* JSON_FALSE "false"
*/
JSON_FALSE "false"
/*
* JSON_NULL "null"
*/
JSON_NULL "null"
/*
* JSON_OPEN_BRACE "{"
*/
JSON_OPEN_BRACE "{"
/*
* JSON_CLOSE_BRACE "}"
*/
JSON_CLOSE_BRACE "}"
/*
* JSON_OPEN_BRACKET "["
*/
JSON_OPEN_BRACKET "["
/*
* JSON_CLOSE_BRACKET "]"
*/
JSON_CLOSE_BRACKET "]"
/*
* JSON_COLON ":"
*/
JSON_COLON ":"
/*
* JSON_COMMA ","
*/
JSON_COMMA ","
/* Actions. */
Expand Down Expand Up @@ -220,7 +269,8 @@ JSON_COMMA ","
. {
/* invalid token: any other character */
dbg(DBG_LOW, "at line %d column %d: invalid token: 0x%02x = <%c>", yylloc->first_line, yylloc->first_column, *yytext, *yytext);
dbg(DBG_LOW, "at line %d column %d: invalid token: 0x%02x = <%c>", yylloc->first_line,
yylloc->first_column, *yytext, *yytext);
/*
* This is a hack for better error messages with
Expand Down
2 changes: 1 addition & 1 deletion jparse/jparse.lex.ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ extern int yylex \
#undef yyTABLES_NAME
#endif

#line 254 "./jparse.l"
#line 304 "./jparse.l"


#line 732 "jparse.lex.h"
Expand Down
92 changes: 71 additions & 21 deletions jparse/jparse.ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,12 @@ static YY_BUFFER_STATE bs;
/*
* Section 1: Patterns (regular expressions) and actions.
*/
/*
* JSON_WS [ \t\r]+
*/
/*
* JSON_NL \n+
*/
/*
* NOTE: on the subject of JSON_STRING one might ask the question about the
* tighter restrictions on JSON strings and why we don't even consider them.
Expand All @@ -883,9 +889,52 @@ static YY_BUFFER_STATE bs;
* interested, the old regexp was:
*
* \"([^\n"]|\\\")*\"
*
* ...and this is the current one:
*
* JSON_STRING \"([^"\x01-\x1f]|\\\")*\"
*/
/*
* JSON_INTEGER -?([1-9][0-9]*|0)
*/
/*
* JSON_FRACTION "."[0-9]+
*/
/*
* JSON_EXPONENT [Ee][-+]?[0-9]+
*/
/*
* JSON_NUMBER ({JSON_INTEGER}|{JSON_INTEGER}{JSON_FRACTION}|{JSON_INTEGER}{JSON_FRACTION}{JSON_EXPONENT}|{JSON_INTEGER}{JSON_EXPONENT})
*/
/*
* JSON_TRUE "true"
*/
/*
* JSON_FALSE "false"
*/
/*
* JSON_NULL "null"
*/
/*
* JSON_OPEN_BRACE "{"
*/
/*
* JSON_CLOSE_BRACE "}"
*/
/*
* JSON_OPEN_BRACKET "["
*/
/*
* JSON_CLOSE_BRACKET "]"
*/
/*
* JSON_COLON ":"
*/
/*
* JSON_COMMA ","
*/
/* Actions. */
#line 837 "jparse.c"
#line 886 "jparse.c"

#define INITIAL 0

Expand Down Expand Up @@ -1165,9 +1214,9 @@ YY_DECL
}

{
#line 148 "./jparse.l"
#line 197 "./jparse.l"

#line 1119 "jparse.c"
#line 1168 "jparse.c"

while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
Expand Down Expand Up @@ -1238,7 +1287,7 @@ YY_DECL

case 1:
YY_RULE_SETUP
#line 149 "./jparse.l"
#line 198 "./jparse.l"
{
/*
* Whitespace excluding newlines
Expand All @@ -1258,105 +1307,106 @@ YY_RULE_SETUP
case 2:
/* rule 2 can match eol */
YY_RULE_SETUP
#line 165 "./jparse.l"
#line 214 "./jparse.l"
{
yycolumn = 1; /* on newline we need to reset the column for error location tracking */
}
YY_BREAK
case 3:
YY_RULE_SETUP
#line 169 "./jparse.l"
#line 218 "./jparse.l"
{
/* string */
return JSON_STRING;
}
YY_BREAK
case 4:
YY_RULE_SETUP
#line 174 "./jparse.l"
#line 223 "./jparse.l"
{
/* number */
return JSON_NUMBER;
}
YY_BREAK
case 5:
YY_RULE_SETUP
#line 179 "./jparse.l"
#line 228 "./jparse.l"
{
/* null object */
return JSON_NULL;
}
YY_BREAK
case 6:
YY_RULE_SETUP
#line 184 "./jparse.l"
#line 233 "./jparse.l"
{
/* boolean: true */
return JSON_TRUE;
}
YY_BREAK
case 7:
YY_RULE_SETUP
#line 188 "./jparse.l"
#line 237 "./jparse.l"
{
/* boolean: false */
return JSON_FALSE;
}
YY_BREAK
case 8:
YY_RULE_SETUP
#line 193 "./jparse.l"
#line 242 "./jparse.l"
{
/* start of object */
return JSON_OPEN_BRACE;
}
YY_BREAK
case 9:
YY_RULE_SETUP
#line 197 "./jparse.l"
#line 246 "./jparse.l"
{
/* end of object */
return JSON_CLOSE_BRACE;
}
YY_BREAK
case 10:
YY_RULE_SETUP
#line 202 "./jparse.l"
#line 251 "./jparse.l"
{
/* start of array */
return JSON_OPEN_BRACKET;
}
YY_BREAK
case 11:
YY_RULE_SETUP
#line 206 "./jparse.l"
#line 255 "./jparse.l"
{
/* end of array */
return JSON_CLOSE_BRACKET;
}
YY_BREAK
case 12:
YY_RULE_SETUP
#line 211 "./jparse.l"
#line 260 "./jparse.l"
{
/* colon or 'equals' */
return JSON_COLON;
}
YY_BREAK
case 13:
YY_RULE_SETUP
#line 216 "./jparse.l"
#line 265 "./jparse.l"
{
/* comma: name/value pair separator */
return JSON_COMMA;
}
YY_BREAK
case 14:
YY_RULE_SETUP
#line 221 "./jparse.l"
#line 270 "./jparse.l"
{
/* invalid token: any other character */
dbg(DBG_LOW, "at line %d column %d: invalid token: 0x%02x = <%c>", yylloc->first_line, yylloc->first_column, *yytext, *yytext);
dbg(DBG_LOW, "at line %d column %d: invalid token: 0x%02x = <%c>", yylloc->first_line,
yylloc->first_column, *yytext, *yytext);

/*
* This is a hack for better error messages with
Expand Down Expand Up @@ -1389,10 +1439,10 @@ YY_RULE_SETUP
YY_BREAK
case 15:
YY_RULE_SETUP
#line 254 "./jparse.l"
#line 304 "./jparse.l"
YY_FATAL_ERROR( "flex scanner jammed" );
YY_BREAK
#line 1344 "jparse.c"
#line 1394 "jparse.c"
case YY_STATE_EOF(INITIAL):
yyterminate();

Expand Down Expand Up @@ -2554,7 +2604,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)

#define YYTABLES_NAME "yytables"

#line 254 "./jparse.l"
#line 304 "./jparse.l"


/* Section 2: Code that's copied to the generated scanner */
Expand Down
Loading

0 comments on commit 5ff60b1

Please sign in to comment.