Chapter 4. The Java Parser

Table of Contents
The Parse Process
Parsing Methods
Rebuilding Methods

The parser code is distributed across various java files:

tools/Argument.java			Handles the arguments of the functions.
tools/ClassDefinition.java		Handles the class definitions.
tools/ConstructorDefinition.java	Handles the constructor definitions.
tools/DefaultConstructorDefinition.java	Handles the constructor default
					definitions.
tools/EnumDefinition.java		Handles the enum definitions.
tools/FlagsDefinition.java		Handles the flag definitions.
tools/MethodDefinition.java		Handles the method definitions.
tools/Parser.java			The main code of the parser.  Calls the
					other classes.
tools/TypeDefinition.java		Handles the type definitions.

The Parser gets called with the arguments defs Gtk, defs Gdk or defs Gnome. It then goes and opens the file defs/gtk.defs, defs/gdk.defs or gnome.defs and parse the appropriate file according to the arguments that was passed to it.

The Parse Process

In this section we will discuss the parcing process in more detail. This is meant to be read with the code and will hopefully help you to get teh general layout of the code.

parseFile sets the comment character to ";" (the StreamTokenizer will ignore everything after a ";"). It also set some other settings to assist in the parsing. It then goes and reads the next token. If the token is a "(" it starts doing the real parsing.

Firstly it calls parseSExpr to parse everything in the round braces. Using recursion parseExpr reads the contents and stores it in a Vector (forming a tree) that it returns.

Depending on the first element of the Vector, the Vector is then parsed (drawn, whipped and forced into submission) further by parseDefineObject, parseDefineBoxed, parseDefineFunc, parseDefineEnum, parseDefineFlags and parseImport. The object/function/enum/flag is added to various Vectors during this process.

Finally rebuildClasses rebuilds the classes and also write the files using the ClassDefinition method saveFile.