@@ -28,6 +28,8 @@ const lineTokens = (input: string, lineNumber: number, lineIndex: number): Token
2828 return tokens ;
2929}
3030
31+ const PROGRAMPARMS_NAME = `PROGRAMPARMS` ;
32+
3133export default class Parser {
3234 parsedCache : { [ thePath : string ] : Cache } = { } ;
3335 tables : TableDetail = { } ;
@@ -951,40 +953,48 @@ export default class Parser {
951953
952954 case `DCL-PI` :
953955 //Procedures can only exist in the global scope.
954- if ( currentProcName ) {
955- if ( parts . length > 0 ) {
956+ if ( parts . length > 0 ) {
957+ if ( currentProcName ) {
956958 currentGroup = `procedures` ;
957959 currentItem = scopes [ 0 ] . procedures . find ( proc => proc . name === currentProcName ) ;
960+ } else {
961+ currentItem = new Declaration ( `struct` ) ;
962+ currentItem . name = PROGRAMPARMS_NAME ;
963+ }
958964
965+ if ( currentItem ) {
959966 const endInline = tokens . findIndex ( part => part . value . toUpperCase ( ) === `END-PI` ) ;
960967
961- if ( currentItem ) {
962-
963- // Indicates that the PI starts and ends on the same line
964- if ( endInline >= 0 ) {
965- tokens . splice ( endInline , 1 ) ;
966- currentItem . readParms = false ;
967- resetDefinition = true ;
968- }
969-
970- currentItem . keyword = {
971- ...currentItem . keyword ,
972- ...Parser . expandKeywords ( tokens . slice ( 2 ) )
973- }
974- currentItem . readParms = true ;
968+ // Indicates that the PI starts and ends on the same line
969+ if ( endInline >= 0 ) {
970+ tokens . splice ( endInline , 1 ) ;
971+ currentItem . readParms = false ;
972+ resetDefinition = true ;
973+ }
975974
976- currentDescription = [ ] ;
975+ currentItem . keyword = {
976+ ...currentItem . keyword ,
977+ ...Parser . expandKeywords ( tokens . slice ( 2 ) )
977978 }
979+ currentItem . readParms = true ;
980+
981+ currentDescription = [ ] ;
978982 }
979983 }
980984 break ;
981985
982986 case `END-PI` :
983987 //Procedures can only exist in the global scope.
984- currentItem = scopes [ 0 ] . procedures . find ( proc => proc . name === currentProcName ) ;
988+ if ( currentProcName ) {
989+ currentItem = scopes [ 0 ] . procedures . find ( proc => proc . name === currentProcName ) ;
985990
986- if ( currentItem && currentItem . type === `procedure` ) {
987- currentItem . readParms = false ;
991+ if ( currentItem && currentItem . type === `procedure` ) {
992+ currentItem . readParms = false ;
993+ resetDefinition = true ;
994+ }
995+ } else if ( currentItem && currentItem . name === PROGRAMPARMS_NAME ) {
996+ // Assign this scopes parameters to the subitems of the program parameters struct
997+ scopes [ 0 ] . parameters = currentItem . subItems ;
988998 resetDefinition = true ;
989999 }
9901000 break ;
@@ -1202,7 +1212,7 @@ export default class Parser {
12021212 currentItem . subItems . push ( currentSub ) ;
12031213 currentSub = undefined ;
12041214
1205- if ( currentItem . type === `struct` ) {
1215+ if ( currentItem . type === `struct` && currentItem . name !== PROGRAMPARMS_NAME ) {
12061216 resetDefinition = true ;
12071217 }
12081218 }
0 commit comments