Skip to content

Commit 9fd20ff

Browse files
committed
Ability to have fixed-format procedure names spread over multiple lines
Signed-off-by: worksofliam <[email protected]>
1 parent cbe5c6c commit 9fd20ff

File tree

2 files changed

+63
-35
lines changed

2 files changed

+63
-35
lines changed

language/models/fixed.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ export function parseDLine(lineNumber, lineIndex, content) {
131131
*/
132132
export function parsePLine(content, lineNumber, lineIndex) {
133133
content = content.padEnd(80);
134-
const name = content.substr(6, 16)
134+
let name = content.substr(6, 16).trimEnd();
135+
if (name.endsWith(`...`)) {
136+
name = name.substring(0, name.length - 3);
137+
}
138+
135139
const longForm = content.substring(6).trimEnd();
136140
const potentialName = longForm.endsWith(`...`) ? calculateToken(lineNumber, lineIndex+6, longForm.substring(0, longForm.length - 3)) : undefined;
137141
const start = content[23].toUpperCase() === `B`;

language/parser.ts

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,29 @@ export default class Parser {
203203
return objectName;
204204
};
205205

206-
let potentialName: Token|undefined;
207-
let potentialNameUsed = false;
206+
let potentialName: Token[]|undefined;
207+
const getPotentialName = () => {
208+
if (potentialName && potentialName.length > 0) {
209+
return potentialName.map(p => p.value).join(``);
210+
} else {
211+
return undefined;
212+
}
213+
}
214+
const pushPotentialNameToken = (token?: Token) => {
215+
if (!potentialName) {
216+
potentialName = [];
217+
}
218+
if (token) {
219+
potentialName.push(token);
220+
}
221+
}
222+
const getPotentialNameToken = (): Token|undefined => {
223+
if (potentialName && potentialName.length > 0) {
224+
return potentialName[potentialName.length - 1];
225+
} else {
226+
return undefined;
227+
}
228+
}
208229

209230
let currentGroup: "structs"|"procedures"|"constants";
210231

@@ -1445,8 +1466,6 @@ export default class Parser {
14451466
}
14461467
}
14471468

1448-
potentialName = cSpec.factor1;
1449-
14501469
switch (cSpec.opcode && cSpec.opcode.value) {
14511470
case `BEGSR`:
14521471

@@ -1523,29 +1542,34 @@ export default class Parser {
15231542
const pSpec = parsePLine(line, lineNumber, lineIndex);
15241543

15251544
if (pSpec.potentialName) {
1526-
potentialName = pSpec.potentialName;
1527-
potentialNameUsed = true;
1545+
pushPotentialNameToken(pSpec.potentialName);
1546+
15281547
tokens = [pSpec.potentialName];
15291548
} else {
15301549
if (pSpec.start) {
1531-
tokens = [...pSpec.keywordsRaw, pSpec.name]
1532-
potentialName = pSpec.name && pSpec.name.value.length > 0 ? pSpec.name : potentialName;
1550+
tokens = [...pSpec.keywordsRaw, pSpec.name];
1551+
1552+
if (pSpec.name && pSpec.name.value.length > 0) {
1553+
pushPotentialNameToken(pSpec.name);
1554+
}
15331555

1534-
if (potentialName) {
1556+
const currentNameToken = getPotentialNameToken();
1557+
1558+
if (currentNameToken) {
15351559
currentItem = new Declaration(`procedure`);
15361560

1537-
currentProcName = potentialName.value;
1561+
currentProcName = getPotentialName();
15381562
currentItem.name = currentProcName;
15391563
currentItem.keyword = pSpec.keywords;
15401564

15411565
currentItem.position = {
15421566
path: fileUri,
1543-
range: potentialName.range
1567+
range: currentNameToken.range
15441568
};
15451569

15461570
currentItem.range = {
1547-
start: potentialName.range.line,
1548-
end: potentialName.range.line
1571+
start: currentNameToken.range.line,
1572+
end: currentNameToken.range.line
15491573
};
15501574

15511575
currentItem.scope = new Cache(undefined, true);
@@ -1573,35 +1597,36 @@ export default class Parser {
15731597
case `D`:
15741598
const dSpec = parseDLine(lineNumber, lineIndex, line);
15751599

1576-
if (dSpec.potentialName && dSpec.potentialName) {
1577-
potentialName = dSpec.potentialName;
1578-
potentialNameUsed = true;
1600+
if (dSpec.potentialName) {
1601+
pushPotentialNameToken(dSpec.potentialName);
15791602
tokens = [dSpec.potentialName];
15801603
continue;
15811604
} else {
1582-
potentialName = dSpec.name && dSpec.name.value.length > 0 ? dSpec.name : potentialName;
1583-
tokens = [dSpec.field, ...dSpec.keywordsRaw, dSpec.name];
15841605

1585-
const useNameToken = potentialName ? potentialName : dSpec.field;
1606+
if (dSpec.name && dSpec.name.value.length > 0) {
1607+
pushPotentialNameToken(dSpec.name);
1608+
}
1609+
1610+
tokens = [dSpec.field, ...dSpec.keywordsRaw, dSpec.name];
15861611

15871612
switch (dSpec.field && dSpec.field.value) {
15881613
case `C`:
15891614
currentItem = new Declaration(`constant`);
1590-
currentItem.name = potentialName ? potentialName.value : NO_NAME;
1615+
currentItem.name = getPotentialName() || NO_NAME;
15911616
currentItem.keyword = dSpec.keywords || {};
15921617

15931618
// TODO: line number might be different with ...?
15941619
currentItem.position = {
15951620
path: fileUri,
1596-
range: useNameToken.range
1621+
range: dSpec.field.range
15971622
};
15981623

15991624
scope.addSymbol(currentItem);
16001625
resetDefinition = true;
16011626
break;
16021627
case `S`:
16031628
currentItem = new Declaration(`variable`);
1604-
currentItem.name = potentialName ? potentialName.value : NO_NAME;
1629+
currentItem.name = getPotentialName() || NO_NAME;
16051630
currentItem.keyword = {
16061631
...dSpec.keywords,
16071632
...prettyTypeFromToken(dSpec),
@@ -1610,7 +1635,7 @@ export default class Parser {
16101635
// TODO: line number might be different with ...?
16111636
currentItem.position = {
16121637
path: fileUri,
1613-
range: useNameToken.range
1638+
range: getPotentialNameToken().range
16141639
};
16151640

16161641
scope.addSymbol(currentItem);
@@ -1619,20 +1644,20 @@ export default class Parser {
16191644

16201645
case `DS`:
16211646
currentItem = new Declaration(`struct`);
1622-
currentItem.name = potentialName ? potentialName.value : NO_NAME;
1647+
currentItem.name = getPotentialName() || NO_NAME;
16231648
currentItem.keyword = dSpec.keywords;
16241649

16251650
currentItem.position = {
16261651
path: fileUri,
1627-
range: useNameToken.range
1652+
range: getPotentialNameToken()?.range || dSpec.field.range
16281653
};
16291654

16301655
currentItem.range = {
16311656
start: currentItem.position.range.line,
16321657
end: currentItem.position.range.line
16331658
};
16341659

1635-
expandDs(fileUri, useNameToken, currentItem);
1660+
expandDs(fileUri, getPotentialNameToken(), currentItem);
16361661

16371662
currentGroup = `structs`;
16381663
scope.addSymbol(currentItem);
@@ -1641,15 +1666,15 @@ export default class Parser {
16411666

16421667
case `PR`:
16431668
currentItem = new Declaration(`procedure`);
1644-
currentItem.name = potentialName ? potentialName.value : NO_NAME;
1669+
currentItem.name = getPotentialName() || NO_NAME;
16451670
currentItem.keyword = {
16461671
...prettyTypeFromToken(dSpec),
16471672
...dSpec.keywords
16481673
}
16491674

16501675
currentItem.position = {
16511676
path: fileUri,
1652-
range: useNameToken.range
1677+
range: getPotentialNameToken().range
16531678
};
16541679

16551680
currentItem.range = {
@@ -1704,27 +1729,27 @@ export default class Parser {
17041729
// This happens when it's a blank parm.
17051730
const baseToken = dSpec.type || dSpec.len;
17061731
if (!potentialName && baseToken) {
1707-
potentialName = {
1732+
pushPotentialNameToken({
17081733
...baseToken,
17091734
value: NO_NAME
1710-
}
1735+
});
17111736
}
17121737

17131738
if (potentialName) {
17141739
currentSub = new Declaration(`subitem`);
1715-
currentSub.name = potentialName.value;
1740+
currentSub.name = getPotentialName();
17161741
currentSub.keyword = {
17171742
...prettyTypeFromToken(dSpec),
17181743
...dSpec.keywords
17191744
}
17201745

17211746
currentSub.position = {
17221747
path: fileUri,
1723-
range: potentialName.range
1748+
range: getPotentialNameToken().range
17241749
};
17251750

17261751
// If the parameter has likeds, add the subitems to make it a struct.
1727-
await expandDs(fileUri, potentialName, currentSub);
1752+
await expandDs(fileUri, getPotentialNameToken(), currentSub);
17281753

17291754
currentItem.subItems.push(currentSub);
17301755
currentSub = undefined;
@@ -1766,7 +1791,6 @@ export default class Parser {
17661791

17671792
if (resetDefinition) {
17681793
potentialName = undefined;
1769-
potentialNameUsed = false;
17701794

17711795
currentItem = undefined;
17721796
currentTitle = undefined;

0 commit comments

Comments
 (0)