Skip to content

Commit 34f1c6a

Browse files
committed
Tcl,TclOO: don't consume input if a subparser extracts something
A subparser may consume the input upto the end of a command line (EOCL) when the subparser extracts something. So consuming input upto EOCL in the base parser, here Tcl parser, after the extraction causes unexpected skipping. Calling skipToEndOfCmdline for consuming input should be done only when any subparser extracts nothing.
1 parent c446f2e commit 34f1c6a

File tree

6 files changed

+47
-4
lines changed

6 files changed

+47
-4
lines changed

Units/parser-itcl.r/simple-itcl.d/expected.tags

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ commonProtected input.tcl /^ protected proc commonProtected "b"$/;" kind:proc
3030
SmartToaster::commonProtected input.tcl /^ protected proc commonProtected "b"$/;" kind:procedure line:48 language:ITcl scope:class:SmartToaster access:protected roles:def extras:qualified,subparser end:48
3131
commonPrivate input.tcl /^ private proc commonPrivate "c"$/;" kind:procedure line:49 language:ITcl scope:class:SmartToaster access:private roles:def extras:subparser end:49
3232
SmartToaster::commonPrivate input.tcl /^ private proc commonPrivate "c"$/;" kind:procedure line:49 language:ITcl scope:class:SmartToaster access:private roles:def extras:qualified,subparser end:49
33+
X input.tcl /^itcl::class X {$/;" kind:class line:51 language:ITcl roles:def extras:subparser
34+
x input.tcl /^ variable x 0$/;" kind:variable line:52 language:ITcl scope:class:X roles:def extras:subparser end:52
35+
X::x input.tcl /^ variable x 0$/;" kind:variable line:52 language:ITcl scope:class:X roles:def extras:qualified,subparser end:52
36+
Y input.tcl /^itcl::class Y {$/;" kind:class line:54 language:ITcl roles:def extras:subparser
37+
y input.tcl /^ variable y 0$/;" kind:variable line:55 language:ITcl scope:class:Y roles:def extras:subparser end:55
38+
Y::y input.tcl /^ variable y 0$/;" kind:variable line:55 language:ITcl scope:class:Y roles:def extras:qualified,subparser end:55

Units/parser-itcl.r/simple-itcl.d/input.tcl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ itcl::class SmartToaster {
4848
protected proc commonProtected "b"
4949
private proc commonPrivate "c"
5050
}
51+
itcl::class X {
52+
variable x 0
53+
}
54+
itcl::class Y {
55+
variable y 0
56+
}
5157

5258
set toaster [SmartToaster #auto]
5359
$toaster toast 2
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--sort=no
2+
--fields=+li
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
S input.tcl /^oo::class create S {$/;" c language:TclOO
2+
sx input.tcl /^ method sx {} {$/;" m language:TclOO class:S
3+
M input.tcl /^oo::class create M {$/;" c language:TclOO
4+
mx input.tcl /^ method mx {} {$/;" m language:TclOO class:M
5+
C input.tcl /^oo::class create C {$/;" c language:TclOO inherits:S
6+
cx input.tcl /^ method cx {} {$/;" m language:TclOO class:C
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
oo::class create S {
2+
variable x
3+
method sx {} {
4+
set x 0
5+
}
6+
}
7+
oo::class create M {
8+
variable x
9+
method mx {} {
10+
incr x 3
11+
}
12+
}
13+
oo::class create C {
14+
superclass S
15+
mixin M
16+
variable x
17+
method cx {} {
18+
incr x 5
19+
}
20+
}
21+
# Taken from https://wiki.tcl-lang.org/page/Variables+in+TclOO

parsers/tcl.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,9 @@ static void parseNamespace (tokenInfo *const token,
632632
parseProc (token, index);
633633
else if (tokenIsType (token, TCL_IDENTIFIER))
634634
{
635-
notifyCommand (token, index);
636-
skipToEndOfCmdline(token); /* ??? */
635+
int r = notifyCommand (token, index);
636+
if (r == CORK_NIL)
637+
skipToEndOfCmdline(token);
637638
}
638639
else if (token->type == '}')
639640
{
@@ -682,8 +683,9 @@ static void findTclTags (void)
682683
parsePackage (token);
683684
else if (tokenIsType (token, TCL_IDENTIFIER))
684685
{
685-
notifyCommand (token, CORK_NIL);
686-
skipToEndOfCmdline(token); /* ??? */
686+
int r = notifyCommand (token, CORK_NIL);
687+
if (r == CORK_NIL)
688+
skipToEndOfCmdline(token);
687689
}
688690
else
689691
skipToEndOfCmdline(token);

0 commit comments

Comments
 (0)