Skip to content

Commit

Permalink
Fix to parser circular include
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Dec 9, 2024
1 parent df3ecb3 commit 9f25251
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
26 changes: 15 additions & 11 deletions language/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,21 @@ export default class Parser {

if (includePath) {
const include = await this.includeFileFetch(workingUri, includePath);
if (include.found) {
scopes[0].includes.push({
toPath: include.uri,
line: lineNumber
});

try {
await parseContent(include.uri, include.content);
} catch (e) {
console.log(`Error parsing include: ${include.uri}`);
console.log(e);
if (include.found && include.uri) {
if (!scopes[0].includes.some(inc => inc.toPath === include.uri)) {
scopes[0].includes.push({
toPath: include.uri,
line: lineNumber
});

try {
await parseContent(include.uri, include.content);
} catch (e) {
console.log(`Error parsing include: ${include.uri}`);
console.log(e);
}
} else {
console.log(`Circular include detected: ${includePath}`);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/parserSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export default function setupParser(projectRoot = TEST_INCLUDE_DIR): Parser {
}

const globPath = path.join(`**`, includeFile);
const files = glob.sync(globPath, {
const files: string[] = glob.sync(globPath, {
cwd: projectRoot,
absolute: true,
nocase: true,
});

if (files.length >= 1) {
const file = files[0];
const file = files.find(f => f.toLowerCase().endsWith(`rpgleinc`)) || files[0];

const content = await readFile(file, { encoding: `utf-8` });

Expand Down
1 change: 1 addition & 0 deletions tests/sources/rpgle-repl
Submodule rpgle-repl added at b4240b

0 comments on commit 9f25251

Please sign in to comment.