/* try_me.p

Quick demonstration.
Runs tokenlister.p to show how tokens in a syntax tree can be displayed.
Runs testrun.p and query_length.p to show how the parser can be used
for queries to analyse your source code.

*/


DEFINE VARIABLE ql_outfile  AS CHARACTER NO-UNDO.
DEFINE VARIABLE tokenlister AS HANDLE    NO-UNDO.

ASSIGN ql_outfile = SESSION:TEMP-DIRECTORY + "/joanju_qry_len.out".

/* If the proparse api can't be found, then assume that this
 * is being run as a double-click from within the proparse directory.
 */
IF SEARCH("proparse/sampledata/smalltest.p") = ? THEN
  PROPATH = PROPATH + ",..".


MESSAGE
  "First: proparse/api/tokenlister.p"
  "~n~n"
  "Parse a program, and then recursively walk through"
  "the syntax tree to display all tokens in it."
  "~n~n"
  "Press Esc to close the following window."
  VIEW-AS ALERT-BOX INFORMATION.

RUN proparse/api/tokenlister.p PERSISTENT SET tokenlister.
RUN setParseFile IN tokenlister ("proparse/sampledata/smalltest.p").
RUN main IN tokenlister.
APPLY "CLOSE":U TO tokenlister.

MESSAGE
  "Next: proparse/api/testrun.p"
  "~n~n"
  "Parse a list of files. Test each resulting syntax tree against"
  "the Progress equivalent preprocess output (optional)."
  "~n~n"
  "Run an optional function against each syntax tree."
  "In our example here, we run examples/query_length.p, which looks" 
  "for specific LENGTH function calls."
  "~n~n"
  "There's only one program in this example file list."
  VIEW-AS ALERT-BOX INFORMATION.

/* Clear the query_length results file */
OUTPUT TO VALUE(ql_outfile). OUTPUT CLOSE.

RUN proparse/api/testrun.p ("proparse/sampledata/filelist.txt", "proparse/examples/query_length.p").

MESSAGE
  "Finally: view the results of our testrun.p -> query_length.p combination."
  "~n~nquery_length.p was looking for all instances of the LENGTH function which do not"
  'provide the second optional "type" parameter: "CHARACTER," "RAW," or "COLUMN".'
  "~n~nFor each instance found, the program name, the include file name, and the"
  "line number are displayed, followed by the text of the LENGTH function call."
  VIEW-AS ALERT-BOX INFORMATION.

RUN proparse/utilities/resultswindow.p (ql_outfile).

OS-DELETE VALUE(ql_outfile).
