Skip to content

Commit

Permalink
Fix for strings with two slashes
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <mrliamallan@live.co.uk>
  • Loading branch information
worksofliam committed Dec 9, 2024
1 parent 57fc34e commit 2112ca8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions language/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ export default class Parser {

const stripComment = (inputLine: string) => {
const comment = inputLine.indexOf(`//`);
const quote = inputLine.lastIndexOf(`'`);
if (comment >= 0 && comment < quote) {
return inputLine;
}

return (comment >= 0 ? inputLine.substring(0, comment).trimEnd() : inputLine);
}

Expand Down Expand Up @@ -577,9 +582,6 @@ export default class Parser {
console.log(`Error parsing include: ${include.uri}`);
console.log(e);
}
} else {
console.log(`Include detected that has already been imported in this scope. Ignoring.`);
console.log({from: fileUri, to: include.uri, lineNumber});
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions tests/suite/references.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1568,4 +1568,26 @@ test('references_24_comment_in_statement', async () => {
const code = freeFormatEvaluationFound.scope.find(`code`);
expect(code.references.length).toBe(25);
expect(code.references.every(ref => lines.substring(ref.offset.position, ref.offset.end) === `code`)).toBe(true);
});

// Test case is from httpapi
test('references_25_fixed_string', async () => {
const lines = [
` D http s 5050a varying`,
` D rc s 10i 0`,
``,
` /free`,
` http_debug(*on: '/tmp/example9-debug.txt');`,
``,
` if %parms < 3;`,
` http_comp('To call, type: +`,
` EXAMPLE9 URL(''http://google.com'') STMF(''/tmp/google.pdf'')');`,
` return;`,
` endif;`,
].join(`\n`);

const cache = await parser.getDocs(uri, lines, { ignoreCache: true, withIncludes: true, collectReferences: true });
const http = cache.find(`http`);
expect(http.references.length).toBe(1);
expect(http.references.every(ref => lines.substring(ref.offset.position, ref.offset.end) === `http`)).toBe(true);
});

0 comments on commit 2112ca8

Please sign in to comment.