-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c21251
commit 34878ac
Showing
8 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using ColorCode.Common; | ||
|
||
namespace ColorCode.Compilation.Languages | ||
{ | ||
/// <summary> | ||
/// Leverage the regex from https://gist.github.com/goodmami/02f344e8c9a22fc9ac879230a9b9e071#version-2 | ||
/// for parsing the key, string value, number, and constant for a JSON code block. | ||
/// </summary> | ||
public class Json : ILanguage | ||
{ | ||
private const string Regex_String = @"""[^""\\]*(?:\\[^\r\n]|[^""\\]*)*"""; | ||
private const string Regex_Number = @"-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?"; | ||
|
||
public string Id | ||
{ | ||
get { return LanguageId.Json; } | ||
} | ||
|
||
public string Name | ||
{ | ||
get { return "JSON"; } | ||
} | ||
|
||
public string CssClassName | ||
{ | ||
get { return "json"; } | ||
} | ||
|
||
public string FirstLinePattern | ||
{ | ||
get { return null; } | ||
} | ||
|
||
public IList<LanguageRule> Rules | ||
{ | ||
get | ||
{ | ||
return new List<LanguageRule> | ||
{ | ||
new LanguageRule( | ||
$@"[,\{{]\s*({Regex_String})\s*:", | ||
new Dictionary<int, string> | ||
{ | ||
{1, ScopeName.JsonKey} | ||
}), | ||
new LanguageRule( | ||
Regex_String, | ||
new Dictionary<int, string> | ||
{ | ||
{0, ScopeName.JsonString} | ||
}), | ||
new LanguageRule( | ||
Regex_Number, | ||
new Dictionary<int, string> | ||
{ | ||
{0, ScopeName.JsonNumber} | ||
}), | ||
new LanguageRule( | ||
@"\b(true|false|null)\b", | ||
new Dictionary<int, string> | ||
{ | ||
{1, ScopeName.JsonConst} | ||
}), | ||
}; | ||
} | ||
} | ||
|
||
public bool HasAlias(string lang) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters