Package: peoplecodeparser
PeopleCode Parser Built with ANTLR 4AboutThis project provides an implementation of a PeopleCode parser for programs of all types (event PeopleCode and Application Classes).It is initially based on PeopleTools 8.56, but built-in functions (the language constructs most susceptible to change between PeopleTools versions) are not referenced individually in the grammar, thereby making it suitable for other PeopleTools versions as well.GoalsThe primary goal of this parser is to enable applications which analyze PeopleCode and validate coding standards. An example of such an application is theStatic Code Analyzer. Said application can use the parser to enforce rules such as "SQLExecfunction calls shall not use string literals as the first argument" (seetest_parser.pyfor this precise example).Another application of the parser is to build documentation generators, such asAppClassDoc.As mentioned in the "About" section above, the parser grammar does not reference individual built-in functions, which a parser aimed at, say, compiling the language would need to do. For example, it will not enforce the fact that theSQLExecfunction requires a first argument that is either a string or a SQL definition reference, and then has zero or more literals, variable references, Record Field references, etc. Valid PeopleCode programs should be successfully parsed by this parser (with the one exception described further below), but it would also be possible to write a syntactically correct PeopleCode program that would fail to compile due to semantic issues, as in the following absurd example:Local SOME:APPLICATION:Class &anObject;

If SQLExec(&anObject) > &anObject Then
   SomeMadeUpFunction(&anObject);
End-If;This PeopleCode snippet would be accepted as syntactically valid by the parser but would fail to compile in Application Designer.Parser ImplementationSee themain project sitefor details about the parser's implementation.Exceptions to Successful ParsingThe parser was tested against 96,136 PeopleCode programs and Application Classes that fall into one of the following categories:They were delivered by Oracle as part of the PeopleSoft HCM 9.2 application (image #32); orThey were custom code developed by me for one of my customers; orThey were part of the development carried out as part of my dissertation (see theacknowledgementsbelow).Of these PeopleCode programs and Application Classes, 96,134 (99.998%) were parsed successfully, and only two Page PeopleCode programs failed to parse. Both errors are attributable to quirks that occur with Directive PeopleCode. Resolving Directive PeopleCode would require a pre-compilation task, but since this is out of scope for the aforementionedgoals, the parser simply treats Directive PeopleCode as if it weren't there.The first error occurs in theHR_MSS_CT_CONF_FLPage Activate event, reproduced here in its entirety:import HR_GUIDED_SELF_SERVICE:Pages:*;

Declare Function UseGSSActivityGuide PeopleCode FUNCLIB_HR_GSS.HR_MSS_CT_NAME FieldFormula;

Local HR_GUIDED_SELF_SERVICE:Pages:ConfirmationPageActivate &Confirmation;

&Confirmation = create HR_GUIDED_SELF_SERVICE:Pages:ConfirmationPageActivate();
#If #ToolsRel >= "8.55" #Then
   If UseGSSActivityGuide() Then
      &Confirmation.Activate( True);
   Else
      &Confirmation.Activate( False);
   End-If
#Else
&Confirmation.Activate( False);
#End-If;Note how theEnd-Ifimmediately above the#Elsedirective does not have a trailing semicolon. If the Directive PeopleCode statements were not present, the semicolon would actually be required.The second error occurs in thePT_HEADERPAGEPage Activate event (excerpted below):#If #toolsrel < "8.55.13" #Then
   If Not (IsLogoutEnabled()) Then
#Else
   /* 855-13a - Support guest disabling of Signout via permission */
   If Not (IsLogoutEnabled()) Or
         (IsIScriptAuthorized("WEBLIB_PORTAL", "PT_PORTAL_HDRLINK", "FieldFormula", "IScript_HideSignOutLink", %Action_UpdateDisplay) And
            Not (IsUserInRole("PeopleSoft Administrator"))) Then
   #End-If
   
   PT_WORK.PT_BUTTON_LOGOUT.Visible = False;
End-If;When the Directive PeopleCode statements are ignored, the twoIfstatements on the second and fifth lines become unbalanced with the singleEnd-Ifon the last line.Of the 96,136 PeopleCode programs tested, only 256 (0.27%) included Directive PeopleCode, of which only these two (0.78% of all programs with Directive PeopleCode, and 0.002% overall) cause parsing issues. Considering that custom PeopleCode will rarely (if ever) include Directive PeopleCode statements, and that even if it did it would be unlikely to manifest one of these two quirks, I believe we can live with these odds.AcknowledgementsThe parser was intially written out of simple curiosity, but was later included as part of the deliverables for my Master of Science dissertation at the University of Liverpool, titled "A Framework for Customizing ERP Systems to Increase Software Reuse and Reduce Rework When Challenged with Evolving Requirements." I mention this primarily in gratitude to my employer, who graciously waived their claim to intellectual property on my work as part of this academic pursuit.