Skip to content

Commit d34d67c

Browse files
committed
lregex: provide the way to intercept a parser making a tag
TBW Known issue: initForeignRefTagEntry doesn't work well. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent b6124a6 commit d34d67c

11 files changed

+57
-6
lines changed

main/dependency.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "debug.h"
1616
#include "dependency.h"
17+
#include "entry.h"
1718
#include "options.h"
1819
#include "parse_p.h"
1920
#include "read.h"
@@ -183,14 +184,18 @@ extern void notifyMakeTagEntry (const tagEntryInfo *tag, int corkIndex)
183184
{
184185
subparser *s;
185186

187+
/* running optscript code attaching to --makeTagEntryReflection-<LANG> */
188+
langType lang = tag->langType;
189+
notifyLanguageRegexMakeTagEntry (lang, corkIndex);
190+
186191
foreachSubparser(s, false)
187192
{
193+
enterSubparser(s);
188194
if (s->makeTagEntryNotify)
189-
{
190-
enterSubparser(s);
191195
s->makeTagEntryNotify (s, tag, corkIndex);
192-
leaveSubparser();
193-
}
196+
/* propagate the event recursively */
197+
notifyMakeTagEntry (tag, corkIndex);
198+
leaveSubparser();
194199
}
195200
}
196201

main/dependency.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ struct sSlaveParser {
4242
slaveParser *next;
4343
};
4444

45+
/* These are for CPreProcessor.
46+
* Don't use in the other parsers. */
47+
extern void notifyInputStart (void);
48+
extern void notifyInputEnd (void);
49+
4550
#endif /* CTAGS_MAIN_DEPENDENCY_H */

main/lregex.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,14 @@ extern void notifyRegexInputEnd (struct lregexControlBlock *lcb)
20272027
fillEndLineFieldOfUpperScopes (lcb, endline);
20282028
}
20292029

2030+
extern void notifyRegexMakeTagEntry (struct lregexControlBlock *lcb,
2031+
int corkIndex)
2032+
{
2033+
optscriptSetup (optvm, lcb->local_dict, corkIndex);
2034+
scriptEvalHook (optvm, lcb, SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION);
2035+
optscriptTeardown (optvm, lcb->local_dict);
2036+
}
2037+
20302038
extern void findRegexTagsMainloop (int (* driver)(void))
20312039
{
20322040
/* merely read all lines of the file */

main/lregex_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extern bool matchMultitableRegex (struct lregexControlBlock *lcb, const vString*
6969

7070
extern void notifyRegexInputStart (struct lregexControlBlock *lcb);
7171
extern void notifyRegexInputEnd (struct lregexControlBlock *lcb);
72+
extern void notifyRegexMakeTagEntry (struct lregexControlBlock *lcb, int corkIndex);
7273

7374
extern void addRegexTable (struct lregexControlBlock *lcb, const char *name);
7475
extern void extendRegexTable (struct lregexControlBlock *lcb, const char *src, const char *dist);

main/options.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ static optionDescription LongOptionDescription [] = {
377377
{1,1," Define new extra for <LANG>. --extras-<LANG>=+{name} enables it."},
378378
{1,1," --_fielddef-<LANG>=<name>,<description>"},
379379
{1,1," Define new field for <LANG>."},
380+
{1,1," --_makeTagEnryReflection-<LANG>={{ optscript-code }}"},
381+
{1,1," Specify code run when <LANG> parser makes a tag."},
380382
{1,1," --_mtable-extend-<LANG>=disttable+srctable."},
381383
{1,1," Copy patterns of a regex table to another regex table."},
382384
{1,1," --_mtable-regex-<LANG>=<table>/<line_pattern>/<name_pattern>/[<flags>]"},
@@ -3337,6 +3339,8 @@ static void processLongOption (
33373339
;
33383340
else if (processSequelOption (option, parameter))
33393341
;
3342+
else if (processMakeTagEntryReflectionOption (option, parameter))
3343+
;
33403344
else if (processPretendOption (option, parameter))
33413345
;
33423346
else if (processRolesOption (option, parameter))

main/options_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ extern bool processRoledefOption (const char *const option, const char *const pa
176176
extern bool processScopesepOption (const char *const option, const char *const parameter);
177177
extern bool processPreludeOption (const char *const option, const char *const parameter);
178178
extern bool processSequelOption (const char *const option, const char *const parameter);
179+
extern bool processMakeTagEntryReflectionOption (const char *const option, const char *const parameter);
179180
extern bool processPretendOption (const char *const option, const char *const parameter);
180181
extern bool processRolesOption (const char *const option, const char *const parameter);
181182

main/parse.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3739,6 +3739,11 @@ extern void notifyLanguageRegexInputEnd (langType language)
37393739
notifyRegexInputEnd((LanguageTable + language)->lregexControlBlock);
37403740
}
37413741

3742+
extern void notifyLanguageRegexMakeTagEntry (langType language, int corkIndex)
3743+
{
3744+
notifyRegexMakeTagEntry((LanguageTable + language)->lregexControlBlock, corkIndex);
3745+
}
3746+
37423747
static unsigned int parserCorkFlags (parserDefinition *parser)
37433748
{
37443749
subparser *tmp;
@@ -5050,6 +5055,11 @@ extern bool processSequelOption (const char *const option, const char *const par
50505055
return processHookOption (option, parameter, "_sequel-", SCRIPT_HOOK_SEQUEL);
50515056
}
50525057

5058+
extern bool processMakeTagEntryReflectionOption (const char *const option, const char *const parameter)
5059+
{
5060+
return processHookOption (option, parameter, "_makeTagEntryReflection-", SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION);
5061+
}
5062+
50535063
extern bool processPretendOption (const char *const option, const char *const parameter)
50545064
{
50555065
langType new_language, old_language;

main/parse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ typedef enum {
7474
enum scriptHook {
7575
SCRIPT_HOOK_PRELUDE,
7676
SCRIPT_HOOK_SEQUEL,
77+
SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION,
7778
SCRIPT_HOOK_MAX,
7879
};
7980

main/parse_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ extern void freeEncodingResources (void);
140140
extern bool processLanguageRegexOption (langType language, enum regexParserType regptype, const char *const parameter);
141141
extern void notifyLanguageRegexInputStart (langType language);
142142
extern void notifyLanguageRegexInputEnd (langType language);
143+
extern void notifyLanguageRegexMakeTagEntry (langType language, int corkIndex);
143144

144145
extern void matchLanguageRegex (const langType language, const vString* const line);
145146
extern void freeRegexResources (void);

main/subparser_p.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ extern langType getSubparserLanguage (subparser *s);
2929

3030
/* A base parser doesn't have to call the following three functions.
3131
The main part calls them internally. */
32-
extern void notifyInputStart (void);
33-
extern void notifyInputEnd (void);
3432
extern void notifyMakeTagEntry (const tagEntryInfo *info, int corkIndex);
3533

3634
extern void setupSubparsersInUse (struct slaveControlBlock *controlBlock);

parsers/cpreprocessor.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <string.h>
1717

1818
#include "debug.h"
19+
#include "dependency.h" /* notifyInputStart, notifyInputEnd */
1920
#include "entry.h"
2021
#include "htable.h"
2122
#include "cpreprocessor.h"
@@ -348,6 +349,14 @@ static void cppInitCommon(langType clientLang,
348349
: clientLang) & CORK_SYMTAB))
349350
? makeMacroTable ()
350351
: NULL;
352+
353+
if (Cpp.lang != Cpp.clientLang
354+
&& Cpp.clientLang != LANG_IGNORE)
355+
{
356+
pushLanguage (Cpp.lang);
357+
notifyInputStart ();
358+
popLanguage ();
359+
}
351360
}
352361

353362
extern void cppInit (const bool state, const bool hasAtLiteralStrings,
@@ -381,6 +390,14 @@ static void cppClearMacroInUse (cppMacroInfo **pM)
381390

382391
extern void cppTerminate (void)
383392
{
393+
if (Cpp.lang != Cpp.clientLang
394+
&& Cpp.clientLang != LANG_IGNORE)
395+
{
396+
pushLanguage (Cpp.lang);
397+
notifyInputEnd ();
398+
popLanguage ();
399+
}
400+
384401
if (Cpp.directive.name != NULL)
385402
{
386403
vStringDelete (Cpp.directive.name);

0 commit comments

Comments
 (0)