Teapot: Details on Extending Programmer's Editors

Extending WinEdit2000

This page discusses the hooks for extending programmer's editors.

The extension hook is set up by configuring the programmers' editor so that it can ask a seperate compiler program to compile the source code file which is currently being edited in WinEdit. The communication between the editor and the compiler is done via command line similar to a DOS prompt box. The editor sends in the name of the file to compile and the compiler sends out and error messages using some standard format.

For example, "javac <fileNameToCompile>" is the way to compile Java source files. The programmer configures WinEdit2000 in a dialog which sets up the compile command for each type of file, for example, C, Java, Basic. Once the editor is configured to work with an external command line compiler, compiling source becomes much more convenient. The programmer can simply pull down a menu and have the editor compile the file. The programmer's editor essentially does the typing for you to kick the parser into action.

Here's more details on what happens when the programmer pulls down that menu to have the current open file compiled. The editor saves the file and then invokes the compiler on that same file by passing the file name on the command line. The compiler reports any errors that occured in the source file. The reporting is possible because compilers generate error messages according to standard formats. For example, there is one standard for MS tools and another for Java error messages. the editor can read the output of the compiler The editor reads these error messages to find out such things as: what file the error occured in (which might not be the file which the compiler was invoked on), the line number (and sometimes even the column number) where the error was detected, and the description of the error.

The error messages formats conform to simple patterns. Although there are some trivial variations between different compilers, as mentioned above they all contains essentially the same information. On the Windows platform, the Microsoft error file format is widely prevelent among compiler tools. This is the default format that the teapot code generates error messages in. The format of the error messages in the Microsoft style is essentially as follows:
         <fullFileNameOfBadFile>(<lineNumerOfError>): error: <errorMessage>
For example:
         C:\foo\bar.xml(17): error: illegal character

After parsing the error message, the editor automatically loads the offending file (if not already open), the input cursor is positioned on the appropriate line, and the error message is displayed to the user. The programmer reads the displayed error message and looks at the file to figure out what is wrong. All of this is simply a convenience for the programmer. The programmer could have saved the file in Notepad, switched to a DOS box, evoked the compiler on the file just saved, manually read the error messages, switched back to Notepad, opened the offending file, moved the cursor to the right line and fixed the problem. The programmers' editor simply saves the programmer from this hassle.

For teapot and XML files, what's happening under the hood is that WinEdit spins up a DOS box and runs the follow:

teapot.exe -r -x <xmlFilesName>

WinEdit grabs the output text from teapot.exe and parses any error messages in order to determine which file to open and what line to scroll to. Well, as you see, nothing special happening there but it is a much more pleasent XML editing experience than constantly switching between a parser in a command line DOS box and notepad.exe.