procs example {a} {
set b [lindex $a 0]
puts "$a $c"
set e [lindex $a end dummy]
foreach d $a {
if {$d==a} {
putd $d
}
}
}
syntax checker will find following errors
procs example {a} {
set b [lindex $a 0]
puts "$a $c"
unknown variable c
set e [lindex $a end dummy]
await (2,2) arguments
foreach d $a {
if {$d==a} {
putd $d
unknown proc
}
}
}
Class Test -parameter {par1}
Test instproc foo1 {a {b 1}} {
puts "[self] $a $b"
}
# Method to check
Test instproc foo2 {b} {
my foo1 test
my foo1 test 1 2
await (1,2) arguments
foreach elem $b {
puts "[my par1] $elem"
my par1 $elem
my foo3
unknown instproc
}
set c $d
unknown variable d
}
If the errors showed by syntax checker are not really errors or you have corrected the syntax errors directly you can press the button Force Saving. The code showed in editor will be so accepted without syntax check.
If you want to force syntax check without accepting choose menu Edit>Syntax Highlight>Force Syntax Check
You can produce a protocol of checking as text file with menu Syntax Check->Protocol to file
Another ways of using Tcl parser in Tcl.
It will be probably better way to ask the original interpreter for parsing-tree. In the fact has Tcl interpreter an internal tree with all information you need. The accessing to this tree is not a part of standard Tcl so one must write a Tcl c-extension. Some folk do not like Tcl c-extension and want alway have a Tcl-pure solution even for such thinks as object-oriented Tcl.
# while proc
[$command getElem 1] substituteContents
[$command getElem 2] evalContents
# set proc
if {$count==2} {
my addVariableFrom [$command getElem 1]
} else {
my checkVariableFrom [$command getElem 1] $notifier
}
It will be not difficult to extent the semantic for over commands.
set a putd
$a hallo
set a c
set $a 2
puts $c
"$a hallo" will be not reported as error but "puts $c" report error "unknown variable c".
If you want to force by the checker to accept one variable use "add variables (varName varName2)"
# add variables (c)
set a c
set $a 3
puts $c
set a [MyClass new]
$a doJob
# also direct call by object name
MyClass myObject
myObject doJob
The first method call will be not checked.
The checker has no information what is $a.
The second method call will be reported with error "no such proc" (myObject).
This second art of call should be very seldom in xotcl programs (beside of using global singleton objects).
To solve the problem the checker need some more type information.
It could be coded as meta information to the class.
for example:
Class A
A addMetaVariable drawContext DrawContext
A instproc draw {} {
my instvar drawContext
$drawContext drawLine 0 2 0 50
}
In this case the Syntax Checker would know that "drawContext" reference to object of class "DrawContext".
The same thing could be done for methods arguments or even all variables by using special in-line directives
set a [MyClass new]
# variableType a MyClass
$a doJob
This were a back door to make tcl type-safe if you want it.
The good think is the meta type information can be collected by doing analyze of running system (for example by using XOTcl filters).
This type informations can be also used to build XOTcl assertions.
So there is a chance to make very powerful Tcl developing systems even with type safe syntax checking.