Skip to content

Commit c6ee556

Browse files
authored
Merge pull request #434 from codefori/fix/symbol_definition_correction
Allow symbols to be defined in free-format
2 parents 1de807d + 8e259ec commit c6ee556

File tree

2 files changed

+84
-51
lines changed

2 files changed

+84
-51
lines changed

language/parser.ts

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -891,51 +891,47 @@ export default class Parser {
891891

892892
case `DCL-S`:
893893
if (parts.length > 1) {
894-
if (currentItem === undefined) {
895-
currentItem = new Declaration(`variable`);
896-
currentItem.name = partsLower[1];
897-
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
898-
currentItem.tags = currentTags;
894+
currentItem = new Declaration(`variable`);
895+
currentItem.name = partsLower[1];
896+
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
897+
currentItem.tags = currentTags;
899898

900-
currentItem.position = {
901-
path: fileUri,
902-
range: tokens[1].range
903-
};
899+
currentItem.position = {
900+
path: fileUri,
901+
range: tokens[1].range
902+
};
904903

905-
currentItem.range = {
906-
start: currentStmtStart.line,
907-
end: lineNumber
908-
};
904+
currentItem.range = {
905+
start: currentStmtStart.line,
906+
end: lineNumber
907+
};
909908

910-
scope.addSymbol(currentItem);
911-
resetDefinition = true;
912-
}
909+
scope.addSymbol(currentItem);
910+
resetDefinition = true;
913911
}
914912
break;
915913

916914
case `DCL-ENUM`:
917-
if (currentItem === undefined) {
918-
if (parts.length > 1) {
919-
currentItem = new Declaration(`constant`);
920-
currentItem.name = partsLower[1];
921-
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
915+
if (parts.length > 1) {
916+
currentItem = new Declaration(`constant`);
917+
currentItem.name = partsLower[1];
918+
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
922919

923-
currentItem.position = {
924-
path: fileUri,
925-
range: tokens[1].range
926-
};
920+
currentItem.position = {
921+
path: fileUri,
922+
range: tokens[1].range
923+
};
927924

928-
currentItem.range = {
929-
start: currentStmtStart.line,
930-
end: currentStmtStart.line
931-
};
925+
currentItem.range = {
926+
start: currentStmtStart.line,
927+
end: currentStmtStart.line
928+
};
932929

933-
currentItem.readParms = true;
930+
currentItem.readParms = true;
934931

935-
currentGroup = `constants`;
932+
currentGroup = `constants`;
936933

937-
currentDescription = [];
938-
}
934+
currentDescription = [];
939935
}
940936
break;
941937

tests/suite/basics.test.ts

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,22 +1877,59 @@ test('correct ranges (#427)', async () => {
18771877
expect(constants[3].keyword[`CONST`]).toBe(`9`);
18781878
});
18791879

1880-
// test('scoobydo', async () => {
1881-
// const content = await getFileContent(path.join(__dirname, `..`, `rpgle`, `testing.rpgle`));
1882-
// const lines = content.split(/\r?\n/);
1883-
// const cache = await parser.getDocs(uri, content, { ignoreCache: true, withIncludes: false });
1880+
test('that symbols can be defined correctly', async () => {
1881+
const lines = [
1882+
``,
1883+
` D SAMPLEPG Ds Qualified `,
1884+
` dcl-s myprogramText char(20);`,
1885+
` dcl-s sampleDcl char(2);`,
1886+
` dcl-enum ENUMTEST qualified;`,
1887+
` CONSTANT1 value1;`,
1888+
` CONSTANT2 value2;`,
1889+
` end-enum;`,
1890+
` `,
1891+
` dcl-proc testing123 ;`,
1892+
` dcl-pi *n ;`,
1893+
` end-pi;`,
1894+
` `,
1895+
` end-proc;`,
1896+
` `,
1897+
].join(`\n`);
18841898

1885-
// const kill = cache.findAll(`kill`);
1886-
1887-
// const killPrototype = kill[0];
1888-
// expect(killPrototype.name).toBe(`kill`);
1889-
// expect(killPrototype.prototype).toBeTruthy();
1890-
// expect(killPrototype.range.start).toBe(71);
1891-
// expect(killPrototype.range.end).toBe(74);
1892-
1893-
// const killProc = kill[1];
1894-
// expect(killProc.name).toBe(`kill`);
1895-
// expect(killProc.prototype).toBeFalsy();
1896-
// expect(killProc.range.start).toBe(741);
1897-
// expect(killProc.range.end).toBe(761);
1898-
// });
1899+
const cache = await parser.getDocs(uri, lines, { ignoreCache: true, withIncludes: false, collectReferences: true });
1900+
1901+
expect(cache.structs.length).toBe(1);
1902+
expect(cache.constants.length).toBe(1);
1903+
expect(cache.variables.length).toBe(2);
1904+
expect(cache.procedures.length).toBe(1);
1905+
});
1906+
1907+
test('that mixed symbols can be defined correctly', async () => {
1908+
const lines = [
1909+
``,
1910+
``,
1911+
` D SAMPLEPG Ds Qualified`,
1912+
` F TEST `,
1913+
` dcl-s myprogramText char(20);`,
1914+
` dcl-s sampleDcl char(2);`,
1915+
` dcl-enum ENUMTEST qualified;`,
1916+
` CONSTANT1 value1;`,
1917+
` CONSTANT2 value2;`,
1918+
` end-enum;`,
1919+
` `,
1920+
` dcl-proc testing123 ;`,
1921+
` dcl-pi *n ;`,
1922+
` end-pi;`,
1923+
` `,
1924+
` end-proc;`,
1925+
` `,
1926+
].join(`\n`);
1927+
1928+
const cache = await parser.getDocs(uri, lines, { ignoreCache: true, withIncludes: false, collectReferences: true });
1929+
1930+
expect(cache.structs.length).toBe(1);
1931+
expect(cache.files.length).toBe(1);
1932+
expect(cache.constants.length).toBe(1);
1933+
expect(cache.variables.length).toBe(2);
1934+
expect(cache.procedures.length).toBe(1);
1935+
});

0 commit comments

Comments
 (0)