Skip to content

Commit

Permalink
Fix to parser with mixed fixed and free structs
Browse files Browse the repository at this point in the history
  • Loading branch information
worksofliam committed Feb 9, 2022
1 parent 1953c03 commit a8903e7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ module.exports = class Parser {
line: lineNumber
}

currentGroup = `structs`;
// Does the keywords include a keyword that makes end-ds useless?
if (currentItem.keywords.some(keyword => oneLineTriggers[`DCL-DS`].some(trigger => keyword.startsWith(trigger)))) {
scope.structs.push(currentItem);
Expand All @@ -424,6 +425,7 @@ module.exports = class Parser {
case `DCL-PR`:
if (currentItem === undefined) {
if (!scope.procedures.find(proc => proc.name.toUpperCase() === parts[1])) {
currentGroup = `procedures`;
currentItem = new Declaration(`procedure`);
currentItem.name = partsLower[1];
currentItem.keywords = parts.slice(2);
Expand Down Expand Up @@ -485,6 +487,7 @@ module.exports = class Parser {
case `DCL-PI`:
//Procedures can only exist in the global scope.
if (currentProcName) {
currentGroup = `procedures`;
currentItem = scopes[0].procedures.find(proc => proc.name === currentProcName);

if (currentItem) {
Expand Down Expand Up @@ -647,6 +650,7 @@ module.exports = class Parser {
});
});

currentGroup = `structs`
scope.structs.push(...recordFormats);
}
break;
Expand Down Expand Up @@ -792,7 +796,9 @@ module.exports = class Parser {
line: lineNumber
}

currentGroup = `structs`;
scope.structs.push(currentItem);
resetDefinition = true;
}
break;

Expand All @@ -808,6 +814,7 @@ module.exports = class Parser {
line: lineNumber
}

currentGroup = `procedures`;
scope.procedures.push(currentItem);
currentDescription = [];
}
Expand All @@ -818,13 +825,25 @@ module.exports = class Parser {
if (currentProcName) {
currentItem = scopes[0].procedures.find(proc => proc.name === currentProcName);

currentGroup = `procedures`;
if (currentItem) {
currentItem.keywords.push(Fixed.getPrettyType(dSpec), ...dSpec.keywords);
}
}
break;

default:
switch (currentGroup) {
case `procedures`:
// Get from the parent
currentItem = scopes[scopes[0].procedures.length - 1].procedures[scopes[0].procedures.length - 1];
break;

case `structs`:
currentItem = scope[currentGroup][scope[currentGroup].length - 1];
break;
}

if (currentItem) {
currentSub = new Declaration(`subitem`);
currentSub.name = (potentialName === `*N` ? `parm${currentItem.subItems.length+1}` : potentialName) ;
Expand All @@ -837,6 +856,8 @@ module.exports = class Parser {

currentItem.subItems.push(currentSub);
currentSub = undefined;

resetDefinition = true;
}
break;
}
Expand Down

0 comments on commit a8903e7

Please sign in to comment.