-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathExternalLanguage.cs
More file actions
54 lines (46 loc) · 1.56 KB
/
ExternalLanguage.cs
File metadata and controls
54 lines (46 loc) · 1.56 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
namespace ColorCode.Compilation.Languages
{
public class ExternalLanguage : ILanguage
{
public ExternalLanguage(FileInfo file)
{
string contents = "";
using (var reader = new StreamReader(file.OpenRead()))
{
contents = reader.ReadToEnd();
}
Parse(contents);
}
public ExternalLanguage(string filecontents)
{
Parse(filecontents);
}
private void Parse(string contents)
{
var data = JObject.Parse(contents);
Id = (string)data["id"];
Name = (string)data["Name"];
CssClassName = (string)data["CssClassName"];
FirstLinePattern = (string)data["FirstLinePattern"];
var rules = new List<LanguageRule>();
foreach (var r in data["Rules"])
{
var captures = new Dictionary<int, string>();
foreach (var c in r["Captures"])
{
captures.Add((int)c["index"], (string)c["name"]);
}
rules.Add(new LanguageRule((string)r["Regex"], captures));
}
Rules = rules;
}
public string Id { get; private set; }
public string FirstLinePattern { get; private set; }
public string Name { get; private set; }
public IList<LanguageRule> Rules { get; private set; }
public string CssClassName { get; private set; }
}
}