Skip to content

Commit cecb4a1

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

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CPreProcessor define define replacement for an identifier (name(params,...)=d
55
CPreProcessor if0 examine code within "#if 0" branch (true or [false])
66
CPreProcessor ignore a token to be specially handled
77
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
8+
ITcl forceUse enable the parser even when `itcl' namespace is not specified in the input (true or [false])
89
TclOO forceUse enable the parser even when `oo' namespace is not specified in the input (true or [false])
910

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

1921
# ALL MACHINABLE NOHEADER
@@ -22,6 +24,7 @@ CPreProcessor define define replacement for an identifier (name(params,...)=defi
2224
CPreProcessor if0 examine code within "#if 0" branch (true or [false])
2325
CPreProcessor ignore a token to be specially handled
2426
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
27+
ITcl forceUse enable the parser even when `itcl' namespace is not specified in the input (true or [false])
2528
TclOO forceUse enable the parser even when `oo' namespace is not specified in the input (true or [false])
2629

2730
# CPP
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--sort=no
2+
--param-ITcl.forceUse=1
3+
--fields=+{language}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MyClass input.tcl /^class MyClass {$/;" c language:ITcl
2+
foo input.tcl /^ public method foo {} {$/;" m language:ITcl class:MyClass
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Assume this source file is loaded from
2+
# another source file:
3+
#
4+
# package require Itcl
5+
# namespace import itcl::*
6+
# source input.tcl
7+
#
8+
class MyClass {
9+
public method foo {} {
10+
}
11+
}
12+
13+
body MyClass::foo {} {
14+
}

parsers/itcl.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "general.h" /* must always come first */
1010
#include "tcl.h"
1111
#include "entry.h"
12+
#include "param.h"
1213
#include "parse.h"
1314
#include "read.h"
1415
#include "keyword.h"
@@ -70,6 +71,8 @@ static const keywordTable ITclKeywordTable[] = {
7071
{ "proc", KEYWORD_PROC },
7172
};
7273

74+
static bool itclForceUse;
75+
7376
static keywordId resolveKeyword (vString *string)
7477
{
7578
char *s = vStringValue (string);
@@ -277,7 +280,7 @@ static void inputStart (subparser *s)
277280
{
278281
struct itclSubparser *itcl = (struct itclSubparser *)s;
279282

280-
itcl->foundITclNamespaceImported = false;
283+
itcl->foundITclNamespaceImported = itclForceUse;
281284
}
282285

283286
struct itclSubparser itclSubparser = {
@@ -296,6 +299,19 @@ static void findITclTags(void)
296299
scheduleRunningBaseparser (RUN_DEFAULT_SUBPARSERS);
297300
}
298301

302+
static void itclForceUseParamHandler (const langType language CTAGS_ATTR_UNUSED,
303+
const char *name, const char *arg)
304+
{
305+
itclForceUse = paramParserBool (arg, itclForceUse, name, "parameter");
306+
}
307+
308+
static parameterHandlerTable ItclParameterHandlerTable [] = {
309+
{ .name = "forceUse",
310+
.desc = "enable the parser even when `itcl' namespace is not specified in the input (true or [false])" ,
311+
.handleParameter = itclForceUseParamHandler,
312+
},
313+
};
314+
299315
extern parserDefinition* ITclParser (void)
300316
{
301317
static const char *const extensions [] = { "itcl", NULL };
@@ -319,5 +335,8 @@ extern parserDefinition* ITclParser (void)
319335
def->keywordTable = ITclKeywordTable;
320336
def->keywordCount = ARRAY_SIZE (ITclKeywordTable);
321337

338+
def->parameterHandlerTable = ItclParameterHandlerTable;
339+
def->parameterHandlerCount = ARRAY_SIZE(ItclParameterHandlerTable);
340+
322341
return def;
323342
}

0 commit comments

Comments
 (0)