diff --git a/src/parser.c.ts b/src/parser.c.ts index 52279aa..9954933 100644 --- a/src/parser.c.ts +++ b/src/parser.c.ts @@ -31,6 +31,7 @@ const versionRegex = /\/\*\sGenerated by\s+cobc\s([0-9a-z\-\.]+)\s+\*\//i; const subroutineRegex = /\sPerform\s/i; const frame_ptrFindRegex = /frame\_ptr\-\-\;/; const fixOlderFormat = /cob\_trace\_stmt/; +const programExit = /\/\*\sProgram\s\exit\s+\*\//i; globalThis.varOccurs = []; @@ -75,6 +76,8 @@ export class SourceMap { private parse(fileC: string): void { let nat = fileC; + let hasProgramExit = false; + if (!nativePath.isAbsolute(fileC)) { nat = nativePathFromPath.resolve(this.cwd, fileC); fileC = nativePath.resolve(this.cwd, fileC); @@ -116,9 +119,9 @@ export class SourceMap { } // fix new codegen match = procedureFixRegex.exec(line); - if (match && this.lines.length > 0) { + if (match && this.lines.length > 0 && !hasProgramExit) { let isOldFormat = fixOlderFormat.exec(this.lineBefore); - if(this.isVersion2_2_or_3_1_1 || !isOldFormat){ // Is it in the old format? + if(fileNameCompare(this.lines[this.lines.length - 1].fileCobol, fileCobol) && (this.isVersion2_2_or_3_1_1 || !isOldFormat)){ // Is it in the old format? let line = this.lines.pop(); line.lineC = parseInt(match[1]); this.lines.push(line); @@ -173,6 +176,10 @@ export class SourceMap { } } this.lineBefore = line; + match = programExit.exec(line); + if (match) { + hasProgramExit=true;; + } lineNumber++; } }