forked from microsoft/vscode-arduino
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprogrammer.ts
67 lines (55 loc) · 1.94 KB
/
programmer.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { IPlatform, IProgrammer } from "./package";
export function parseProgrammerDescriptor(programmerDescriptor: string, plat: IPlatform): Map<string, IProgrammer> {
const progrmmerLineRegex = /([^\.]+)\.(\S+)=(.+)/;
const result = new Map<string, IProgrammer>();
const lines = programmerDescriptor.split(/[\r|\r\n|\n]/);
const menuMap = new Map<string, string>();
lines.forEach((line) => {
// Ignore comments.
if (line.startsWith("#")) {
return;
}
const match = progrmmerLineRegex.exec(line);
if (match && match.length > 3) {
let programmer = result.get(match[1]);
if (!programmer) {
programmer = new Programmer(match[1], plat);
result.set(programmer.name
, programmer);
}
if (match[2] === "name") {
programmer.displayName = match[3].trim();
}
}
});
return result;
}
export class Programmer implements IProgrammer {
constructor(private _name: string,
private _platform: IPlatform,
private _displayName: string = _name) {
}
public get name(): string {
return this._name;
}
public get platform(): IPlatform {
return this._platform;
}
public get displayName(): string {
return this._displayName;
}
public set displayName(value: string) {
this._displayName = value;
}
/**
* @returns {string} Return programmer key in format packageName:name
*/
public get key() {
return `${this.getPackageName}:${this.name}`;
}
private get getPackageName(): string {
return this.platform.packageName ? this.platform.packageName : this.platform.package.name;
}
}