Starting With Something Practical

We'll start off with a look at a practical example of how to use the parser to do an ad hoc query into your source code.

The program examples/query_length.p finds LENGTH() functions within the current node which do not provide the second "type" parameter: "CHARACTER," "RAW," or "COLUMN". A query like this might be used as part of your effort to ensure that your application is unicode ready.

Query_length.p is not called directly. It is meant to be called by a program like proparse/api/testrun.p, which takes care of the details of reading through a list of programs to be parsed, parsing each of those, and then handing off the syntax tree to query_length.p.

Because the calling program, testrun.p, has already instantiated the persistent parser interface, proparse.p, we don't need to do it again here. We just need the handle to it, which we call parser. To access the API, all we need to do is include proparse/api/proparse.i, passing it the handle to the parser.

This program uses Proparse's named queries. It creates a query for LENGTH nodes, and then loops through each of the nodes in the query result set. For each node in the result set, it checks to see if the LENGTH function is given the second, optional "type" parameter. If not, then it reports on it.

In practice, you would want to change query_length.p so that it reports each include file only once. ie: Create a temp-table storing each filename/line-number combination only once, and then report on that.