Skip to content

Commit 9fd8d5d

Browse files
committed
json-writer: provide the way to define extra key and value pair
With the original code, json-writer emits the following form for TAG_ROLE_DESCRIPTION: {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "LANG!KIND", ... This commit is PREPARATION for changing the form like: {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "LANG", "kindName": "KIND", ... In the "parserName" field, two values are embedded. With this change, by specifying jsonObjectKey in the ptag definition, json-writer split the value for parserName into two subvalues. The first subvalue is for "parserName" key, and the second subvalue is for the key specified with jsonObjectKey. This extension is for newer file format. So it is disabled now. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 7bff9af commit 9fd8d5d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

main/ptag_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ struct sPtagDesc {
6969
bool (* makeTag) (ptagDesc *, langType, const void *);
7070

7171
ptagFlag flags;
72+
73+
/* See writer-json.c */
74+
const char *jsonObjectKey;
7275
};
7376

7477
extern bool makePtagIfEnabled (ptagType type, langType language, const void *data);

main/writer-json.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,23 @@ static int writeJsonPtagEntry (tagWriter *writer CTAGS_ATTR_UNUSED,
241241
{
242242
#define OPT(X) ((X)?(X):"")
243243
json_t *response;
244+
char *parserName0 = NULL;
244245

245-
if (parserName)
246+
const char *rest = ((JSON_WRITER_MAJOR > 0) && parserName && desc->jsonObjectKey)
247+
? strchr(parserName, '!')
248+
: NULL;
249+
if (rest)
250+
{
251+
parserName0 = eStrndup(parserName, rest - parserName);
252+
response = json_pack ("{ss ss ss ss ss ss}",
253+
"_type", "ptag",
254+
"name", desc->name,
255+
"parserName", parserName0,
256+
desc->jsonObjectKey, rest + 1,
257+
"path", OPT(fileName),
258+
"pattern", OPT(pattern));
259+
}
260+
else if (parserName)
246261
{
247262
response = json_pack ("{ss ss ss ss ss}",
248263
"_type", "ptag",
@@ -264,6 +279,8 @@ static int writeJsonPtagEntry (tagWriter *writer CTAGS_ATTR_UNUSED,
264279
int length = mio_printf (mio, "%s\n", buf);
265280
free (buf);
266281
json_decref (response);
282+
if (parserName0)
283+
eFree(parserName0);
267284

268285
return length;
269286
#undef OPT

0 commit comments

Comments
 (0)