This page will provide a few starter hints for using the Proparse libraries.
Follow along in the source code, or else in the 'javadoc' here:
www.joanju.com/analyst/javadoc/
(Ignore the packages 'com.joanju.cg' and 'com.joanju.cgs'. Those are not part of Proparse.)
We use an instance of this class:
RefactorSession prsession = RefactorSession.getInstance();
With our instance, we are able to load our project settings :
prsession.loadProject(projectName);
We usually want to disable the parser's binary serialization output as well, otherwise it would write a huge amount of information into the prorefactor/projects/projectName/pubs directory. (We'd want to keep those only if we wanted to re-load the stored syntax trees very frequently.)
// Disable parser serialization. prsession.setProjectBinariesEnabledOff();
This package contains a number of frequently used classes, such as SymbolScope and Symbol. As examples, there is a SymbolScope for every PROCEDURE, and there is a Symbol for every VARIABLE.
var f = new java.io.File(fileName); ParseUnit pu = new ParseUnit(f);
Note that if you are using Proparse.Net, java.io.File is actually provided by the IKVM libraries! Good thing, since it's required as the input parameter for constructing a ParseUnit.
Now, there are two different methods for building the syntax tree:
parseUnit.treeParser01();
That's the basic method call. It is builds the syntax tree in two passes. The first pass is the basic parser, the second pass builds the symbol tables.
pu.loadOrBuildPUB();
That method call would be useful if you did not setProjectBinariesEnabledOff(), because Proparse would check the file time stamps, and load the syntax tree from the serialized binaries rather than re-parse the source.
Now let's get the topmost node in the syntax tree:
pu.getTopNode()
Also of interest is pu.getRootScope(), because Scopes are where the symbol tables are stored.
This is the base class for nodes in Proparse's syntax tree. Have a look at the javadoc. There are a huge number of methods available in this class, and it also has a few interesting subclasses.
Use the static members of TokenTypes to check on the type of a JPNode. For example:
if (node.getType() == TokenTypes.DEFINE) ...
(TokenTypes inherits all its integer token types from org.prorefactor.treeparserbase.JPTreeParserTokenTypes, which is not published in the javadoc. Your IDE should pop up the complete list when you type TokenTypes. into your editor.)