Skip to content

Commit 1b4a608

Browse files
committed
main: introduce FOREIGNER dependency type
With initForeignRefTagEntry, you can make a tag for language X when parsing language Y. X had no chance to initialize the parser itself when Y called initForeignRefTagEntry (and makeTagEntry). This change introduces a new dependency FOREIGNER gives the chance. With the dependency type, Y can declare it will use X via initForeignRefTagEntry. The main part of ctags can initialize X just after initializing Y with the declaration as a hint. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
1 parent b6124a6 commit 1b4a608

File tree

5 files changed

+75
-7
lines changed

5 files changed

+75
-7
lines changed

main/dependency.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern void linkDependencyAtInitializeParsing (depType dtype,
4343
{
4444
if (dtype == DEPTYPE_KIND_OWNER)
4545
linkKindDependency (masterKCB, slaveKCB);
46-
else if (dtype == DEPTYPE_SUBPARSER)
46+
else if (dtype == DEPTYPE_SUBPARSER || dtype == DEPTYPE_FOREIGNER)
4747
{
4848
slaveParser *s = xMalloc (1, slaveParser);
4949

@@ -118,8 +118,9 @@ extern void initializeDependencies (parserDefinition *parser,
118118
for (i = 0; i < parser->dependencyCount; i++)
119119
{
120120
parserDependency *d = parser->dependencies + i;
121-
if (d->type == DEPTYPE_SUBPARSER &&
122-
((subparser *)(d->data))->direction & SUBPARSER_SUB_RUNS_BASE)
121+
if ((d->type == DEPTYPE_SUBPARSER &&
122+
((subparser *)(d->data))->direction & SUBPARSER_SUB_RUNS_BASE)
123+
|| (d->type == DEPTYPE_FOREIGNER))
123124
{
124125
langType baseParser;
125126
baseParser = getNamedLanguage (d->upperParser, 0);
@@ -320,6 +321,9 @@ extern void subparserColprintAddSubparsers (struct colprintTable *table,
320321
pushLanguage (scb->owner);
321322
foreachSlaveParser(tmp)
322323
{
324+
if (tmp->type != DEPTYPE_SUBPARSER)
325+
continue;
326+
323327
struct colprintLine *line = colprintTableGetNewLine(table);
324328

325329
colprintLineAppendColumnCString (line, getLanguageName (tmp->id));

main/dependency.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
typedef enum eDepType {
2727
DEPTYPE_KIND_OWNER,
2828
DEPTYPE_SUBPARSER,
29+
DEPTYPE_FOREIGNER,
2930
COUNT_DEPTYPES,
3031
} depType;
3132

main/entry.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ extern void initTagEntry (tagEntryInfo *const e, const char *const name,
137137
int kindIndex);
138138
extern void initRefTagEntry (tagEntryInfo *const e, const char *const name,
139139
int kindIndex, int roleIndex);
140+
141+
/* initForeignRefTagEntry() is for making a tag for the language X when parsing
142+
* source code of Y language.
143+
* From the view point of the language Y, we call the language X a foreign
144+
* language.
145+
*
146+
* When making a tag for a foreign with this function, you must declare the
147+
* language X in the parser of Y with DEPTYPE_FOREIGNER dependency.
148+
*/
140149
extern void initForeignRefTagEntry (tagEntryInfo *const e, const char *const name,
141150
langType type,
142151
int kindIndex, int roleIndex);

main/parse.c

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,19 +1853,37 @@ static void linkDependenciesAtInitializeParsing (parserDefinition *const parser)
18531853
unsigned int i;
18541854
parserDependency *d;
18551855
langType upper;
1856+
parserDefinition *lowerParser;
18561857
parserObject *upperParser;
18571858

18581859
for (i = 0; i < parser->dependencyCount; i++)
18591860
{
18601861
d = parser->dependencies + i;
1861-
upper = getNamedLanguage (d->upperParser, 0);
1862+
1863+
if (d->type == DEPTYPE_FOREIGNER)
1864+
{
1865+
upper = parser->id;
1866+
langType lower = getNamedLanguage (d->upperParser, 0);
1867+
if (lower == LANG_IGNORE)
1868+
error (FATAL,
1869+
"Unknown language: \"%s\" as a foreigner for %s",
1870+
d->upperParser, parser->name);
1871+
1872+
lowerParser = LanguageTable [lower].def;
1873+
}
1874+
else
1875+
{
1876+
upper = getNamedLanguage (d->upperParser, 0);
1877+
lowerParser = parser;
1878+
}
1879+
18621880
upperParser = LanguageTable + upper;
18631881

18641882
linkDependencyAtInitializeParsing (d->type, upperParser->def,
18651883
upperParser->slaveControlBlock,
18661884
upperParser->kindControlBlock,
1867-
parser,
1868-
(LanguageTable + parser->id)->kindControlBlock,
1885+
lowerParser,
1886+
(LanguageTable + lowerParser->id)->kindControlBlock,
18691887
d->data);
18701888
}
18711889
}
@@ -3731,11 +3749,39 @@ static rescanReason createTagsForFile (const langType language,
37313749

37323750
extern void notifyLanguageRegexInputStart (langType language)
37333751
{
3734-
notifyRegexInputStart((LanguageTable + language)->lregexControlBlock);
3752+
parserObject *pobj = LanguageTable + language;
3753+
parserDefinition *pdef = pobj->def;
3754+
3755+
notifyRegexInputStart(pobj->lregexControlBlock);
3756+
for (unsigned int i = 0; i < pdef->dependencyCount; i++)
3757+
{
3758+
parserDependency *d = pdef->dependencies + i;
3759+
if (d->type != DEPTYPE_FOREIGNER)
3760+
continue;
3761+
langType foreigner = getNamedLanguage (d->upperParser, 0);
3762+
if (foreigner == LANG_IGNORE)
3763+
continue;
3764+
3765+
notifyLanguageRegexInputStart (foreigner);
3766+
}
37353767
}
37363768

37373769
extern void notifyLanguageRegexInputEnd (langType language)
37383770
{
3771+
parserObject *pobj = LanguageTable + language;
3772+
parserDefinition *pdef = pobj->def;
3773+
3774+
for (unsigned int i = 0; i < pdef->dependencyCount; i++)
3775+
{
3776+
parserDependency *d = pdef->dependencies + i;
3777+
if (d->type != DEPTYPE_FOREIGNER)
3778+
continue;
3779+
langType foreigner = getNamedLanguage (d->upperParser, 0);
3780+
if (foreigner == LANG_IGNORE)
3781+
continue;
3782+
3783+
notifyLanguageRegexInputEnd (foreigner);
3784+
}
37393785
notifyRegexInputEnd((LanguageTable + language)->lregexControlBlock);
37403786
}
37413787

parsers/rpmspec.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "routines.h"
3232
#include "trace.h"
3333

34+
#include "dependency.h"
3435
#include "autoconf.h"
3536

3637
typedef enum {
@@ -385,10 +386,17 @@ extern parserDefinition* RpmSpecParser (void)
385386
"rpm-spec", /* the mode name in Emacs */
386387
NULL };
387388
parserDefinition* const def = parserNew ("RpmSpec");
389+
390+
static parserDependency dependencies [] = {
391+
[0] = { DEPTYPE_FOREIGNER, "Autoconf", NULL },
392+
};
393+
388394
def->kindTable = RpmSpecKinds;
389395
def->kindCount = ARRAY_SIZE (RpmSpecKinds);
390396
def->extensions = extensions;
391397
def->aliases = aliases;
398+
def->dependencies = dependencies;
399+
def->dependencyCount = ARRAY_SIZE (dependencies);
392400
def->initialize = initializeRpmSpecParser;
393401
def->parser = findRpmSpecTags;
394402
def->method = METHOD_REGEX;

0 commit comments

Comments
 (0)