-
Notifications
You must be signed in to change notification settings - Fork 116
/
parseRawGrammar.ts
29 lines (25 loc) · 1.05 KB
/
parseRawGrammar.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import { IRawGrammar } from './rawGrammar';
import * as plist from './plist';
import { DebugFlags } from './debug';
import { parseJSON } from './json';
export function parseRawGrammar(content: string, filePath: string | null = null): IRawGrammar {
if (filePath !== null && /\.json$/.test(filePath)) {
return parseJSONGrammar(content, filePath);
}
return parsePLISTGrammar(content, filePath);
}
function parseJSONGrammar(contents: string, filename: string | null): IRawGrammar {
if (DebugFlags.InDebugMode) {
return <IRawGrammar>parseJSON(contents, filename, true);
}
return <IRawGrammar>JSON.parse(contents);
}
function parsePLISTGrammar(contents: string, filename: string | null): IRawGrammar {
if (DebugFlags.InDebugMode) {
return <IRawGrammar>plist.parseWithLocation(contents, filename, '$vscodeTextmateLocation');
}
return <IRawGrammar>plist.parsePLIST(contents);
}