Updated 2016-08-05 18:04:48 by spjuth
What: nagelfar
Where: http://nagelfar.sourceforge.net
Description: Nagelfar is a Tcl application to read a Tcl program and provide static syntax analysis - information regarding Tcl syntax errors like missing braces, incomplete commands, etc.
Currently at version 1.2.3.
Updated: 2016-08-05
Contact: peter dot spjuth at gmail dot com

This tool by Peter Spjuth performs static syntax analysis. It is, moreover, extensible, with a customizable exposed syntax database.

See the project page for features and fixes in 1.2.1+.

escargo 2014-06-24 - The Sourceforge download link is for the version 1.1.12, and the link from the Sourceforge page to http://nagelfar.berlios.de/ doesn't bring up the expected project page. Peter Spjuth 2015-02-07: The sourceforge site should be in better shape now. A lot was lost in the hasty transition form Berlios.

With version 1.1.11 support for 8.6 is getting better. OO support is still not very friendly but possible. For anyone who wants to try, there are some experiments in the repository: http://git.berlios.de/cgi-bin/cgit.cgi/nagelfar/tree/ootest

As of June 2004, Version 1.0.1 is available. This version can process {expand}, but "[t]o get it to work you still need to generate your own syntax database from 8.5, and run Nagelfar in an 8.5 interpreter ..."

RLH: {expand} is changing to {*}. Just an FYI.

Peter Spjuth: As of version 1.1.6, {*} is supported, and in version 1.1.8 the old {expand} was removed.

From version 1.1, Nagelfar can help with simple Coverage Analysis.

Is there interest in teaching nagelfar about Itcl?

Peter Spjuth: Checking OO code is tricky. I personally don't use Itcl but checking Tk gives similar problems. Once I figure out how to do it well (and get enough time to do it) I'll probably start with Snit since I occasionally use that. After that Itcl is probably not too much work, but it is far into the future unless someone else does it.

The problem with OO is basically that with [cmd arg arg] it is obvious what command is checked, but with [$obj arg arg] you need to know what kind of object is contained in $obj.

RLH I tried 1.1.3 on OSX and I do not seem to be able to build a syntaxdb:
 robert$ sudo tclsh syntaxbuild.tcl
 # Automatically generated syntax database.
 # Generated with syntaxbuild Revision: 1.25

 lappend ::dbInfo {Tcl 8.4.13 unix}
 set ::dbTclVersion 8.4
 set ::knownGlobals {argc argv argv0 auto_index auto_oldpath auto_path env errorCode errorInfo tcl_interactive tcl_libPath tcl_library  set ::syntax(TreeCtrlLoad) 1
 set ::syntax(after) {r 1}
 set ::syntax(append) {n x*}
 set ::syntax(array) {s v x?}
 set {::syntax(array exists)} l
 set {::syntax(array names)} {v x? x?}
 set {::syntax(array set)} {n x}
 set {::syntax(array size)} v
 set {::syntax(array statistics)} v

There was actually a lot more lines...

Peter Spjuth: You didn't specify an output file name, so you got it on standard out. Try 'sudo tclsh syntaxbuild.tcl syntaxdb.tcl'

RLH I will so that. I don't remember having to before though. : )

HZe 2006-07-23 I really would like to use a syntax checker for my project, but it is a bigger project, meaning that there are many files. Most of them are just defining packages and are used later in other files. E.g.:

file1.tcl
  proc square {x} {
      return [expr {$x*$x}]
  } 
  package provide file1 0.1

file2.tcl
  package require file1
  proc main {argv} {
      puts [square [lindex $argv 0]]
  }
  main $argv

I've read, that Nagelfar is using two passes, the first to detect the procs and the second to check them. Here, it would be necessary to detect procs in all files first, then in the second pass use the information to do the check on all files. Is this possible using Nagelfar or do I miss something?

Peter Spjuth: One way is to check all files in one command. Nagelfar remembers procs defined in previous files when it checks the next:
 > nagelfar file1.tcl file2.tcl
 Checking file file1.tcl
 Checking file file2.tcl

This does not work so well if you have cross-calls between files. Then you can generate a header-file before checking:
 > nagelfar -header myprocs file1.tcl file2.tcl
 Checking file file1.tcl
 Checking file file2.tcl
 Writing "myprocs"
 > nagelfar myprocs file1.tcl
 Checking file myprocs
 Checking file file1.tcl
 > nagelfar myprocs file2.tcl
 Checking file myprocs
 Checking file file2.tcl

RLH 2006-12-01: When using the exe version, is there a way to tell Nagelfar not to use the gui?

Peter Spjuth: I don't think so at present. If Nagelfar thinks you are running in wish, and thus do not have a stdout, it always go to GUI. If that assumption is still true and if it is different in the starpack is something I should look at. I have opened FR 2942 for this.

If you get the starkit and wrap it yourself with tclkitsh you can get a command line exe.

[John Hughes] 2006-12-15: I just want to clarify a couple of issues. If you have a large project, like 30KLOC of tcl/tk, and multiple directories, the best way to get Nagelfar to remember procs is to use the header file feature? i.e. I want to run it across all of the directories that comprise my project. And yes, there are some cross calls between some of the files.

Second, does it recognize itcl syntax yet?

Peter Spjuth: In that situation I think generating a header file is the best approach. This might be improved in a later release, FR 2979. No itcl support yet. FR 2569 is open for OO thoughts.

Lorance - 2011-09-13 18:04:07 - Updated 2011-09-17 05:31 PM

I created a compiler plugin for Vim to use Nagelfar to check Tcl files. This is now a more complete package and lives on vim.org. Details at Nagelfar-Vim.

Works best if g:nagelfar_file is pointed to the nagelfar.tcl file. This will use tclsh to execute Nagelfar on the currently open file. Works in Windows if tclsh.exe is in the path. Don't forget to enter ':compiler nagelfar' at some point, otherwise ':make' will use the default compiler.

RLH - +1