Skip to content

Commit 0d95841

Browse files
committed
TclOO: introduce "forceUse" parameter
The original code expects the pattern `namespace import oo' in input. The pattern is used for detecting whether TclOO is used in the input file. However, there can be a case that the pattern is not appeared though the input file uses TclOO: namespace import oo::* source input.tcl To allow users to handle the none-self-contained case manually, this change introduces the parameter `--param-TclOO.forceUse=1`. If the parameter is set, the parser runs as if 'namespace import oo::*' is specified at the head of input files. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 8a87cff commit 0d95841

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

Tmain/list-params.d/stdout-expected.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# ALL
2-
#LANGUAGE NAME DESCRIPTION
3-
CPreProcessor _expand expand macros if their definitions are in the current C/C++/CUDA input file (true or [false])
4-
CPreProcessor define define replacement for an identifier (name(params,...)=definition)
5-
CPreProcessor if0 examine code within "#if 0" branch (true or [false])
6-
CPreProcessor ignore a token to be specially handled
7-
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
2+
#LANGUAGE NAME DESCRIPTION
3+
CPreProcessor _expand expand macros if their definitions are in the current C/C++/CUDA input file (true or [false])
4+
CPreProcessor define define replacement for an identifier (name(params,...)=definition)
5+
CPreProcessor if0 examine code within "#if 0" branch (true or [false])
6+
CPreProcessor ignore a token to be specially handled
7+
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
8+
TclOO forceUse enable the parser even when `oo' namespace is not specified in the input (true or [false])
89

910
# ALL MACHINABLE
1011
#LANGUAGE NAME DESCRIPTION
@@ -13,13 +14,15 @@ CPreProcessor define define replacement for an identifier (name(params,...)=defi
1314
CPreProcessor if0 examine code within "#if 0" branch (true or [false])
1415
CPreProcessor ignore a token to be specially handled
1516
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
17+
TclOO forceUse enable the parser even when `oo' namespace is not specified in the input (true or [false])
1618

1719
# ALL MACHINABLE NOHEADER
1820
CPreProcessor _expand expand macros if their definitions are in the current C/C++/CUDA input file (true or [false])
1921
CPreProcessor define define replacement for an identifier (name(params,...)=definition)
2022
CPreProcessor if0 examine code within "#if 0" branch (true or [false])
2123
CPreProcessor ignore a token to be specially handled
2224
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
25+
TclOO forceUse enable the parser even when `oo' namespace is not specified in the input (true or [false])
2326

2427
# CPP
2528
#NAME DESCRIPTION
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--sort=no
2+
--param-TclOO.forceUse=1
3+
--fields=+{language}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
X input.tcl /^class create X {$/;" c language:TclOO
2+
add input.tcl /^ method add v {$/;" m language:TclOO class:X
3+
doSomething input.tcl /^ }; method doSomething {v} {$/;" m language:TclOO class:X
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Assume this source file is loaded from
2+
# another source file:
3+
#
4+
# namespace import oo::*
5+
# source input.tcl
6+
#
7+
class create X {
8+
method add v {
9+
}; method doSomething {v} {
10+
}
11+
}

parsers/tcloo.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "general.h" /* must always come first */
1010
#include "tcl.h"
11+
#include "param.h"
1112
#include "parse.h"
1213
#include "entry.h"
1314
#include "tokeninfo.h"
@@ -35,6 +36,8 @@ static kindDefinition TclOOKinds[] = {
3536
ATTACH_SEPARATORS(TclOOGenericSeparators) },
3637
};
3738

39+
static bool tclooForceUse;
40+
3841
static void parseMethod (tokenInfo *token, int owner)
3942
{
4043
tokenRead (token);
@@ -141,7 +144,7 @@ static void inputStart (subparser *s)
141144
{
142145
struct tclooSubparser *tcloo = (struct tclooSubparser *)s;
143146

144-
tcloo->foundTclOONamespaceImported = false;
147+
tcloo->foundTclOONamespaceImported = tclooForceUse;
145148
}
146149

147150
static struct tclooSubparser tclooSubparser = {
@@ -160,6 +163,19 @@ static void findTclOOTags(void)
160163
scheduleRunningBaseparser (RUN_DEFAULT_SUBPARSERS);
161164
}
162165

166+
static void tclooForceUseParamHandler (const langType language CTAGS_ATTR_UNUSED,
167+
const char *name, const char *arg)
168+
{
169+
tclooForceUse = paramParserBool (arg, tclooForceUse, name, "parameter");
170+
}
171+
172+
static parameterHandlerTable TclOOParameterHandlerTable [] = {
173+
{ .name = "forceUse",
174+
.desc = "enable the parser even when `oo' namespace is not specified in the input (true or [false])" ,
175+
.handleParameter = tclooForceUseParamHandler,
176+
},
177+
};
178+
163179
extern parserDefinition* TclOOParser (void)
164180
{
165181
parserDefinition* const def = parserNew("TclOO");
@@ -178,5 +194,8 @@ extern parserDefinition* TclOOParser (void)
178194
def->useCork = CORK_QUEUE;
179195
def->requestAutomaticFQTag = true;
180196

197+
def->parameterHandlerTable = TclOOParameterHandlerTable;
198+
def->parameterHandlerCount = ARRAY_SIZE(TclOOParameterHandlerTable);
199+
181200
return def;
182201
}

0 commit comments

Comments
 (0)