Fix comment parsing to handle end of line inline comments
This commit is contained in:
parent
4c8f2cd228
commit
97cfc8ea9b
1 changed files with 27 additions and 0 deletions
|
|
@ -11,12 +11,39 @@ import * as vscode from "vscode";
|
|||
/**
|
||||
* Strip comments from theme
|
||||
*/
|
||||
|
||||
function stripInLineComment(line: string): string {
|
||||
let inString = false;
|
||||
let pCh = '';
|
||||
|
||||
for (let i = 0; i < line.length-1; i++) {
|
||||
const ch = line[i];
|
||||
const nCh = line[i + 1];
|
||||
|
||||
// If we're not in a string and we see '//' this is a comment.
|
||||
if (!inString && ch === '/' && nCh === '/') {
|
||||
// Stop processing this line from here.
|
||||
return line.substring(0, i);
|
||||
}
|
||||
|
||||
// Toggle inString state if we see a double quote not escaped by a backslash.
|
||||
if (ch === '"' && pCh !== '\\') {
|
||||
inString = !inString;
|
||||
}
|
||||
|
||||
pCh = ch;
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
function parseThemeString(themeString: string | undefined): any {
|
||||
themeString = themeString
|
||||
?.split("\n")
|
||||
.filter((line) => {
|
||||
return !line.trim().startsWith("//");
|
||||
})
|
||||
.map(stripInLineComment)
|
||||
.join("\n");
|
||||
return JSON.parse(themeString ?? "{}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue