Skip to content

Commit 9dfa465

Browse files
committed
main: implement --describe-language option
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent f6e857c commit 9dfa465

File tree

5 files changed

+113
-1
lines changed

5 files changed

+113
-1
lines changed

docs/man/ctags.1.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,9 @@ Listing Options
13221322
Miscellaneous Options
13231323
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13241324

1325+
``--describe-language=<language>``
1326+
Prints the various aspects of the parser implementing the language.
1327+
13251328
``--help``
13261329
Prints to standard output a detailed usage description, and then exits.
13271330

main/options.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ static optionDescription LongOptionDescription [] = {
480480
{1,1," Output list of flags which can be used with --roledef option."},
481481
{1,0,""},
482482
{1,0,"Miscellaneous Options"},
483+
{1,0," --describe-language=<language>"},
484+
{1,0," Print the various aspects of the parser implementing the language."},
483485
{1,0," --help"},
484486
{1,0," Print this option summary."},
485487
{1,0," -? Print this option summary."},
@@ -2306,6 +2308,107 @@ static void processListSubparsersOption (const char *const option CTAGS_ATTR_UNU
23062308
exit (0);
23072309
}
23082310

2311+
static void proecssDescribeLanguage(const char *const option,
2312+
const char *const parameter)
2313+
{
2314+
/* Version, enable */
2315+
if (parameter == NULL || parameter[0] == '\0')
2316+
error (FATAL, "No language given in \"--%s\" option", option);
2317+
2318+
2319+
langType language = getNamedLanguage (parameter, 0);
2320+
if (language == LANG_IGNORE)
2321+
error (FATAL, "Unknown language \"--%s\" in \"%s\"", parameter, option);
2322+
2323+
initializeParser (language);
2324+
2325+
printf("About %s language\n", parameter);
2326+
puts("=======================================================");
2327+
2328+
printf("enabled: %s\n", isLanguageEnabled(language)? "yes": "no");
2329+
printf("version: %u.%u\n",
2330+
getLanguageVersionCurrent (language),
2331+
getLanguageVersionAge (language));
2332+
2333+
puts("");
2334+
puts("Mappings/patterns");
2335+
puts("-------------------------------------------------------");
2336+
printLanguageMaps (language, LMAP_PATTERN|LMAP_NO_LANG_PREFIX,
2337+
localOption.withListHeader, localOption.machinable,
2338+
stdout);
2339+
2340+
puts("");
2341+
puts("Mappings/extensions");
2342+
puts("-------------------------------------------------------");
2343+
printLanguageMaps (language, LMAP_EXTENSION|LMAP_NO_LANG_PREFIX,
2344+
localOption.withListHeader, localOption.machinable,
2345+
stdout);
2346+
2347+
puts("");
2348+
puts("Aliases");
2349+
puts("-------------------------------------------------------");
2350+
printLanguageAliases (language,
2351+
localOption.withListHeader, localOption.machinable, stdout);
2352+
2353+
puts("");
2354+
puts("Kinds");
2355+
puts("-------------------------------------------------------");
2356+
2357+
printLanguageKinds (language, true,
2358+
localOption.withListHeader, localOption.machinable, stdout);
2359+
2360+
puts("");
2361+
puts("Roles");
2362+
puts("-------------------------------------------------------");
2363+
printLanguageRoles (language, "*",
2364+
localOption.withListHeader,
2365+
localOption.machinable,
2366+
stdout);
2367+
2368+
puts("");
2369+
puts("Fields");
2370+
puts("-------------------------------------------------------");
2371+
{
2372+
writerCheckOptions (Option.fieldsReset);
2373+
struct colprintTable * table = fieldColprintTableNew ();
2374+
fieldColprintAddLanguageLines (table, language);
2375+
fieldColprintTablePrint (table, localOption.withListHeader, localOption.machinable, stdout);
2376+
colprintTableDelete (table);
2377+
}
2378+
2379+
puts("");
2380+
puts("Extras");
2381+
puts("-------------------------------------------------------");
2382+
{
2383+
struct colprintTable * table = xtagColprintTableNew ();
2384+
xtagColprintAddLanguageLines (table, language);
2385+
xtagColprintTablePrint (table, localOption.withListHeader, localOption.machinable, stdout);
2386+
colprintTableDelete (table);
2387+
}
2388+
2389+
puts("");
2390+
puts("Parameters");
2391+
puts("-------------------------------------------------------");
2392+
printLanguageParams (language,
2393+
localOption.withListHeader, localOption.machinable,
2394+
stdout);
2395+
2396+
puts ("");
2397+
puts("Sub parsers stacked on this parser");
2398+
puts("-------------------------------------------------------");
2399+
printLanguageSubparsers(language,
2400+
localOption.withListHeader, localOption.machinable,
2401+
stdout);
2402+
2403+
puts("");
2404+
puts("Implementation specific status");
2405+
puts("-------------------------------------------------------");
2406+
printf("allow null tags: %s\n", doesLanguageAllowNullTag(language)? "yes": "no");
2407+
2408+
exit (0);
2409+
2410+
}
2411+
23092412
static void processListOperators (const char *const option CTAGS_ATTR_UNUSED,
23102413
const char *const parameter)
23112414
{
@@ -2864,6 +2967,7 @@ static void processDumpOptionsOption (const char *const option, const char *cons
28642967
static void processDumpPreludeOption (const char *const option, const char *const parameter);
28652968

28662969
static parametricOption ParametricOptions [] = {
2970+
{ "describe-language", proecssDescribeLanguage, true, STAGE_ANY },
28672971
{ "etags-include", processEtagsInclude, false, STAGE_ANY },
28682972
{ "exclude", processExcludeOption, false, STAGE_ANY },
28692973
{ "exclude-exception", processExcludeExceptionOption, false, STAGE_ANY },

main/parse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3762,7 +3762,8 @@ static void printMaps (const langType language, langmapType type)
37623762
unsigned int i;
37633763

37643764
parser = LanguageTable + language;
3765-
printf ("%-8s", parser->def->name);
3765+
if (! (LMAP_NO_LANG_PREFIX & type))
3766+
printf ("%-8s", parser->def->name);
37663767
if (parser->currentPatterns != NULL && (type & LMAP_PATTERN))
37673768
for (i = 0 ; i < stringListCount (parser->currentPatterns) ; ++i)
37683769
printf (" %s", vStringValue (

main/parse_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef enum {
3535
LMAP_EXTENSION = 1 << 1,
3636
LMAP_ALL = LMAP_PATTERN | LMAP_EXTENSION,
3737
LMAP_TABLE_OUTPUT = 1 << 2,
38+
LMAP_NO_LANG_PREFIX = 1 << 3,
3839
} langmapType;
3940

4041
enum parserCategory

man/ctags.1.rst.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,9 @@ Listing Options
13221322
Miscellaneous Options
13231323
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13241324

1325+
``--describe-language=<language>``
1326+
Prints the various aspects of the parser implementing the language.
1327+
13251328
``--help``
13261329
Prints to standard output a detailed usage description, and then exits.
13271330

0 commit comments

Comments
 (0)