forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammarReader.ts
More file actions
30 lines (26 loc) · 1.02 KB
/
grammarReader.ts
File metadata and controls
30 lines (26 loc) · 1.02 KB
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
30
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
'use strict';
import { IRawGrammar } from './types';
import * as plist from './plist';
import { CAPTURE_METADATA } from './debug';
import { parse as manualParseJSON } from './json';
export function parseRawGrammar(content: string, filePath: string): IRawGrammar {
if (/\.json$/.test(filePath)) {
return parseJSONGrammar(content, filePath);
}
return parsePLISTGrammar(content, filePath);
}
function parseJSONGrammar(contents: string, filename: string): IRawGrammar {
if (CAPTURE_METADATA) {
return <IRawGrammar>manualParseJSON(contents, filename, true);
}
return <IRawGrammar>JSON.parse(contents);
}
function parsePLISTGrammar(contents: string, filename: string): IRawGrammar {
if (CAPTURE_METADATA) {
return <IRawGrammar>plist.parseWithLocation(contents, filename, '$vscodeTextmateLocation');
}
return <IRawGrammar>plist.parse(contents);
}