■ 소스 코드를 HTML 문자열로 만드는 방법을 보여준다.
※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다.
※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를 None으로 추가했다.
[TestLibrary 프로젝트]
▶ ArgumentHelper.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
namespace TestLibrary; /// <summary> /// 인자 헬퍼 /// </summary> public static class ArgumentHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region NOT NULL 여부 확인하기 - EnsureIsNotNull(argument, title) /// <summary> /// NOT NULL 여부 확인하기 /// </summary> /// <param name="argument">인자</param> /// <param name="title">제목</param> public static void EnsureIsNotNull(object argument, string title) { if(argument == null) { throw new ArgumentNullException(title); } } #endregion #region NOT NULL이고 값을 가진 문자열 여부 확인하기 - EnsureIsNotNullAndNotEmpty(argument, title) /// <summary> /// NOT NULL이고 값을 가진 문자열 여부 확인하기 /// </summary> /// <param name="argument">인자</param> /// <param name="title">제목</param> public static void EnsureIsNotNullAndNotEmpty(string argument, string title) { if(argument == null) { throw new ArgumentNullException(title); } if(string.IsNullOrEmpty(argument)) { throw new ArgumentException($"The {title} argument value must not be empty."); } } #endregion #region NOT NULL이고 값을 가진 딕셔너리 여부 확인하기 - EnsureIsNotNullAndNotEmpty<TKey, TValue>(argumentDictionary, title) /// <summary> /// NOT NULL이고 값을 가진 딕셔너리 여부 확인하기 /// </summary> /// <typeparam name="TKey">키 타입</typeparam> /// <typeparam name="TValue">값 타입</typeparam> /// <param name="argumentDictionary">인자 딕셔너리</param> /// <param name="title">제목</param> public static void EnsureIsNotNullAndNotEmpty<TKey, TValue>(IDictionary<TKey, TValue> argumentDictionary, string title) { if(argumentDictionary == null || argumentDictionary.Count == 0) { throw new ArgumentNullException(title); } } #endregion #region NOT NULL이 값을 가진 리스트 여부 확인하기 - EnsureIsNotNullAndNotEmpty<T>(argumentList, title) /// <summary> /// NOT NULL이 값을 가진 리스트 여부 확인하기 /// </summary> /// <typeparam name="TItem">항목 타입</typeparam> /// <param name="argumentList">인자 리스트</param> /// <param name="title">제목</param> public static void EnsureIsNotNullAndNotEmpty<TItem>(IList<TItem> argumentList, string title) { if(argumentList == null) { throw new ArgumentNullException(title); } if(argumentList.Count == 0) { throw new ArgumentException($"The {title} argument value must not be empty."); } } #endregion } |
▶ HTMLExtension.cs
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 |
namespace TestLibrary; /// <summary> /// HTML 확장 /// </summary> public static class HTMLExtension { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region HTML 색상 문자열 구하기 - ToHTMLColorString(color) /// <summary> /// HTML 색상 문자열 구하기 /// </summary> /// <param name="color">색상 문자열</param> /// <returns>HTML 색상 문자열</returns> public static string ToHTMLColorString(this string color) { if(color == null) { return null; } int length = 6; int start = color.Length - length; return "#" + color.Substring(start, length); } #endregion } |
▶ ILanguageRepository.cs
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 |
namespace TestLibrary; /// <summary> /// 언어 저장소 인터페이스 /// </summary> public interface ILanguageRepository { //////////////////////////////////////////////////////////////////////////////////////////////////// Property #region 언어 인터페이스 열거 가능형 - LanguageEnumerable /// <summary> /// 언어 인터페이스 열거 가능형 /// </summary> IEnumerable<ILanguage> LanguageEnumerable { get; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method #region ID로 언어 인터페이스 찾기 - FindByID(languageID) /// <summary> /// ID로 언어 인터페이스 찾기 /// </summary> /// <param name="languageID"></param> /// <returns>언어 인터페이스</returns> ILanguage FindByID(string languageID); #endregion #region 로드하기 - Load(language) /// <summary> /// 로드하기 /// </summary> /// <param name="language">언어 인터페이스</param> void Load(ILanguage language); #endregion } |
▶ LanguageID.cs
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 |
namespace TestLibrary; /// <summary> /// 언어 ID /// </summary> public static class LanguageID { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field public const string ASAX = "asax"; public const string ASHX = "ashx"; public const string ASPX = "aspx"; public const string ASPXCS = "aspx(c#)"; public const string ASPXVB = "aspx(vb.net)"; public const string CSHARP = "c#"; public const string CPP = "cpp"; public const string CSS = "css"; public const string FSHARP = "f#"; public const string HTML = "html"; public const string JAVA = "java"; public const string JAVASCRIPT = "javascript"; public const string JSON = "json"; public const string TYPESCRIPT = "typescript"; public const string PHP = "php"; public const string POWERSHELL = "powershell"; public const string SQL = "sql"; public const string VBDOTNET = "vb.net"; public const string XML = "xml"; public const string KOKA = "koka"; public const string HASKELL = "haskell"; public const string MARKDOWN = "markdown"; public const string FORTRAN = "fortran"; public const string PYTHON = "python"; public const string MATLAB = "matlab"; #endregion } |
▶ LanguageRepository.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
namespace TestLibrary; /// <summary> /// 언어 저장소 /// </summary> public class LanguageRepository : ILanguageRepository { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 언어 딕셔너리 /// </summary> private readonly Dictionary<string, ILanguage> languageDictionary; /// <summary> /// 읽기/쓰기 잠금 슬림 /// </summary> private readonly ReaderWriterLockSlim readerWriterLockSlim; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region 언어 인터페이스 열거 가능형 - LanguageEnumerable /// <summary> /// 언어 인터페이스 열거 가능형 /// </summary> public IEnumerable<ILanguage> LanguageEnumerable { get { return this.languageDictionary.Values; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructir ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - LanguageRepository(languageDictionary) /// <summary> /// 생성자 /// </summary> /// <param name="languageDictionary">언어 딕셔너리</param> public LanguageRepository(Dictionary<string, ILanguage> languageDictionary) { this.languageDictionary = languageDictionary; this.readerWriterLockSlim = new ReaderWriterLockSlim(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID로 찾기 - FindByID(languageID) /// <summary> /// ID로 찾기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>언어 인터페이스</returns> public ILanguage FindByID(string languageID) { ArgumentHelper.EnsureIsNotNullAndNotEmpty(languageID, "languageID"); ILanguage language = null; this.readerWriterLockSlim.EnterReadLock(); try { language = this.languageDictionary.FirstOrDefault(x => (x.Key.ToLower() == languageID.ToLower()) || (x.Value.HasAlias(languageID))).Value; } finally { this.readerWriterLockSlim.ExitReadLock(); } return language; } #endregion #region 로드하기 - Load(language) /// <summary> /// 로드하기 /// </summary> /// <param name="language">언어 인터페이스</param> public void Load(ILanguage language) { ArgumentHelper.EnsureIsNotNull(language, "language"); if(string.IsNullOrEmpty(language.ID)) { throw new ArgumentException("The language identifier must not be null or empty.", "language"); } this.readerWriterLockSlim.EnterWriteLock(); try { this.languageDictionary[language.ID] = language; } finally { this.readerWriterLockSlim.ExitWriteLock(); } } #endregion } |
▶ ScopeName.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 |
namespace TestLibrary; /// <summary> /// 범위명 /// </summary> public class ScopeName { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field public const string ClassName = "Class Name"; public const string Comment = "Comment"; public const string CssPropertyName = "CSS Property Name"; public const string CssPropertyValue = "CSS Property Value"; public const string CssSelector = "CSS Selector"; public const string HtmlAttributeName = "HTML Attribute ScopeName"; public const string HtmlAttributeValue = "HTML Attribute Value"; public const string HtmlComment = "HTML Comment"; public const string HtmlElementName = "HTML Element ScopeName"; public const string HtmlEntity = "HTML Entity"; public const string HtmlOperator = "HTML Operator"; public const string HtmlServerSideScript = "HTML Server-Side Script"; public const string HtmlTagDelimiter = "Html Tag Delimiter"; public const string JsonKey = "Json Key"; public const string JsonString = "Json String"; public const string JsonNumber = "Json Number"; public const string JsonConst = "Json Const"; public const string Keyword = "Keyword"; public const string LanguagePrefix = "&"; public const string PlainText = "Plain Text"; public const string PowerShellAttribute = "PowerShell Attribute"; public const string PowerShellOperator = "PowerShell Operator"; public const string PowerShellType = "PowerShell Type"; public const string PowerShellVariable = "PowerShell Variable"; public const string PowerShellCommand = "PowerShell Command"; public const string PowerShellParameter = "PowerShell Parameter"; public const string PreprocessorKeyword = "Preprocessor Keyword"; public const string SqlSystemFunction = "SQL System Function"; public const string String = "String"; public const string StringCSharpVerbatim = "String (C# @ Verbatim)"; public const string XmlAttribute = "XML Attribute"; public const string XmlAttributeQuotes = "XML Attribute Quotes"; public const string XmlAttributeValue = "XML Attribute Value"; public const string XmlCDataSection = "XML CData Section"; public const string XmlComment = "XML Comment"; public const string XmlDelimiter = "XML Delimiter"; public const string XmlDocComment = "XML Doc Comment"; public const string XmlDocTag = "XML Doc Tag"; public const string XmlName = "XML Name"; public const string Type = "Type"; public const string TypeVariable = "Type Variable"; public const string NameSpace = "Name Space"; public const string Constructor = "Constructor"; public const string Predefined = "Predefined"; public const string PseudoKeyword = "Pseudo Keyword"; public const string StringEscape = "String Escape"; public const string ControlKeyword = "Control Keyword"; public const string Number = "Number"; public const string Operator = "Operator"; public const string Delimiter = "Delimiter"; public const string MarkdownHeader = "Markdown Header"; public const string MarkdownCode = "Markdown Code"; public const string MarkdownListItem = "Markdown List Item"; public const string MarkdownEmph = "Markdown Emphasized"; public const string MarkdownBold = "Markdown Bold"; public const string BuiltinFunction = "Built In Function"; public const string BuiltinValue = "Built In Value"; public const string Attribute = "Attribute"; public const string SpecialCharacter = "Special Character"; public const string Intrinsic = "Intrinsic"; public const string Brackets = "Brackets"; public const string Continuation = "Continuation"; #endregion } |
▶ SortExtension.cs
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 |
namespace TestLibrary; /// <summary> /// 정렬 확장 /// </summary> public static class SortExtension { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 안정적으로 정렬하기 - SortStable<T>(list, comparison) /// <summary> /// 안정적으로 정렬하기 /// </summary> /// <typeparam name="T">요소 타입</typeparam> /// <param name="list">리스트 인터페이스</param> /// <param name="comparison">비교 델리게이트</param> public static void SortStable<T>(this IList<T> list, Comparison<T> comparison) { ArgumentHelper.EnsureIsNotNull(list, "list"); int count = list.Count; for(int j = 1; j < count; j++) { T key = list[j]; int i = j - 1; for(; i >= 0 && comparison(list[i], key) > 0; i--) { list[i + 1] = list[i]; } list[i + 1] = key; } } #endregion } |
▶ TextInsertion.cs
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 |
namespace TestLibrary; /// <summary> /// 텍스트 삽입 /// </summary> public class TextInsertion { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 인덱스 - Index /// <summary> /// 인덱스 /// </summary> public virtual int Index { get; set; } #endregion #region 텍스트 - Text /// <summary> /// 텍스트 /// </summary> public virtual string Text { get; set; } #endregion #region 범위 - Scope /// <summary> /// 범위 /// </summary> public virtual Scope Scope { get; set; } #endregion } |
▶ CompiledLanguage.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
using System.Text.RegularExpressions; namespace TestLibrary; /// <summary> /// 컴파일된 언어 /// </summary> public class CompiledLanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get; set; } #endregion #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 정규식 - Regex /// <summary> /// 정규식 /// </summary> public Regex Regex { get; set; } #endregion #region 캡처 리스트 - CaptureList /// <summary> /// 캡처 리스트 /// </summary> public IList<string> CaptureList { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CompiledLanguage(id, name, regex, captureList) /// <summary> /// 생성자 /// </summary> /// <param name="id">ID</param> /// <param name="name">명칭</param> /// <param name="regex">정규식</param> /// <param name="captureList">캡처 리스트</param> public CompiledLanguage(string id, string name, Regex regex, IList<string> captureList) { ArgumentHelper.EnsureIsNotNullAndNotEmpty(id, "id"); ArgumentHelper.EnsureIsNotNullAndNotEmpty(name, "name"); ArgumentHelper.EnsureIsNotNull(regex, "regex"); ArgumentHelper.EnsureIsNotNullAndNotEmpty(captureList, "captures"); ID = id; Name = name; Regex = regex; CaptureList = captureList; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { return Name; } #endregion } |
▶ ILanguageCompiler.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
namespace TestLibrary; /// <summary> /// 언어 컴파일러 인터페이스 /// </summary> public interface ILanguageCompiler { //////////////////////////////////////////////////////////////////////////////////////////////////// Method #region 컴파일하기 - Compile(language) /// <summary> /// 컴파일하기 /// </summary> /// <param name="language">언어 인터페이스</param> /// <returns>컴파일된 언어</returns> CompiledLanguage Compile(ILanguage language); #endregion } |
▶ LanguageCompiler.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
using System.Text; using System.Text.RegularExpressions; namespace TestLibrary; /// <summary> /// 언어 컴파일러 /// </summary> public class LanguageCompiler : ILanguageCompiler { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 정규식 /// </summary> private static readonly Regex _regex = new Regex(@"(?x)(?<!(\\|(?!\\)\(\?))\((?!\?)", RegexOptions.Compiled); #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 컴파일된 언어 딕셔너리 /// </summary> private readonly Dictionary<string, CompiledLanguage> compiledLanguageDictionary; /// <summary> /// 읽기/쓰기 잠금 슬림 /// </summary> private readonly ReaderWriterLockSlim readerWriterLockSlim; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - LanguageCompiler(compiledLanguageDictionary, readerWriterLockSlim) /// <summary> /// 생성자 /// </summary> /// <param name="compiledLanguageDictionary">컴파일된 언어 딕셔너리</param> /// <param name="readerWriterLockSlim">읽기/쓰기 잠금 슬림</param> public LanguageCompiler(Dictionary<string, CompiledLanguage> compiledLanguageDictionary, ReaderWriterLockSlim readerWriterLockSlim) { this.compiledLanguageDictionary = compiledLanguageDictionary; this.readerWriterLockSlim = readerWriterLockSlim; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 캡처 카운트 구하기 - GetCaptureCount(regularExpressionString) /// <summary> /// 캡처 카운트 구하기 /// </summary> /// <param name="regularExpressionString">정규 표현식 문자열</param> /// <returns>캡처 카운트</returns> private static int GetCaptureCount(string regularExpressionString) { return _regex.Matches(regularExpressionString).Count; } #endregion #region 규칙 컴파일하기 - CompileRule(languageRule, regex, captureCollection, isFirstRule) /// <summary> /// 규칙 컴파일하기 /// </summary> /// <param name="languageRule">언어 규칙</param> /// <param name="regex">정규식</param> /// <param name="captureCollection">캡처 컬렉션</param> /// <param name="isFirstRule">첫번째 규칙 여부</param> private static void CompileRule(LanguageRule languageRule, StringBuilder regex, ICollection<string> captureCollection, bool isFirstRule) { if(!isFirstRule) { regex.AppendLine(); regex.AppendLine(); regex.AppendLine("|"); regex.AppendLine(); } regex.AppendFormat("(?-xis)(?m)({0})(?x)", languageRule.RegularExpression); int captureCount = GetCaptureCount(languageRule.RegularExpression); for(int i = 0; i <= captureCount; i++) { string scope = null; foreach(int captureIndex in languageRule.CaptureDictionary.Keys) { if(i == captureIndex) { scope = languageRule.CaptureDictionary[captureIndex]; break; } } captureCollection.Add(scope); } } #endregion #region 규칙들 컴파일하기 - CompileRules(languageRuleList, regex, captureList) /// <summary> /// 규칙들 컴파일하기 /// </summary> /// <param name="languageRuleList">언어 규칙 리스트</param> /// <param name="regex">정규식</param> /// <param name="captureList">캡처 리스트</param> private static void CompileRules(IList<LanguageRule> languageRuleList, out Regex regex, out IList<string> captureList) { StringBuilder stringBuilder = new StringBuilder(); captureList = new List<string>(); stringBuilder.AppendLine("(?x)"); captureList.Add(null); CompileRule(languageRuleList[0], stringBuilder, captureList, true); for(int i = 1; i < languageRuleList.Count; i++) { CompileRule(languageRuleList[i], stringBuilder, captureList, false); } regex = new Regex(stringBuilder.ToString()); } #endregion #region 언어 컴파일하기 - CompileLanguage(language) /// <summary> /// 언어 컴파일하기 /// </summary> /// <param name="language">언어</param> /// <returns>컴파일된 언어</returns> private static CompiledLanguage CompileLanguage(ILanguage language) { string id = language.ID; string name = language.Name; CompileRules(language.LanguageRuleList, out Regex regex, out IList<string> captureList); return new CompiledLanguage(id, name, regex, captureList); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Public #region 컴파일하기 - Compile(language) /// <summary> /// 컴파일하기 /// </summary> /// <param name="language">언어 인터페이스</param> /// <returns>컴파일된 언어</returns> public CompiledLanguage Compile(ILanguage language) { ArgumentHelper.EnsureIsNotNull(language, "language"); if(string.IsNullOrEmpty(language.ID)) { throw new ArgumentException("The language identifier must not be null.", "language"); } CompiledLanguage compiledLanguage; this.readerWriterLockSlim.EnterReadLock(); try { if(this.compiledLanguageDictionary.ContainsKey(language.ID)) { return this.compiledLanguageDictionary[language.ID]; } } finally { this.readerWriterLockSlim.ExitReadLock(); } this.readerWriterLockSlim.EnterUpgradeableReadLock(); try { if(this.compiledLanguageDictionary.ContainsKey(language.ID)) { compiledLanguage = this.compiledLanguageDictionary[language.ID]; } else { this.readerWriterLockSlim.EnterWriteLock(); try { if(string.IsNullOrEmpty(language.Name)) { throw new ArgumentException("The language name must not be null or empty.", "language"); } if(language.LanguageRuleList == null || language.LanguageRuleList.Count == 0) { throw new ArgumentException("The language rules collection must not be empty.", "language"); } compiledLanguage = CompileLanguage(language); this.compiledLanguageDictionary.Add(compiledLanguage.ID, compiledLanguage); } finally { this.readerWriterLockSlim.ExitWriteLock(); } } } finally { this.readerWriterLockSlim.ExitUpgradeableReadLock(); } return compiledLanguage; } #endregion } |
▶ RuleCapture.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
namespace TestLibrary; /// <summary> /// 규칙 캡처 /// </summary> public static class RuleCapture { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 자바 스크립트 딕셔너리 /// </summary> public static IDictionary<int, string> JavaScriptDictionary; /// <summary> /// C# 스크립트 딕셔너리 /// </summary> public static IDictionary<int, string> CSharpScriptDictionary; /// <summary> /// VB.NET 스크립트 딕셔너리 /// </summary> public static IDictionary<int, string> VbDotNetScriptDictionary; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Static #region 생성자 - RuleCapture() /// <summary> /// 생성자 /// </summary> static RuleCapture() { JavaScriptDictionary = BuildCaptureDictionary(LanguageID.JAVASCRIPT); CSharpScriptDictionary = BuildCaptureDictionary(LanguageID.CSHARP ); VbDotNetScriptDictionary = BuildCaptureDictionary(LanguageID.VBDOTNET ); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 캡처 딕셔너리 만들기 - BuildCaptureDictionary(languageID) /// <summary> /// 캡처 딕셔너리 만들기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>캡처 딕셔너리</returns> private static IDictionary<int, string> BuildCaptureDictionary(string languageID) { return new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlAttributeName }, { 4, ScopeName.HtmlOperator }, { 5, ScopeName.HtmlAttributeValue }, { 6, ScopeName.HtmlAttributeName }, { 7, ScopeName.HtmlOperator }, { 8, ScopeName.HtmlAttributeValue }, { 9, ScopeName.HtmlAttributeName }, { 10, ScopeName.HtmlOperator }, { 11, ScopeName.HtmlAttributeValue }, { 12, ScopeName.HtmlAttributeName }, { 13, ScopeName.HtmlAttributeName }, { 14, ScopeName.HtmlOperator }, { 15, ScopeName.HtmlAttributeValue }, { 16, ScopeName.HtmlAttributeName }, { 17, ScopeName.HtmlOperator }, { 18, ScopeName.HtmlAttributeValue }, { 19, ScopeName.HtmlAttributeName }, { 20, ScopeName.HtmlOperator }, { 21, ScopeName.HtmlAttributeValue }, { 22, ScopeName.HtmlAttributeName }, { 23, ScopeName.HtmlOperator }, { 24, ScopeName.HtmlAttributeValue }, { 25, ScopeName.HtmlAttributeName }, { 26, ScopeName.HtmlTagDelimiter }, { 27, $"{ScopeName.LanguagePrefix}{languageID}" }, { 28, ScopeName.HtmlTagDelimiter }, { 29, ScopeName.HtmlElementName }, { 30, ScopeName.HtmlTagDelimiter } }; } #endregion } |
▶ RuleFormat.cs
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 |
namespace TestLibrary; /// <summary> /// 규칙 포맷 /// </summary> public static class RuleFormat { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 자바 스크립트 /// </summary> public static string JavaScript; /// <summary> /// 서버 스크립트 /// </summary> public static string ServerScript; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Static #region 생성자 - RuleFormat() /// <summary> /// 생성자 /// </summary> static RuleFormat() { const string scriptRegularExpressionString = @"(?xs)(<)(script){0}[\s\n]+({1})[\s\n]*(=)[\s\n]*(""{2}""){0}[\s\n]*(>)(.*?)(</)(script)(>)"; const string attributeRegularExpressionString = @"(?:[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*([^\s\n""']+?)|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*(""[^\n]+?"")|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*('[^\n]+?')|[\s\n]+([a-z0-9-_]+) )*"; JavaScript = string.Format(scriptRegularExpressionString, attributeRegularExpressionString, "type|language", "[^\n]*javascript"); ServerScript = string.Format(scriptRegularExpressionString, attributeRegularExpressionString, "runat" , "server" ); } #endregion } |
▶ ASAX.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
namespace TestLibrary; /// <summary> /// ASAX /// </summary> public class ASAX : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.ASAX; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "ASAX"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "asax"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"(<%)(--.*?--)(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlComment }, { 3, ScopeName.HtmlServerSideScript } } ), new LanguageRule ( @"(?is)(?<=<%@.+?language=""c\#"".*?%>.*?<script.*?runat=""server"">)(.*)(?=</script>)", new Dictionary<int, string> { { 1, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageID.CSHARP) } } ), new LanguageRule ( @"(?is)(?<=<%@.+?language=""vb"".*?%>.*?<script.*?runat=""server"">)(.*)(?=</script>)", new Dictionary<int, string> { { 1, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageID.VBDOTNET) } } ), new LanguageRule ( @"(?xi)(</?)(?: ([a-z][a-z0-9-]*)(:) )*([a-z][a-z0-9-_]*)(?:[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*([^\s\n""']+?)|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*(""[^\n]+?"")|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*('[^\n]+?')|[\s\n]+([a-z0-9-_]+) )*[\s\n]*(/?>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlTagDelimiter }, { 4, ScopeName.HtmlElementName }, { 5, ScopeName.HtmlAttributeName }, { 6, ScopeName.HtmlOperator }, { 7, ScopeName.HtmlAttributeValue }, { 8, ScopeName.HtmlAttributeName }, { 9, ScopeName.HtmlOperator }, { 10, ScopeName.HtmlAttributeValue }, { 11, ScopeName.HtmlAttributeName }, { 12, ScopeName.HtmlOperator }, { 13, ScopeName.HtmlAttributeValue }, { 14, ScopeName.HtmlAttributeName }, { 15, ScopeName.HtmlTagDelimiter } } ), new LanguageRule ( @"(<%)(@)(?:\s+([a-zA-Z0-9]+))*(?:\s+([a-zA-Z0-9]+)(=)(""[^\n]*?""))*\s*?(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlTagDelimiter }, { 3, ScopeName.HtmlElementName }, { 4, ScopeName.HtmlAttributeName }, { 5, ScopeName.HtmlOperator }, { 6, ScopeName.HtmlAttributeValue }, { 7, ScopeName.HtmlServerSideScript } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { return false; } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ ASHX.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
namespace TestLibrary; /// <summary> /// ASHX /// </summary> public class ASHX : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.ASHX; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "ASHX"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "ashx"; } } #endregion #region 첫번쨰 라인 패턴 - FirstLinePattern /// <summary> /// 첫번쨰 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"(<%)(--.*?--)(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlComment }, { 3, ScopeName.HtmlServerSideScript } } ), new LanguageRule ( @"(?is)(?<=<%@.+?language=""c\#"".*?%>)(.*)", new Dictionary<int, string> { { 1, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageID.CSHARP) } } ), new LanguageRule ( @"(?is)(?<=<%@.+?language=""vb"".*?%>)(.*)", new Dictionary<int, string> { { 1, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageID.VBDOTNET) } } ), new LanguageRule ( @"(<%)(@)(?:\s+([a-zA-Z0-9]+))*(?:\s+([a-zA-Z0-9]+)(=)(""[^\n]*?""))*\s*?(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlTagDelimiter }, { 3, ScopeName.HtmlElementName }, { 4, ScopeName.HtmlAttributeName }, { 5, ScopeName.HtmlOperator }, { 6, ScopeName.HtmlAttributeValue }, { 7, ScopeName.HtmlServerSideScript } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { return false; } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ ASPX.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
namespace TestLibrary; /// <summary> /// ASPX /// </summary> public class ASPX : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.ASPX; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "ASPX"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "aspx"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"(?s)(<%)(--.*?--)(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlComment }, { 3, ScopeName.HtmlServerSideScript } } ), new LanguageRule( @"(?s)<!--.*?-->", new Dictionary<int, string> { { 0, ScopeName.HtmlComment } }), new LanguageRule ( @"(?i)(<%)(@)(?:\s+([a-z0-9]+))*(?:\s+([a-z0-9]+)(=)(""[^\n]*?""))*\s*?(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlTagDelimiter }, { 3, ScopeName.HtmlElementName }, { 4, ScopeName.HtmlAttributeName }, { 5, ScopeName.HtmlOperator }, { 6, ScopeName.HtmlAttributeValue }, { 7, ScopeName.HtmlServerSideScript } } ), new LanguageRule ( @"(?s)(?:(<%=|<%)(?!=|@|--))(?:.*?)(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlServerSideScript } } ), new LanguageRule ( @"(?is)(<!)(DOCTYPE)(?:\s+([a-z0-9]+))*(?:\s+(""[^""]*?""))*(>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlAttributeName }, { 4, ScopeName.HtmlAttributeValue }, { 5, ScopeName.HtmlTagDelimiter } } ), new LanguageRule(RuleFormat.JavaScript, RuleCapture.JavaScriptDictionary), new LanguageRule ( @"(?xi)(</?)(?: ([a-z][a-z0-9-]*)(:) )*([a-z][a-z0-9-_]*)(?:[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*([^\s\n""']+?)|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*(""[^\n]+?"")|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*('[^\n]+?')|[\s\n]+([a-z0-9-_]+) )*[\s\n]*(/?>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlTagDelimiter }, { 4, ScopeName.HtmlElementName }, { 5, ScopeName.HtmlAttributeName }, { 6, ScopeName.HtmlOperator }, { 7, ScopeName.HtmlAttributeValue }, { 8, ScopeName.HtmlAttributeName }, { 9, ScopeName.HtmlOperator }, { 10, ScopeName.HtmlAttributeValue }, { 11, ScopeName.HtmlAttributeName }, { 12, ScopeName.HtmlOperator }, { 13, ScopeName.HtmlAttributeValue }, { 14, ScopeName.HtmlAttributeName }, { 15, ScopeName.HtmlTagDelimiter } } ), new LanguageRule ( @"(?i)&[a-z0-9]+?;", new Dictionary<int, string> { { 0, ScopeName.HtmlEntity } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { return false; } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ ASPXCS.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
namespace TestLibrary; /// <summary> /// ASPX CS /// </summary> public class ASPXCS : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.ASPXCS; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "ASPX (C#)"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "aspx-cs"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return @"(?xims)<%@\s*?(?:page|control|master|servicehost|webservice).*?(?:language=""c\#""|src="".+?.cs"").*?%>"; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"(?s)(<%)(--.*?--)(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlComment }, { 3, ScopeName.HtmlServerSideScript } } ), new LanguageRule ( @"(?s)<!--.*-->", new Dictionary<int, string> { { 0, ScopeName.HtmlComment }, } ), new LanguageRule ( @"(?i)(<%)(@)(?:\s+([a-z0-9]+))*(?:\s+([a-z0-9]+)\s*(=)\s*(""[^\n]*?""))*\s*?(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlTagDelimiter }, { 3, ScopeName.HtmlElementName }, { 4, ScopeName.HtmlAttributeName }, { 5, ScopeName.HtmlOperator }, { 6, ScopeName.HtmlAttributeValue }, { 7, ScopeName.HtmlServerSideScript } } ), new LanguageRule ( @"(?s)(?:(<%=|<%)(?!=|@|--))(.*?)(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, $"{ScopeName.LanguagePrefix}{LanguageID.CSHARP}" }, { 3, ScopeName.HtmlServerSideScript } } ), new LanguageRule(RuleFormat.ServerScript, RuleCapture.CSharpScriptDictionary), new LanguageRule ( @"(?i)(<!)(DOCTYPE)(?:\s+([a-zA-Z0-9]+))*(?:\s+(""[^""]*?""))*(>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlAttributeName }, { 4, ScopeName.HtmlAttributeValue }, { 5, ScopeName.HtmlTagDelimiter } } ), new LanguageRule(RuleFormat.JavaScript, RuleCapture.JavaScriptDictionary), new LanguageRule ( @"(?xis)(</?)(?: ([a-z][a-z0-9-]*)(:) )*([a-z][a-z0-9-_]*)(?:[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*([^\s\n""']+?)|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*(""[^\n]+?"")|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*('[^\n]+?')|[\s\n]+([a-z0-9-_]+) )*[\s\n]*(/?>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlTagDelimiter }, { 4, ScopeName.HtmlElementName }, { 5, ScopeName.HtmlAttributeName }, { 6, ScopeName.HtmlOperator }, { 7, ScopeName.HtmlAttributeValue }, { 8, ScopeName.HtmlAttributeName }, { 9, ScopeName.HtmlOperator }, { 10, ScopeName.HtmlAttributeValue }, { 11, ScopeName.HtmlAttributeName }, { 12, ScopeName.HtmlOperator }, { 13, ScopeName.HtmlAttributeValue }, { 14, ScopeName.HtmlAttributeName }, { 15, ScopeName.HtmlTagDelimiter } } ), new LanguageRule ( @"(?i)&\#?[a-z0-9]+?;", new Dictionary<int, string> { { 0, ScopeName.HtmlEntity } } ), }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "aspx-cs": case "aspx (cs)": case "aspx(cs)": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ ASPXVB.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
namespace TestLibrary; /// <summary> /// ASPX VB /// </summary> public class ASPXVB : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.ASPXVB; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "ASPX (VB.NET)"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "aspx-vb"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return @"(?xims)<%@\s*?(?:page|control|master|webhandler|servicehost|webservice).*?language=""vb"".*?%>"; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"(?s)(<%)(--.*?--)(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlComment }, { 3, ScopeName.HtmlServerSideScript } } ), new LanguageRule ( @"(?s)<!--.*-->", new Dictionary<int, string> { { 0, ScopeName.HtmlComment }, } ), new LanguageRule ( @"(?i)(<%)(@)(?:\s+([a-z0-9]+))*(?:\s+([a-z0-9]+)\s*(=)\s*(""[^\n]*?""))*\s*?(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, ScopeName.HtmlTagDelimiter }, { 3, ScopeName.HtmlElementName }, { 4, ScopeName.HtmlAttributeName }, { 5, ScopeName.HtmlOperator }, { 6, ScopeName.HtmlAttributeValue }, { 7, ScopeName.HtmlServerSideScript } } ), new LanguageRule ( @"(?s)(?:(<%=|<%)(?!=|@|--))(.*?)(%>)", new Dictionary<int, string> { { 1, ScopeName.HtmlServerSideScript }, { 2, $"{ScopeName.LanguagePrefix}{LanguageID.VBDOTNET}" }, { 3, ScopeName.HtmlServerSideScript } } ), new LanguageRule(RuleFormat.ServerScript, RuleCapture.VbDotNetScriptDictionary), new LanguageRule( @"(?i)(<!)(DOCTYPE)(?:\s+([a-zA-Z0-9]+))*(?:\s+(""[^""]*?""))*(>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlAttributeName }, { 4, ScopeName.HtmlAttributeValue }, { 5, ScopeName.HtmlTagDelimiter } }), new LanguageRule(RuleFormat.JavaScript, RuleCapture.JavaScriptDictionary), new LanguageRule ( @"(?xis)(</?)(?: ([a-z][a-z0-9-]*)(:) )*([a-z][a-z0-9-_]*)(?:[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*(?:'(<%\#)(.+?)(%>)')|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*(?:""(<%\#)(.+?)(%>)"")|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*([^\s\n""']+?)|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*(""[^\n]+?"")|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*('[^\n]+?')|[\s\n]+([a-z0-9-_]+) )*[\s\n]*(/?>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlTagDelimiter }, { 4, ScopeName.HtmlElementName }, { 5, ScopeName.HtmlAttributeName }, { 6, ScopeName.HtmlOperator }, { 7, ScopeName.HtmlServerSideScript }, { 8, $"{ScopeName.LanguagePrefix}{LanguageID.VBDOTNET}" }, { 9, ScopeName.HtmlServerSideScript }, { 10, ScopeName.HtmlAttributeName }, { 11, ScopeName.HtmlOperator }, { 12, ScopeName.HtmlServerSideScript }, { 13, $"{ScopeName.LanguagePrefix}{LanguageID.VBDOTNET}" }, { 14, ScopeName.HtmlServerSideScript }, { 15, ScopeName.HtmlAttributeName }, { 16, ScopeName.HtmlOperator }, { 17, ScopeName.HtmlAttributeValue }, { 18, ScopeName.HtmlAttributeName }, { 19, ScopeName.HtmlOperator }, { 20, ScopeName.HtmlAttributeValue }, { 21, ScopeName.HtmlAttributeName }, { 22, ScopeName.HtmlOperator }, { 23, ScopeName.HtmlAttributeValue }, { 24, ScopeName.HtmlAttributeName }, { 25, ScopeName.HtmlTagDelimiter } } ), new LanguageRule ( @"(?i)&\#?[a-z0-9]+?;", new Dictionary<int, string> { { 0, ScopeName.HtmlEntity } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "aspx-vb": case "aspx (vb.net)": case "aspx(vb.net)": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ CPP.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
namespace TestLibrary; /// <summary> /// C++ /// </summary> public class CPP : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.CPP; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "C++"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "cplusplus"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), new LanguageRule ( @"(//.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"(?s)(""[^\n]*?(?<!\\)"")", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"\b(abstract|array|auto|bool|break|case|catch|char|ref class|class|const|const_cast|continue|default|delegate|delete|deprecated|dllexport|dllimport|do|double|dynamic_cast|each|else|enum|event|explicit|export|extern|false|float|for|friend|friend_as|gcnew|generic|goto|if|in|initonly|inline|int|interface|literal|long|mutable|naked|namespace|new|noinline|noreturn|nothrow|novtable|nullptr|operator|private|property|protected|public|register|reinterpret_cast|return|safecast|sealed|selectany|short|signed|sizeof|static|static_cast|ref struct|struct|switch|template|this|thread|throw|true|try|typedef|typeid|typename|union|unsigned|using|uuid|value|virtual|void|volatile|wchar_t|while)\b", new Dictionary<int, string> { {0, ScopeName.Keyword} } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "c++": case "c": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ CSHARP.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
namespace TestLibrary; /// <summary> /// C# /// </summary> public class CSHARP : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.CSHARP; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "C#"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "csharp"; } } #endregion #region 첫번쨰 라인 패턴 - FirstLinePattern /// <summary> /// 첫번쨰 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), new LanguageRule ( @"(///)(?:\s*?(<[/a-zA-Z0-9\s""=]+>))*([^\r\n]*)", new Dictionary<int, string> { { 1, ScopeName.XmlDocTag }, { 2, ScopeName.XmlDocTag }, { 3, ScopeName.XmlDocComment } } ), new LanguageRule ( @"(//.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"'[^\n]*?(?<!\\)'", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"(?s)@""(?:""""|.)*?""(?!"")", new Dictionary<int, string> { { 0, ScopeName.StringCSharpVerbatim } } ), new LanguageRule ( @"(?s)(""[^\n]*?(?<!\\)"")", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"\[(assembly|module|type|return|param|method|field|property|event):[^\]""]*(""[^\n]*?(?<!\\)"")?[^\]]*\]", new Dictionary<int, string> { { 1, ScopeName.Keyword }, { 2, ScopeName.String } } ), new LanguageRule ( @"^\s*(\#define|\#elif|\#else|\#endif|\#endregion|\#error|\#if|\#line|\#pragma|\#region|\#undef|\#warning).*?$", new Dictionary<int, string> { { 1, ScopeName.PreprocessorKeyword } } ), new LanguageRule ( @"\b(abstract|as|ascending|base|bool|break|by|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|equals|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|goto|group|if|implicit|in|int|into|interface|internal|is|join|let|lock|long|namespace|new|null|object|on|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|var|virtual|void|volatile|where|while|yield|async|await|warning|disable)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ), new LanguageRule ( @"\b[0-9]{1,}\b", new Dictionary<int, string> { { 0, ScopeName.Number } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "cs": case "c#": case "csharp": case "cake": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ CSS.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
namespace TestLibrary; /// <summary> /// CSS /// </summary> public class CSS : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.CSS; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "CSS"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "css"; } } #endregion #region 첫번쨰 라인 패턴 - FirstLinePattern /// <summary> /// 첫번쨰 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"(?msi)(?:(\s*/\*.*?\*/)|(([a-z0-9#. \[\]=\"":_-]+)\s*(?:,\s*|{))+(?:(\s*/\*.*?\*/)|(?:\s*([a-z0-9 -]+\s*):\s*([a-z0-9#,<>\?%. \(\)\\\/\*\{\}:'\""!_=-]+);?))*\s*})", new Dictionary<int, string> { { 3, ScopeName.CssSelector }, { 5, ScopeName.CssPropertyName }, { 6, ScopeName.CssPropertyValue }, { 4, ScopeName.Comment }, { 1, ScopeName.Comment } } ), }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { return false; } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ FORTRAN.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
namespace TestLibrary; /// <summary> /// FORTRAN /// </summary> public class FORTRAN : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.FORTRAN; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "Fortran"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "fortran"; } } #endregion #region 첫번쨰 라인 패턴 - FirstLinePattern /// <summary> /// 첫번쨰 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { // Comments new LanguageRule ( @"!.*", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), // String type 1 new LanguageRule ( @""".*?""|'.*?'", new Dictionary<int, string> { { 0, ScopeName.String } } ), // Program keywords new LanguageRule ( @"(?i)\b(?:program|endprogram)\b", new Dictionary<int, string> { { 0, ScopeName.Keyword } } ), // Module keywords new LanguageRule ( @"(?i)\b(?:module|endmodule|contains)\b", new Dictionary<int, string> { { 0, ScopeName.Keyword } } ), // Type keywords new LanguageRule ( @"(?i)\b(?:type|endtype|abstract)\b", new Dictionary<int, string> { { 0, ScopeName.Keyword } } ), // Interface definition keywords new LanguageRule ( @"(?i)\b(?:interface|endinterface|operator|assignment)\b", new Dictionary<int, string> { { 0, ScopeName.Keyword } } ), // Procedure definition keywords new LanguageRule ( @"(?i)\b(?:function|endfunction|subroutine|endsubroutine|elemental|recursive|pure)\b", new Dictionary<int, string> { { 0, ScopeName.Keyword } } ), // Variable keywords new LanguageRule ( @"(?i)INTEGER|REAL|DOUBLE\s*PRECISION|COMPLEX|CHARACTER|LOGICAL|TYPE", new Dictionary<int, string> { { 0, ScopeName.Keyword } } ), // Attribute keywords new LanguageRule ( @"(?i)\b(?:parameter|allocatable|optional|pointer|save|dimension|target)\b", new Dictionary<int, string> { { 0, ScopeName.Keyword } } ), // Intent keywords new LanguageRule ( @"(?i)\b(intent)\s*(\()\s*(in|out|inout)\s*(\))", new Dictionary<int, string> { { 1, ScopeName.Keyword }, { 2, ScopeName.Brackets }, { 3, ScopeName.Keyword }, { 4, ScopeName.Brackets } } ), // Namelist new LanguageRule ( @"(?i)\b(namelist)(/)\w+(/)", new Dictionary<int, string> { { 1, ScopeName.Keyword }, { 2, ScopeName.Brackets }, { 3, ScopeName.Brackets } } ), // Intrinsic functions new LanguageRule ( @"(?i)\b(PRESENT" + "|INT|REAL|DBLE|CMPLX|AIMAG|CONJG|AINT|ANINT|NINT|ABS|MOD|SIGN|DIM|DPROD|MODULO|FLOOR|CEILING|MAX|MIN" + "|SQRT|EXP|LOG|LOG10|SIN|COS|TAN|ASIN|ACOS|ATAN|ATAN2|SINH|COSH|TANH" + "|ICHAR|CHAR|LGE|LGT|LLE|LLT|IACHAR|ACHAR|INDEX|VERIFY|ADJUSTL|ADJUSTR|SCAN|LEN_TRIM|REPEAT|TRIM" + "|KIND|SELECTED_INT_KIND|SELECTED_REAL_KIND" + "|LOGICAL" + "|IOR|IAND|NOT|IEOR| ISHFT|ISHFTC|BTEST|IBSET|IBCLR|BITSIZE" + "|TRANSFER" + "|RADIX|DIGITS|MINEXPONENT|MAXEXPONENT|PRECISION|RANGE|HUGE|TINY|EPSILON" + "|EXPONENT|SCALE|NEAREST|FRACTION|SET_EXPONENT|SPACING|RRSPACING" + "|LBOUND|SIZE|UBOUND" + "|MASK" + "|MATMUL|DOT_PRODUCT" + "|SUM|PRODUCT|MAXVAL|MINVAL|COUNT|ANY|ALL" + "|ALLOCATED|SIZE|SHAPE|LBOUND|UBOUND" + "|MERGE|SPREAD|PACK|UNPACK" + "|RESHAPE" + "|TRANSPOSE|EOSHIFT|CSHIFT" + "|MAXLOC|MINLOC" + @"|ASSOCIATED)\b(\()", new Dictionary<int, string> { { 1, ScopeName.Intrinsic }, { 2, ScopeName.Brackets } } ), // Intrinsic functions new LanguageRule ( @"(?i)(call)\s+(DATE_AND_TIME|SYSTEM_CLOCK|RANDOM_NUMBER|RANDOM_SEED|MVBITS)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword }, { 2, ScopeName.Intrinsic } } ), // Special Character new LanguageRule ( @"\=|\*|\+|\\|\-|\.\w+\.|>|<|::|%|,|;|\?|\$", new Dictionary<int, string> { { 0, ScopeName.SpecialCharacter } } ), // Line Continuation new LanguageRule ( @"&", new Dictionary<int, string> { { 0, ScopeName.Continuation } } ), // Number new LanguageRule ( @"\b[0-9.]+(_\w+)?\b", new Dictionary<int, string> { { 0, ScopeName.Number } } ), // Brackets new LanguageRule ( @"[\(\)\[\]]", new Dictionary<int, string> { { 0, ScopeName.Brackets } } ), // Preprocessor keywords new LanguageRule ( @"(?i)(?:#define|#elif|#elifdef|#elifndef|#else|#endif|#error|#if|#ifdef|#ifndef|#include|#line|#pragma|#undef)\b", new Dictionary<int, string> { { 0, ScopeName.PreprocessorKeyword } } ), // General keywords new LanguageRule ( @"(?i)\b(?:end|use|do|enddo|select|endselect|case|endcase|if|then|else|endif|implicit|none" + @"|do\s+while|call|public|private|protected|where|go\s*to|file|block|data|blockdata" + @"|end\s*blockdata|default|procedure|include|go\s*to|allocate|deallocate|open|close|write|stop|return)\b", new Dictionary<int, string> { { 0, ScopeName.Keyword } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "fortran": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ FSHARP.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
namespace TestLibrary; /// <summary> /// F# /// </summary> public class FSHARP : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.FSHARP; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "F#"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "FSharp"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"\(\*([^*]|[\r\n]|(\*+([^*)]|[\r\n])))*\*+\)", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), new LanguageRule ( @"(///)(?:\s*?(<[/a-zA-Z0-9\s""=]+>))*([^\r\n]*)", new Dictionary<int, string> { { 1, ScopeName.XmlDocTag }, { 2, ScopeName.XmlDocTag }, { 3, ScopeName.XmlDocComment } } ), new LanguageRule ( @"(//.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"'[^\n]*?(?<!\\)'", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"(?s)@""(?:""""|.)*?""(?!"")", new Dictionary<int, string> { { 0, ScopeName.StringCSharpVerbatim } } ), new LanguageRule ( @"(?s)""""""(?:""""|.)*?""""""(?!"")", new Dictionary<int, string> { { 0, ScopeName.StringCSharpVerbatim } } ), new LanguageRule ( @"(?s)(""[^\n]*?(?<!\\)"")", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"^\s*(\#else|\#endif|\#if).*?$", new Dictionary<int, string> { { 1, ScopeName.PreprocessorKeyword } } ), new LanguageRule ( @"\b(let!|use!|do!|yield!|return!)\s", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ), new LanguageRule ( @"\b(abstract|and|as|assert|base|begin|class|default|delegate|do|done|downcast|downto|elif|else|end|exception|extern|false|finally|for|fun|function|global|if|in|inherit|inline|interface|internal|lazy|let|match|member|module|mutable|namespace|new|null|of|open|or|override|private|public|rec|return|sig|static|struct|then|to|true|try|type|upcast|use|val|void|when|while|with|yield|atomic|break|checked|component|const|constraint|constructor|continue|eager|fixed|fori|functor|include|measure|method|mixin|object|parallel|params|process|protected|pure|recursive|sealed|tailcall|trait|virtual|volatile|async|let!|use!|do!)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ), new LanguageRule ( @"(\w|\s)(->)(\w|\s)", new Dictionary<int, string> { { 2, ScopeName.Keyword } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "fs": case "f#": case "fsharp": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ HASKELL.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
namespace TestLibrary; /// <summary> /// HASKELL /// </summary> public class HASKELL : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field private const string nonnestComment = @"((?:--.*\r?\n|{-(?:[^-]|-(?!})|[\r\n])*-}))"; private const string incomment = @"([^-{}]|{(?!-)|-(?!})|(?<!-)})*"; private const string keywords = @"case|class|data|default|deriving|do|else|foreign|if|import|in|infix|infixl|infixr|instance|let|module|newtype|of|then|type|where"; private const string opKeywords = @"\.\.|:|::|=|\\|\||<-|->|@|~|=>"; private const string vsymbol = @"[\!\#\$%\&\⋆\+\./<=>\?@\\\^\-~\|]"; private const string symbol = @"(?:" + vsymbol + "|:)"; private const string varop = vsymbol + "(?:" + symbol + @")*"; private const string conop = ":(?:" + symbol + @")*"; private const string conid = @"(?:[A-Z][\w']*|\(" + conop + @"\))"; private const string varid = @"(?:[a-z][\w']*|\(" + varop + @"\))"; private const string qconid = @"((?:[A-Z][\w']*\.)*)" + conid; private const string qvarid = @"((?:[A-Z][\w']*\.)*)" + varid; private const string qconidop = @"((?:[A-Z][\w']*\.)*)(?:" + conid + "|" + conop + ")"; private const string intype = @"(\bforall\b|=>)|" + qconidop + @"|(?!deriving|where|data|type|newtype|instance|class)([a-z][\w']*)|\->|[ \t!\#]|\r?\n[ \t]+(?=[\(\)\[\]]|->|=>|[A-Z])"; private const string toptype = "(?:" + intype + "|::)"; private const string nestedtype = @"(?:" + intype + ")"; private const string datatype = "(?:" + intype + @"|[,]|\r?\n[ \t]+|::|(?<!" + symbol + @"|^)([=\|])\s*(" + conid + ")|" + nonnestComment + ")"; private const string inexports = @"(?:[\[\],\s]|(" + conid + ")|" + varid + "|" + nonnestComment + @"|\((?:[,\.\s]|(" + conid + ")|" + varid + @")*\)" + ")*"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.HASKELL; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "Haskell"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "haskell"; } } #endregion #region 첫번쨰 라인 패턴 - FirstLinePattern /// <summary> /// 첫번쨰 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { // Nested block comments: note does not match no unclosed block comments. new LanguageRule ( // Handle nested block comments using named balanced groups @"{-+" + incomment + @"(?>" + @"(?>(?<comment>{-)" + incomment + ")+" + @"(?>(?<-comment>-})" + incomment + ")+" + @")*" + @"(-+})", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), // Line comments new LanguageRule ( @"(--.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), // Types new LanguageRule ( // Type highlighting using named balanced groups to balance parenthesized sub types // 'toptype' and 'nestedtype' capture three groups: type keywords, namespaces, and type variables @"(?:" + @"\b(class|instance|deriving)\b"+ @"|::(?!" + symbol + ")" + @"|\b(type)\s+" + toptype + @"*\s*(=)" + @"|\b(data|newtype)\s+" + toptype + @"*\s*(=)\s*(" + conid + ")" + @"|\s+(\|)\s*(" + conid + ")" + ")" + toptype + "*" + @"(?:" + @"(?:(?<type>[\(\[<])(?:" + nestedtype + @"|[,]" + @")*)+" + @"(?:(?<-type>[\)\]>])(?:" + nestedtype + @"|(?(type)[,])" + @")*)+" + @")*", new Dictionary<int,string> { { 0, ScopeName.Type }, { 1, ScopeName.Keyword }, // class instance etc { 2, ScopeName.Keyword }, // type { 3, ScopeName.Keyword }, { 4, ScopeName.NameSpace }, { 5, ScopeName.TypeVariable }, { 6, ScopeName.Keyword }, { 7, ScopeName.Keyword }, // data , newtype { 8, ScopeName.Keyword }, { 9, ScopeName.NameSpace }, { 10, ScopeName.TypeVariable }, { 11, ScopeName.Keyword }, // = conid { 12, ScopeName.Constructor }, { 13, ScopeName.Keyword }, // | conid { 14, ScopeName.Constructor }, { 15, ScopeName.Keyword }, { 16, ScopeName.NameSpace }, { 17, ScopeName.TypeVariable }, { 18, ScopeName.Keyword }, { 19, ScopeName.NameSpace }, { 20, ScopeName.TypeVariable }, { 21, ScopeName.Keyword }, { 22, ScopeName.NameSpace }, { 23, ScopeName.TypeVariable } } ), // Special sequences new LanguageRule ( @"\b(module)\s+(" + qconid + @")(?:\s*\(" + inexports + @"\))?", new Dictionary<int, string> { { 1, ScopeName.Keyword }, { 2, ScopeName.NameSpace }, { 4, ScopeName.Type }, { 5, ScopeName.Comment }, { 6, ScopeName.Constructor } } ), new LanguageRule ( @"\b(module|as)\s+(" + qconid + ")", new Dictionary<int, string> { { 1, ScopeName.Keyword }, { 2, ScopeName.NameSpace } } ), new LanguageRule ( @"\b(import)\s+(qualified\s+)?(" + qconid + @")\s*" + @"(?:\(" + inexports + @"\))?" + @"(?:(hiding)(?:\s*\(" + inexports + @"\)))?", new Dictionary<int, string> { { 1, ScopeName.Keyword }, { 2, ScopeName.Keyword }, { 3, ScopeName.NameSpace }, { 5, ScopeName.Type }, { 6, ScopeName.Comment }, { 7, ScopeName.Constructor }, { 8, ScopeName.Keyword }, { 9, ScopeName.Type }, { 10, ScopeName.Comment }, { 11, ScopeName.Constructor } } ), // Keywords new LanguageRule ( @"\b(" + keywords + @")\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ), new LanguageRule ( @"(?<!" + symbol +")(" + opKeywords + ")(?!" + symbol + ")", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ), // Names new LanguageRule ( qvarid, new Dictionary<int, string> { { 1, ScopeName.NameSpace } } ), new LanguageRule ( qconid, new Dictionary<int, string> { { 0, ScopeName.Constructor }, { 1, ScopeName.NameSpace } } ), // Operators and punctuation new LanguageRule ( varop, new Dictionary<int, string> { { 0, ScopeName.Operator } } ), new LanguageRule ( conop, new Dictionary<int, string> { { 0, ScopeName.Constructor } } ), new LanguageRule ( @"[{}\(\)\[\];,]", new Dictionary<int, string> { { 0, ScopeName.Delimiter } } ), // Literals new LanguageRule ( @"0[xX][\da-fA-F]+|\d+(\.\d+([eE][\-+]?\d+)?)?", new Dictionary<int, string> { { 0, ScopeName.Number } } ), new LanguageRule ( @"'[^\n]*?'", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"""[^\n]*?""", new Dictionary<int, string> { { 0, ScopeName.String } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "hs": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ HTML.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
namespace TestLibrary; /// <summary> /// HTML /// </summary> public class HTML : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID = ID /// <summary> /// /// </summary> public string ID { get { return LanguageID.HTML; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "HTML"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "html"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>", new Dictionary<int, string> { { 0, ScopeName.HtmlComment }, } ), new LanguageRule ( @"(?i)(<!)(DOCTYPE)(?:\s+([a-zA-Z0-9]+))*(?:\s+(""[^""]*?""))*(>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlAttributeName }, { 4, ScopeName.HtmlAttributeValue }, { 5, ScopeName.HtmlTagDelimiter } } ), new LanguageRule ( @"(?xis)(<)(script)(?:[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*([^\s\n""']+?)|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*(""[^\n]+?"")|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*('[^\n]+?')|[\s\n]+([a-z0-9-_]+) )*[\s\n]*(>)(.*?)(</)(script)(>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlAttributeName }, { 4, ScopeName.HtmlOperator }, { 5, ScopeName.HtmlAttributeValue }, { 6, ScopeName.HtmlAttributeName }, { 7, ScopeName.HtmlOperator }, { 8, ScopeName.HtmlAttributeValue }, { 9, ScopeName.HtmlAttributeName }, { 10, ScopeName.HtmlOperator }, { 11, ScopeName.HtmlAttributeValue }, { 12, ScopeName.HtmlAttributeName }, { 13, ScopeName.HtmlTagDelimiter }, { 14, $"{ScopeName.LanguagePrefix}{LanguageID.JAVASCRIPT}" }, { 15, ScopeName.HtmlTagDelimiter }, { 16, ScopeName.HtmlElementName }, { 17, ScopeName.HtmlTagDelimiter } } ), new LanguageRule ( @"(?xis)(</?)(?: ([a-z][a-z0-9-]*)(:) )*([a-z][a-z0-9-_]*)(?:[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*([^\s\n""']+?)|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*(""[^\n]+?"")|[\s\n]+([a-z0-9-_]+)[\s\n]*(=)[\s\n]*('[^\n]+?')|[\s\n]+([a-z0-9-_]+) )*[\s\n]*(/?>)", new Dictionary<int, string> { { 1, ScopeName.HtmlTagDelimiter }, { 2, ScopeName.HtmlElementName }, { 3, ScopeName.HtmlTagDelimiter }, { 4, ScopeName.HtmlElementName }, { 5, ScopeName.HtmlAttributeName }, { 6, ScopeName.HtmlOperator }, { 7, ScopeName.HtmlAttributeValue }, { 8, ScopeName.HtmlAttributeName }, { 9, ScopeName.HtmlOperator }, { 10, ScopeName.HtmlAttributeValue }, { 11, ScopeName.HtmlAttributeName }, { 12, ScopeName.HtmlOperator }, { 13, ScopeName.HtmlAttributeValue }, { 14, ScopeName.HtmlAttributeName }, { 15, ScopeName.HtmlTagDelimiter } } ), new LanguageRule ( @"(?i)&\#?[a-z0-9]+?;", new Dictionary<int, string> { { 0, ScopeName.HtmlEntity } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "htm": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ JAVA.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
namespace TestLibrary; /// <summary> /// JAVA /// </summary> public class JAVA : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.JAVA; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "Java"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "java"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), new LanguageRule ( @"(//.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"'[^\n]*?(?<!\\)'", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"(?s)(""[^\n]*?(?<!\\)"")", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"\b(abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|false|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|transient|true|try|void|volatile|while)\b", new Dictionary<int, string> { {0, ScopeName.Keyword} } ), new LanguageRule ( @"\b[0-9]{1,}\b", new Dictionary<int, string> { { 0, ScopeName.Number } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { return false; } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ JAVASCRIPT.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
namespace TestLibrary; /// <summary> /// 자바 스크립트 /// </summary> public class JAVASCRIPT : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// /// </summary> public string ID { get { return LanguageID.JAVASCRIPT; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "JavaScript"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "javascript"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), new LanguageRule ( @"(//.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"'[^\n]*?'", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"""[^\n]*?""", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"\b(abstract|boolean|break|byte|case|catch|char|class|const|continue|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|void|volatile|while|with)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "js": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ JSON.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
namespace TestLibrary; /// <summary> /// JSON /// </summary> public class JSON : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// REGEX_STRING /// </summary> private const string REGEX_STRING = @"""[^""\\]*(?:\\[^\r\n]|[^""\\]*)*"""; /// <summary> /// REGEX_NUMBER /// </summary> private const string REGEX_NUMBER = @"-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// /// </summary> public string ID { get { return LanguageID.JSON; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "JSON"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "json"; } } #endregion #region 첫번쨰 라인 패턴 - FirstLinePattern /// <summary> /// 첫번쨰 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { 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 } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { return false; } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ KOKA.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
namespace TestLibrary; /// <summary> /// KOKA /// </summary> public class KOKA : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field private const string incomment = @"([^*/]|/(?!\*)|\*(?!/))*"; private const string plainKeywords = @"infix|infixr|infixl|type|cotype|rectype|struct|alias|interface|instance|external|fun|function|val|var|con|module|import|as|public|private|abstract|yield"; private const string controlKeywords = @"if|then|else|elif|match|return"; private const string typeKeywords = @"forall|exists|some|with"; private const string pseudoKeywords = @"include|inline|cs|js|file"; private const string opkeywords = @"[=\.\|]|\->|\:="; private const string intype = @"\b(" + typeKeywords + @")\b|(?:[a-z]\w*/)*[a-z]\w+\b|(?:[a-z]\w*/)*[A-Z]\w*\b|([a-z][0-9]*\b|_\w*\b)|\->|[\s\|]"; private const string toptype = "(?:" + intype + "|::)"; private const string nestedtype = @"(?:([a-z]\w*)\s*[:]|" + intype + ")"; private const string symbol = @"[$%&\*\+@!\\\^~=\.:\-\?\|<>/]"; private const string symbols = @"(?:" + symbol + @")+"; private const string escape = @"\\(?:[nrt\\""']|x[\da-fA-F]{2}|u[\da-fA-F]{4}|U[\da-fA-F]{6})"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.KOKA; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "Koka"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "koka"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { // Nested block comments. note: does not match on unclosed comments new LanguageRule ( // Handle nested block comments using named balanced groups @"/\*" + incomment + @"(" + @"((?<comment>/\*)" + incomment + ")+" + @"((?<-comment>\*/)" + incomment + ")+" + @")*" + @"(\*+/)", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), // Line comments new LanguageRule ( @"(//.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), // operator keywords new LanguageRule ( @"(?<!" + symbol + ")(" + opkeywords + @")(?!" + symbol + @")", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ), // Types new LanguageRule ( // Type highlighting using named balanced groups to balance parenthesized sub types // 'toptype' captures two groups: type keyword and type variables // each 'nestedtype' captures three groups: parameter names, type keywords and type variables @"(?:" + @"\b(type|struct|cotype|rectype)\b|" + @"::?(?!" + symbol + ")|" + @"\b(alias)\s+[a-z]\w+\s*(?:<[^>]*>\s*)?(=)" + ")" + toptype + "*" + @"(?:" + @"(?:(?<type>[\(\[<])(?:" + nestedtype + @"|[,]" + @")*)+" + @"(?:(?<-type>[\)\]>])(?:" + nestedtype + @"|(?(type)[,])" + @")*)+" + @")*" + @"", new Dictionary<int,string> { { 0, ScopeName.Type }, { 1, ScopeName.Keyword }, // type struct etc { 2, ScopeName.Keyword }, // alias { 3, ScopeName.Keyword }, // = { 4, ScopeName.Keyword }, { 5, ScopeName.TypeVariable }, { 6, ScopeName.PlainText }, { 7, ScopeName.Keyword }, { 8, ScopeName.TypeVariable }, { 9, ScopeName.PlainText }, { 10, ScopeName.Keyword }, { 11, ScopeName.TypeVariable } } ), // module and imports new LanguageRule ( @"\b(module)\s+(interface\s+)?((?:[a-z]\w*/)*[a-z]\w*)", new Dictionary<int, string> { { 1, ScopeName.Keyword }, { 2, ScopeName.Keyword }, { 3, ScopeName.NameSpace } } ), new LanguageRule ( @"\b(import)\s+((?:[a-z]\w*/)*[a-z]\w*)\s*(?:(=)\s*(qualified\s+)?((?:[a-z]\w*/)*[a-z]\w*))?", new Dictionary<int, string> { { 1, ScopeName.Keyword }, { 2, ScopeName.NameSpace }, { 3, ScopeName.Keyword }, { 4, ScopeName.Keyword }, { 5, ScopeName.NameSpace } } ), // keywords new LanguageRule ( @"\b(" + plainKeywords + "|" + typeKeywords + @")\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ), new LanguageRule ( @"\b(" + controlKeywords + @")\b", new Dictionary<int, string> { { 1, ScopeName.ControlKeyword } } ), new LanguageRule ( @"\b(" + pseudoKeywords + @")\b", new Dictionary<int, string> { { 1, ScopeName.PseudoKeyword } } ), // Names new LanguageRule ( @"([a-z]\w*/)*([a-z]\w*|\(" + symbols + @"\))", new Dictionary<int, string> { { 1, ScopeName.NameSpace } } ), new LanguageRule ( @"([a-z]\w*/)*([A-Z]\w*)", new Dictionary<int, string> { { 1, ScopeName.NameSpace }, { 2, ScopeName.Constructor } } ), // Operators and punctuation new LanguageRule ( symbols, new Dictionary<int, string> { { 0, ScopeName.Operator } } ), new LanguageRule ( @"[{}\(\)\[\];,]", new Dictionary<int, string> { { 0, ScopeName.Delimiter } } ), // Literals new LanguageRule ( @"0[xX][\da-fA-F]+|\d+(\.\d+([eE][\-+]?\d+)?)?", new Dictionary<int, string> { { 0, ScopeName.Number } } ), new LanguageRule ( @"(?s)'(?:[^\t\n\\']+|(" + escape + @")|\\)*'", new Dictionary<int, string> { { 0, ScopeName.String }, { 1, ScopeName.StringEscape } } ), new LanguageRule ( @"(?s)@""(?:("""")|[^""]+)*""(?!"")", new Dictionary<int, string> { { 0, ScopeName.StringCSharpVerbatim }, { 1, ScopeName.StringEscape } } ), new LanguageRule ( @"(?s)""(?:[^\t\n\\""]+|(" + escape + @")|\\)*""", new Dictionary<int, string> { { 0, ScopeName.String }, { 1, ScopeName.StringEscape } } ), new LanguageRule ( @"^\s*(\#error|\#line|\#pragma|\#warning|\#!/usr/bin/env\s+koka|\#).*?$", new Dictionary<int, string> { { 1, ScopeName.PreprocessorKeyword } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "kk": case "kki": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ MARKDOWN.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
namespace TestLibrary; /// <summary> /// MARKDOWN /// </summary> public class MARKDOWN : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.MARKDOWN; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "Markdown"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "markdown"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { // Heading new LanguageRule ( @"^(\#.*)\r?|^.*\r?\n([-]+|[=]+)\r?$", new Dictionary<int, string> { { 0, ScopeName.MarkdownHeader } } ), // Code block new LanguageRule ( @"^([ ]{4}(?![ ])(?:.|\r?\n[ ]{4})*)|^(```+[ \t]*\w*)((?:[ \t\r\n]|.)*?)(^```+)[ \t]*\r?$", new Dictionary<int, string> { { 1, ScopeName.MarkdownCode }, { 2, ScopeName.XmlDocTag }, { 3, ScopeName.MarkdownCode }, { 4, ScopeName.XmlDocTag } } ), // Line new LanguageRule ( @"^\s*((-\s*){3}|(\*\s*){3}|(=\s*){3})[ \t\-\*=]*\r?$", new Dictionary<int, string> { { 0, ScopeName.MarkdownHeader } } ), // List new LanguageRule ( @"^[ \t]*([\*\+\-]|\d+\.)", new Dictionary<int, string> { { 1, ScopeName.MarkdownListItem } } ), // Escape new LanguageRule ( @"\\[\`\*_{}\[\]\(\)\#\+\-\.\!]", new Dictionary<int, string> { { 0, ScopeName.StringEscape } } ), // Link new LanguageRule ( GetLink(GetLink()) + "|" + GetLink(), // support nested links (mostly for images) new Dictionary<int, string> { { 1, ScopeName.MarkdownBold }, { 2, ScopeName.XmlDocTag }, { 3, ScopeName.XmlDocTag }, { 4, ScopeName.MarkdownBold }, { 5, ScopeName.XmlDocTag } } ), new LanguageRule ( @"^[ ]{0,3}\[[^\]\n]+\]:(.|\r|\n[ \t]+(?![\r\n]))*$", new Dictionary<int, string> { { 0, ScopeName.XmlDocTag } } ), // Bold new LanguageRule ( @"\*(?!\*)([^\*\n]|\*\w)+?\*(?!\w)|\*\*([^\*\n]|\*(?!\*))+?\*\*", new Dictionary<int, string> { { 0, ScopeName.MarkdownBold } } ), // Emphasized new LanguageRule ( @"_([^_\n]|_\w)+?_(?!\w)|__([^_\n]|_(?=[\w_]))+?__(?!\w)", new Dictionary<int, string> { { 0, ScopeName.MarkdownEmph } } ), // Inline code new LanguageRule ( @"`[^`\n]+?`|``([^`\n]|`(?!`))+?``", new Dictionary<int, string> { { 0, ScopeName.MarkdownCode } } ), // Strings new LanguageRule ( @"""[^""\n]+?""|'[\w\-_]+'", new Dictionary<int, string> { { 0, ScopeName.String } } ), // Html tag new LanguageRule ( @"</?\w.*?>", new Dictionary<int, string> { { 0, ScopeName.HtmlTagDelimiter } } ), // Html entity new LanguageRule ( @"\&\#?\w+?;", new Dictionary<int, string> { { 0, ScopeName.HtmlEntity } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "md": case "markdown": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 링크 구하기 - GetLink(content) /// <summary> /// 링크 구하기 /// </summary> /// <param name="content">컨텐트</param> /// <returns>링크 구하기</returns> private string GetLink(string content = @"([^\]\n]+)") { return @"\!?\[" + content + @"\][ \t]*(\([^\)\n]*\)|\[[^\]\n]*\])"; } #endregion } |
▶ MATLAB.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
namespace TestLibrary; /// <summary> /// 매트랩 /// </summary> public class MATLAB : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.MATLAB; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "MATLAB"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "matlab"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { // Regular comments new LanguageRule ( @"(%.*)\r?", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), // Regular strings new LanguageRule ( @"(?<!\.)('[^\n]*?')", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"""[^\n]*?""", new Dictionary<int, string> { { 0, ScopeName.String } } ), // Keywords new LanguageRule ( @"(?i)\b(break|case|catch|continue|else|elseif|end|for|function|global|if|otherwise|persistent|return|switch|try|while)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ), // Line continuation new LanguageRule ( @"\.\.\.", new Dictionary<int, string> { { 0, ScopeName.Continuation } } ), // Numbers new LanguageRule ( @"\b([0-9.]|[0-9.]+(e-*)(?=[0-9]))+?\b", new Dictionary<int, string> { { 0, ScopeName.Number } } ), }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "m": return true; case "mat": return true; case "matlab": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ PHP.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
namespace TestLibrary; /// <summary> /// PHP /// </summary> public class PHP : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.PHP; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "PHP"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "php"; } } #endregion #region 첫번쨰 라인 패턴 - FirstLinePattern /// <summary> /// 첫번쨰 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), new LanguageRule ( @"(//.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"(#.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"'[^\n]*?(?<!\\)'", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"""[^\n]*?(?<!\\)""", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"\b(abstract|and|array|as|break|case|catch|cfunction|class|clone|const|continue|declare|default|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|exception|extends|fclose|file|final|for|foreach|function|global|goto|if|implements|interface|instanceof|mysqli_fetch_object|namespace|new|old_function|or|php_user_filter|private|protected|public|static|switch|throw|try|use|var|while|xor|__CLASS__|__DIR__|__FILE__|__FUNCTION__|__LINE__|__METHOD__|__NAMESPACE__|die|echo|empty|exit|eval|include|include_once|isset|list|require|require_once|return|print|unset)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "php3": case "php4": case "php5": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ POWERSHELL.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
namespace TestLibrary; /// <summary> /// 파워쉘 /// </summary> public class POWERSHELL : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.POWERSHELL; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "PowerShell"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "powershell"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule( @"(?s)(<\#.*?\#>)", new Dictionary<int, string> { {1, ScopeName.Comment} }), new LanguageRule( @"(\#.*?)\r?$", new Dictionary<int, string> { {1, ScopeName.Comment} }), new LanguageRule( @"'[^\n]*?(?<!\\)'", new Dictionary<int, string> { {0, ScopeName.String} }), new LanguageRule( @"(?s)@"".*?""@", new Dictionary<int, string> { {0, ScopeName.StringCSharpVerbatim} }), new LanguageRule( @"(?s)(""[^\n]*?(?<!`)"")", new Dictionary<int, string> { {0, ScopeName.String} }), new LanguageRule( @"\$(?:[\d\w\-]+(?::[\d\w\-]+)?|\$|\?|\^)", new Dictionary<int, string> { {0, ScopeName.PowerShellVariable} }), new LanguageRule( @"\${[^}]+}", new Dictionary<int, string> { {0, ScopeName.PowerShellVariable} }), new LanguageRule( @"(?i)\b(begin|break|catch|continue|data|do|dynamicparam|elseif|else|end|exit|filter|finally|foreach|for|from|function|if|in|param|process|return|switch|throw|trap|try|until|while)\b", new Dictionary<int, string> { {1, ScopeName.Keyword} }), new LanguageRule( @"\b(\w+\-\w+)\b", new Dictionary<int, string> { {1, ScopeName.PowerShellCommand} }), new LanguageRule( @"-(?:c|i)?(?:eq|ne|gt|ge|lt|le|notlike|like|notmatch|match|notcontains|contains|replace)", new Dictionary<int, string> { {0, ScopeName.PowerShellOperator} } ), new LanguageRule( @"-(?:band|and|as|join|not|bxor|xor|bor|or|isnot|is|split)", new Dictionary<int, string> { {0, ScopeName.PowerShellOperator} } ), new LanguageRule( @"-\w+\d*\w*", new Dictionary<int, string> { {0, ScopeName.PowerShellParameter} } ), new LanguageRule( @"(?:\+=|-=|\*=|/=|%=|=|\+\+|--|\+|-|\*|/|%|\||,)", new Dictionary<int, string> { {0, ScopeName.PowerShellOperator} } ), new LanguageRule( @"(?:\>\>|2\>&1|\>|2\>\>|2\>)", new Dictionary<int, string> { {0, ScopeName.PowerShellOperator} } ), new LanguageRule( @"(?is)\[(cmdletbinding|alias|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|validatescript|validaterange|validatepattern|validatelength|supportswildcards)[^\]]+\]", new Dictionary<int, string> { {1, ScopeName.PowerShellAttribute} }), new LanguageRule( @"(\[)([^\]]+)(\])(::)?", new Dictionary<int, string> { {1, ScopeName.PowerShellOperator}, {2, ScopeName.PowerShellType}, {3, ScopeName.PowerShellOperator}, {4, ScopeName.PowerShellOperator} }) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "posh": case "ps1": case "pwsh": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ PYTHON.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
namespace TestLibrary; /// <summary> /// 파이썬 /// </summary> public class PYTHON : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.PYTHON; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "Python"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "python"; } } #endregion #region 첫번쨰 라인 패턴 - FirstLinePattern /// <summary> /// 첫번쨰 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { // Docstring comments new LanguageRule ( @"(?<=:\s*)(""{3})([^""]+)(""{3})", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), new LanguageRule ( @"(?<=:\s*)('{3})([^']+)('{3})", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), // Regular comments new LanguageRule ( @"(#.*)\r?", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), // Multi-line strings new LanguageRule ( @"(?<==\s*f*b*r*u*)(""{3})([^""]+)(""{3})", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"(?<==\s*f*b*r*u*)('{3})([^']+)('{3})", new Dictionary<int, string> { { 0, ScopeName.String } } ), // Regular strings new LanguageRule ( @"'[^\n]*?'", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"""[^\n]*?""", new Dictionary<int, string> { { 0, ScopeName.String } } ), // Keywords new LanguageRule ( @"(?i)\b(False|await|else|import|pass|None|break|except|in|raise|True|class|finally|is|return|and|continue|for|lambda|try|as|def|from|" + @"nonlocal|while|assert|del|global|not|with|async|elif|if|or|yield|self)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword }, }), // intrinsic functions new LanguageRule( @"(?i)\b(abs|delattr|hash|memoryview|set|all|dict|help|min|setattr|any|dir|hex|next|slice|ascii|divmod|id|object|sorted|bin|enumerate" + "|input|oct|staticmethod|bool|eval|int|open|str|breakpoint|exec|isinstance|ord|sum|bytearray|filter|issubclass|pow|super|bytes|float" + "|iter|print|tuple|callable|format|len|property|type|chr|frozenset|list|range|vars|classmethod|getattr|locals|repr|zip|compile|globals" + @"|map|reversed|__import__|complex|hasattr|max|round)\b", new Dictionary<int, string> { { 1, ScopeName.Intrinsic } } ), // Numbers new LanguageRule ( @"\b([0-9.]|[0-9.]+(e-*)(?=[0-9]))+?\b", new Dictionary<int, string> { { 0, ScopeName.Number } } ), }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "py": return true; case "python": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ SQL.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
namespace TestLibrary; /// <summary> /// SQL /// </summary> public class SQL : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.SQL; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "SQL"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "sql"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"(?s)/\*.*?\*/", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), new LanguageRule ( @"(--.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"'(?>[^\']*)'", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"""(?>[^\""]*)""", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"\[(?>[^\]]*)]", new Dictionary<int, string> { { 0, null } } ), new LanguageRule ( @"(?i)\b(?<![.@""])(ADA|ADD|AFTER|ALL|ALTER|AND|ANY|AS|ASC|AT|AUTHORIZATION|AUTO|BACKUP|BEGIN|BETWEEN|BINARY|BIT|BIT_LENGTH|BREAK|BROWSE|BULK|BY|CASCADE|CASE|CHAR|CHARACTER|CHARACTER_LENGTH|CHAR_LENGTH|CHECK|CHECKPOINT|CHECKSUM_AGG|CLOSE|CLUSTERED|COLLATE|COL_LENGTH|COL_NAME|COLUMN|COLUMNPROPERTY|COMMIT|COMPUTE|CONNECT|CONNECTION|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CREATE|CROSS|CUBE|CURRENT|CURRENT_DATE|CURRENT_TIME|CURSOR|DATABASE|DATABASEPROPERTY|DATE|DATETIME|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFERRED|DELETE|DENY|DESC|DISK|DISTINCT|DISTRIBUTED|DOUBLE|DROP|DUMMY|DUMP|ELSE|ENCRYPTION|END-EXEC|END|ERRLVL|ESCAPE|EXCEPT|EXEC|EXECUTE|EXISTS|EXIT|EXTERNAL|EXTRACT|FALSE|FETCH|FILE|FILE_ID|FILE_NAME|FILEGROUP_ID|FILEGROUP_NAME|FILEGROUPPROPERTY|FILEPROPERTY|FILLFACTOR|FIRST|FLOAT|FOR|FOREIGN|FORTRAN|FREE|FREETEXT|FREETEXTTABLE|FROM|FULL|FULLTEXTCATALOGPROPERTY|FULLTEXTSERVICEPROPERTY|FUNCTION|GLOBAL|GOTO|GRANT|GROUP|HAVING|HOLDLOCK|HOUR|IDENTITY|IDENTITYCOL|IDENTITY_INSERT|IF|IGNORE|IMAGE|IMMEDIATE|IN|INCLUDE|INDEX|INDEX_COL|INDEXKEY_PROPERTY|INDEXPROPERTY|INNER|INSENSITIVE|INSERT|INSTEAD|INT|INTEGER|INTERSECT|INTO|IS|ISOLATION|JOIN|KEY|KILL|LANGUAGE|LAST|LEFT|LEVEL|LIKE|LINENO|LOAD|LOCAL|MINUTE|MODIFY|MONEY|NAME|NATIONAL|NCHAR|NEXT|NOCHECK|NONCLUSTERED|NOCOUNT|NONE|NOT|NULL|NUMERIC|NVARCHAR|OBJECT_ID|OBJECT_NAME|OBJECTPROPERTY|OCTET_LENGTH|OF|OFF|OFFSETS|ON|ONLY|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPENXML|OPTION|OR|ORDER|OUTER|OUTPUT|OVER|OVERLAPS|PARTIAL|PASCAL|PERCENT|PLAN|POSITION|PRECISION|PREPARE|PRIMARY|PRINT|PRIOR|PRIVILEGES|PROC|PROCEDURE|PUBLIC|RAISERROR|READ|READTEXT|REAL|RECONFIGURE|REFERENCES|REPLICATION|RESTORE|RESTRICT|RETURN|RETURNS|REVERT|REVOKE|RIGHT|ROLLBACK|ROLLUP|ROWCOUNT|ROWGUIDCOL|ROWS|RULE|SAVE|SCHEMA|SCROLL|SECOND|SECTION|SELECT|SEQUENCE|SET|SETUSER|SHUTDOWN|SIZE|SMALLINT|SMALLMONEY|SOME|SQLCA|SQLERROR|SQUARE|STATISTICS|TABLE|TEMPORARY|TEXT|TEXTPTR|TEXTSIZE|TEXTVALID|THEN|TIME|TIMESTAMP|TO|TOP|TRAN|TRANSACTION|TRANSLATION|TRIGGER|TRUE|TRUNCATE|TSEQUAL|TYPEPROPERTY|UNION|UNIQUE|UPDATE|UPDATETEXT|USE|VALUES|VARCHAR|VARYING|VIEW|WAITFOR|WHEN|WHERE|WHILE|WITH|WORK|WRITETEXT|IS_MEMBER|IS_SRVROLEMEMBER|PERMISSIONS|SUSER_SID|SUSER_SNAME|SYSNAME|UNIQUEIDENTIFIER|USER_ID|VARBINARY|ABSOLUTE|DATEPART|DATEDIFF|WEEK|WEEKDAY|MILLISECOND|GETUTCDATE|DATENAME|DATEADD|BIGINT|TINYINT|SMALLDATETIME|NTEXT|XML|ASSEMBLY|AGGREGATE|TYPE)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ), new LanguageRule ( @"(?i)\b(?<![.@""])(ABS|ACOS|APP_NAME|ASCII|ASIN|ATAN|ATN2|AVG|BINARY_CHECKSUM|CAST|CEILING|CHARINDEX|CHECKSUM|CONVERT|COALESCE|COLLATIONPROPERTY|COLUMNS_UPDATED|COUNT|COS|COT|COUNT_BIG|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR_STATUS|DATALENGTH|DAY|DB_ID|DB_NAME|DEGREES|DIFFERENCE|ERROR_LINE|ERROR_MESSAGE|ERROR_NUMBER|ERROR_PROCEDURE|ERROR_SEVERITY|ERROR_STATE|EXP|FLOOR|FORMATMESSAGE|GETANSINULL|GETDATE|GROUPING|HOST_ID|HOST_NAME|IDENT_CURRENT|IDENT_INCR|IDENT_SEED|ISDATE|ISNULL|ISNUMERIC|LEN|LOG|LOG10|LOWER|LTRIM|MAX|MIN|MONTH|NEWID|NULLIF|PARSENAME|PATINDEX|PI|POWER|ORIGINAL_LOGIN|QUOTENAME|UNICODE|ROW_NUMBER|RADIANS|RAND|ROUND|RTRIM|REPLACE|REPLICATE|REVERSE|SCOPE_IDENTITY|SOUNDEX|STR|STUFF|SERVERPROPERTY|SESSIONPROPERTY|SESSION_USER|SIGN|SIN|SPACE|STATS_DATE|STDEV|STDEVP|SQRT|SUBSTRING|SUM|SUSER_NAME|SQL_VARIANT|SQL_VARIANT_PROPERTY|SYSTEM_USER|TAN|UPPER|USER|USER_NAME|VAR|VARP|XACT_STATE|YEAR)\b", new Dictionary<int, string> { { 1, ScopeName.SqlSystemFunction } } ), new LanguageRule ( @"(?i)\B(@@(?:ERROR|IDENTITY|ROWCOUNT|TRANCOUNT|FETCH_STATUS))\b", new Dictionary<int, string> { {1, ScopeName.SqlSystemFunction} } ), }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { return false; } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ TYPESCRIPT.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
namespace TestLibrary; /// <summary> /// 타입 스크립트 /// </summary> public class TYPESCRIPT : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.TYPESCRIPT; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "Typescript"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "typescript"; } } #endregion #region 첫번쨰 라인 패턴 - FirstLinePattern /// <summary> /// 첫번쨰 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", new Dictionary<int, string> { { 0, ScopeName.Comment } } ), new LanguageRule ( @"(//.*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"'[^\n]*?'", new Dictionary<int, string> { { 0, ScopeName.String }, } ), new LanguageRule ( @"""[^\n]*?""", new Dictionary<int, string> { { 0, ScopeName.String }, } ), new LanguageRule ( @"\b(abstract|any|bool|boolean|break|byte|case|catch|char|class|const|constructor|continue|debugger|declare|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|long|module|native|new|number|null|package|private|protected|public|return|short|static|string|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|void|volatile|while|with)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "ts": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ VBDOTNET.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
namespace TestLibrary; /// <summary> /// VB.NET /// </summary> public class VBDOTNET : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.VBDOTNET; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "VB.NET"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "vb-net"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"('''[^\n]*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"((?:'|REM\s+).*?)\r?$", new Dictionary<int, string> { { 1, ScopeName.Comment } } ), new LanguageRule ( @"""(?:""""|[^""\n])*""", new Dictionary<int, string> { { 0, ScopeName.String } } ), new LanguageRule ( @"(?:\s|^)(\#End\sRegion|\#Region|\#Const|\#End\sExternalSource|\#ExternalSource|\#If|\#Else|\#End\sIf)(?:\s|\(|\r?$)", new Dictionary<int, string> { { 1, ScopeName.PreprocessorKeyword } } ), new LanguageRule ( @"(?i)\b(AddHandler|AddressOf|Aggregate|Alias|All|And|AndAlso|Ansi|Any|As|Ascending|(?<!<)Assembly|Auto|Average|Boolean|By|ByRef|Byte|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|CDec|CDbl|Char|CInt|Class|CLng|CObj|Const|Continue|Count|CShort|CSng|CStr|CType|Date|Decimal|Declare|Default|DefaultStyleSheet|Delegate|Descending|Dim|DirectCast|Distinct|Do|Double|Each|Else|ElseIf|End|Enum|Equals|Erase|Error|Event|Exit|Explicit|False|Finally|For|Friend|From|Function|Get|GetType|GoSub|GoTo|Group|Group|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Into|Is|IsNot|Join|Let|Lib|Like|Long|LongCount|Loop|Max|Me|Min|Mod|Module|MustInherit|MustOverride|My|MyBase|MyClass|Namespace|New|Next|Not|Nothing|NotInheritable|NotOverridable|(?<!\.)Object|Off|On|Option|Optional|Or|Order|OrElse|Overloads|Overridable|Overrides|ParamArray|Partial|Preserve|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|Select|Set|Shadows|Shared|Short|Single|Skip|Static|Step|Stop|String|Structure|Sub|Sum|SyncLock|Take|Then|Throw|To|True|Try|TypeOf|Unicode|Until|Variant|When|Where|While|With|WithEvents|WriteOnly|Xor|SByte|UInteger|ULong|UShort|Using|CSByte|CUInt|CULng|CUShort|Async|Await)\b", new Dictionary<int, string> { { 1, ScopeName.Keyword } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "vb.net": case "vbnet": case "vb": case "visualbasic": case "visual basic": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ XML.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
namespace TestLibrary; /// <summary> /// XML /// </summary> public class XML : ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get { return LanguageID.XML; } } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> public string Name { get { return "XML"; } } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> public string CSSClassName { get { return "xml"; } } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> public string FirstLinePattern { get { return null; } } #endregion #region 언어 규칙 리스트 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 /// </summary> public IList<LanguageRule> LanguageRuleList { get { return new List<LanguageRule> { new LanguageRule ( @"\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>", new Dictionary<int, string> { { 0, ScopeName.HtmlComment } } ), new LanguageRule ( @"(?i)(<!)(doctype)(?:\s+([a-z0-9]+))*(?:\s+("")([^\n]*?)(""))*(>)", new Dictionary<int, string> { { 1, ScopeName.XmlDelimiter }, { 2, ScopeName.XmlName }, { 3, ScopeName.XmlAttribute }, { 4, ScopeName.XmlAttributeQuotes }, { 5, ScopeName.XmlAttributeValue }, { 6, ScopeName.XmlAttributeQuotes }, { 7, ScopeName.XmlDelimiter } } ), new LanguageRule ( @"(?i)(<\?)(xml-stylesheet)((?:\s+[a-z0-9]+=""[^\n""]*"")*(?:\s+[a-z0-9]+=\'[^\n\']*\')*\s*?)(\?>)", new Dictionary<int, string> { { 1, ScopeName.XmlDelimiter }, { 2, ScopeName.XmlName }, { 3, ScopeName.XmlDocTag }, { 4, ScopeName.XmlDelimiter } } ), new LanguageRule ( @"(?i)(<\?)([a-z][a-z0-9-]*)(?:\s+([a-z0-9]+)(=)("")([^\n]*?)(""))*(?:\s+([a-z0-9]+)(=)(\')([^\n]*?)(\'))*\s*?(\?>)", new Dictionary<int, string> { { 1, ScopeName.XmlDelimiter }, { 2, ScopeName.XmlName }, { 3, ScopeName.XmlAttribute }, { 4, ScopeName.XmlDelimiter }, { 5, ScopeName.XmlAttributeQuotes }, { 6, ScopeName.XmlAttributeValue }, { 7, ScopeName.XmlAttributeQuotes }, { 8, ScopeName.XmlAttribute }, { 9, ScopeName.XmlDelimiter }, { 10, ScopeName.XmlAttributeQuotes }, { 11, ScopeName.XmlAttributeValue }, { 12, ScopeName.XmlAttributeQuotes }, { 13, ScopeName.XmlDelimiter } } ), new LanguageRule ( @"(?xi)(</?)(?: ([a-z][a-z0-9-]*)(:) )*([a-z][a-z0-9-_\.]*)(?:|[\s\n]+([a-z0-9-_\.:]+)[\s\n]*(=)[\s\n]*("")([^\n]+?)("")|[\s\n]+([a-z0-9-_\.:]+)[\s\n]*(=)[\s\n]*(')([^\n]+?)(')|[\s\n]+([a-z0-9-_\.:]+) )*[\s\n]*(/?>)", new Dictionary<int, string> { { 1, ScopeName.XmlDelimiter }, { 2, ScopeName.XmlName }, { 3, ScopeName.XmlDelimiter }, { 4, ScopeName.XmlName }, { 5, ScopeName.XmlAttribute }, { 6, ScopeName.XmlDelimiter }, { 7, ScopeName.XmlAttributeQuotes }, { 8, ScopeName.XmlAttributeValue }, { 9, ScopeName.XmlAttributeQuotes }, { 10, ScopeName.XmlAttribute }, { 11, ScopeName.XmlDelimiter }, { 12, ScopeName.XmlAttributeQuotes }, { 13, ScopeName.XmlAttributeValue }, { 14, ScopeName.XmlAttributeQuotes }, { 15, ScopeName.XmlAttribute }, { 16, ScopeName.XmlDelimiter } } ), new LanguageRule ( @"(?i)&[a-z0-9]+?;", new Dictionary<int, string> { { 0, ScopeName.XmlAttribute } } ), new LanguageRule ( @"(?s)(<!\[CDATA\[)(.*?)(\]\]>)", new Dictionary<int, string> { { 1, ScopeName.XmlDelimiter }, { 2, ScopeName.XmlCDataSection }, { 3, ScopeName.XmlDelimiter } } ) }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부</returns> public bool HasAlias(string languageID) { switch (languageID.ToLower()) { case "xaml": case "axml": return true; default: return false; } } #endregion #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns></returns> public override string ToString() { return Name; } #endregion } |
▶ ILanguageParser.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
namespace TestLibrary; /// <summary> /// 언어 파서 인터페이스 /// </summary> public interface ILanguageParser { //////////////////////////////////////////////////////////////////////////////////////////////////// Method #region 파싱하기 - Parse(sourceCode, language, parseHandler) /// <summary> /// 파싱하기 /// </summary> /// <param name="sourceCode">소스 코드</param> /// <param name="language">언어</param> /// <param name="parseHandler">파싱 핸들러</param> void Parse(string sourceCode, ILanguage language, Action<string, IList<Scope>> parseHandler); #endregion } |
▶ LanguageParser.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
using System.Text.RegularExpressions; namespace TestLibrary; /// <summary> /// 언어 파서 /// </summary> public class LanguageParser : ILanguageParser { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 언어 컴파일러 인터페이스 /// </summary> private readonly ILanguageCompiler languageCompiler; /// <summary> /// 언어 저장소 인터페이스 /// </summary> private readonly ILanguageRepository languageRepository; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - LanguageParser(languageCompiler, languageRepository) /// <summary> /// 생성자 /// </summary> /// <param name="languageCompiler">언어 컴파일러 인터페이스</param> /// <param name="languageRepository">언어 저장소 인터페이스</param> public LanguageParser(ILanguageCompiler languageCompiler, ILanguageRepository languageRepository) { this.languageCompiler = languageCompiler; this.languageRepository = languageRepository; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 캡처된 범위 인덱스 증가시키기 - IncreaseCapturedScopeIndex(capturedScopeList, indexDelta) /// <summary> /// 캡처된 범위 인덱스 증가시키기 /// </summary> /// <param name="capturedScopeList">캡처된 범위 리스트</param> /// <param name="indexDelta">인덱스 변동값</param> private static void IncreaseCapturedScopeIndex(IList<Scope> capturedScopeList, int indexDelta) { for(int i = 0; i < capturedScopeList.Count; i++) { Scope scope = capturedScopeList[i]; scope.Index += indexDelta; if(scope.ChildScopeList.Count > 0) { IncreaseCapturedScopeIndex(scope.ChildScopeList, indexDelta); } } } #endregion #region 중첩된 범위 컬렉션에 범위 추가하기 - AddScopeToNestedScopeCollection(scope, currentScope, treeCapturedScopeCollection) /// <summary> /// 중첩된 범위 컬렉션에 범위 추가하기 /// </summary> /// <param name="scope">범위</param> /// <param name="currentScope">현재 범위</param> /// <param name="treeCapturedScopeCollection">트리 캡처된 범위 컬렉션</param> private static void AddScopeToNestedScopeCollection(Scope scope, ref Scope currentScope, ICollection<Scope> treeCapturedScopeCollection) { if(scope.Index >= currentScope.Index && (scope.Index + scope.Length <= currentScope.Index + currentScope.Length)) { currentScope.AddChild(scope); currentScope = scope; } else { currentScope = currentScope.ParentScope; if(currentScope != null) { AddScopeToNestedScopeCollection(scope, ref currentScope, treeCapturedScopeCollection); } else { treeCapturedScopeCollection.Add(scope); } } } #endregion #region 트리 캡처된 범위 리스트 생성하기 - CreateTreeCapturedScopeList(capturedScopeList) /// <summary> /// 트리 캡처된 범위 리스트 생성하기 /// </summary> /// <param name="capturedScopeList">캡처된 범위 리스트</param> /// <returns>트리 캡처된 범위 리스트</returns> private static List<Scope> CreateTreeCapturedScopeList(IList<Scope> capturedScopeList) { capturedScopeList.SortStable((x, y) => x.Index.CompareTo(y.Index)); List<Scope> treeCapturedScopeList = new List<Scope>(capturedScopeList.Count); Scope currentScope = null; foreach(Scope capturedScope in capturedScopeList) { if(currentScope == null) { treeCapturedScopeList.Add(capturedScope); currentScope = capturedScope; continue; } AddScopeToNestedScopeCollection(capturedScope, ref currentScope, treeCapturedScopeList); } return treeCapturedScopeList; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Public #region 파싱하기 - Parse(sourceCode, language, parseHandler) /// <summary> /// 파싱하기 /// </summary> /// <param name="sourceCode">소스 코드</param> /// <param name="language">언어</param> /// <param name="parseHandler">파싱 핸들러</param> public void Parse(string sourceCode, ILanguage language, Action<string, IList<Scope>> parseHandler) { if(string.IsNullOrEmpty(sourceCode)) { return; } CompiledLanguage compiledLanguage = this.languageCompiler.Compile(language); Parse(sourceCode, compiledLanguage, parseHandler); } #endregion //////////////////////////////////////////////////////////////////////////////// Private #region 중첩된 언어용 캡처된 범위 추가하기 - AppendCapturedScopeForNestedLanguage(capture, offset, nestedLanguageID, capturedScoleCollection) /// <summary> /// 중첩된 언어용 캡처된 범위 추가하기 /// </summary> /// <param name="capture">캡처</param> /// <param name="offset">오프셋</param> /// <param name="nestedLanguageID">중첩 언어 ID</param> /// <param name="capturedScoleCollection">캡처된 범위 컬렉션</param> private void AppendCapturedScopeForNestedLanguage(Capture capture, int offset, string nestedLanguageID, ICollection<Scope> capturedScoleCollection) { ILanguage nestedLanguage = languageRepository.FindByID(nestedLanguageID); if(nestedLanguage == null) { throw new InvalidOperationException("The nested language was not found in the language repository."); } else { CompiledLanguage nestedCompiledLanguage = languageCompiler.Compile(nestedLanguage); Match match = nestedCompiledLanguage.Regex.Match(capture.Value, 0, capture.Value.Length); if(!match.Success) { return; } else { while(match.Success) { List<Scope> capturedScopeList = GetCapturedScopeList(match, 0, nestedCompiledLanguage); List<Scope> treeCapturedScopeList = CreateTreeCapturedScopeList(capturedScopeList); foreach(Scope treeCapturedScope in treeCapturedScopeList) { IncreaseCapturedScopeIndex(treeCapturedScopeList, offset); capturedScoleCollection.Add(treeCapturedScope); } match = match.NextMatch(); } } } } #endregion #region 정규식 캡처용 캡처 스타일 추가하기 - AppendCapturedStylesForRegexCapture(capture, currentIndex, styleName, capturedScopeCollection) /// <summary> /// 정규식 캡처용 캡처 스타일 추가하기 /// </summary> /// <param name="capture">캡처</param> /// <param name="currentIndex">현재 인덱스</param> /// <param name="styleName">스타일명</param> /// <param name="capturedScopeCollection">캡처 범위 컬렉션</param> private void AppendCapturedStylesForRegexCapture(Capture capture, int currentIndex, string styleName, ICollection<Scope> capturedScopeCollection) { if(styleName.StartsWith(ScopeName.LanguagePrefix)) { string nestedGrammarID = styleName.Substring(1); AppendCapturedScopeForNestedLanguage(capture, capture.Index - currentIndex, nestedGrammarID, capturedScopeCollection); } else { capturedScopeCollection.Add(new Scope(styleName, capture.Index - currentIndex, capture.Length)); } } #endregion #region 캡처 범위 리스트 구하기 - GetCapturedScopeList(match, currentIndex, compiledLanguage) /// <summary> /// 캡처 범위 리스트 구하기 /// </summary> /// <param name="match">매치</param> /// <param name="currentIndex">현재 인덱스</param> /// <param name="compiledLanguage">컴파일된 언어</param> /// <returns>캡처된 범위 리스트</returns> private List<Scope> GetCapturedScopeList(Match match, int currentIndex, CompiledLanguage compiledLanguage) { List<Scope> scopeList = new List<Scope>(); for(int i = 0; i < match.Groups.Count; i++) { Group group = match.Groups[i]; if(group.Length > 0 && i < compiledLanguage.CaptureList.Count) { string styleName = compiledLanguage.CaptureList[i]; if(!string.IsNullOrEmpty(styleName)) { foreach(Capture capture in group.Captures) { AppendCapturedStylesForRegexCapture(capture, currentIndex, styleName, scopeList); } } } } return scopeList; } #endregion #region 파싱하기 - Parse(sourceCode, compiledLanguage, parseHandler) /// <summary> /// 파싱하기 /// </summary> /// <param name="sourceCode">소스 코드</param> /// <param name="compiledLanguage">컴파일된 언어</param> /// <param name="parseHandler">파싱 핸들러</param> private void Parse(string sourceCode, CompiledLanguage compiledLanguage, Action<string, IList<Scope>> parseHandler) { Match match = compiledLanguage.Regex.Match(sourceCode); if(!match.Success) { parseHandler(sourceCode, new List<Scope>()); } else { int currentIndex = 0; while(match.Success) { string sourceCodeBeforeMatch = sourceCode.Substring(currentIndex, match.Index - currentIndex); if(!string.IsNullOrEmpty(sourceCodeBeforeMatch)) { parseHandler(sourceCodeBeforeMatch, new List<Scope>()); } string matchedSourceCode = sourceCode.Substring(match.Index, match.Length); if(!string.IsNullOrEmpty(matchedSourceCode)) { List<Scope> capturedStylesForMatchedFragment = GetCapturedScopeList(match, match.Index, compiledLanguage); List<Scope> capturedStyleTree = CreateTreeCapturedScopeList(capturedStylesForMatchedFragment); parseHandler(matchedSourceCode, capturedStyleTree); } currentIndex = match.Index + match.Length; match = match.NextMatch(); } string sourceCodeAfterAllMatches = sourceCode.Substring(currentIndex); if(!string.IsNullOrEmpty(sourceCodeAfterAllMatches)) { parseHandler(sourceCodeAfterAllMatches, new List<Scope>()); } } } #endregion } |
▶ Scope.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
namespace TestLibrary; /// <summary> /// 범위 /// </summary> public class Scope { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 범위명 - Name /// <summary> /// 범위명 /// </summary> public string Name { get; set; } #endregion #region 인덱스 - Index /// <summary> /// 인덱스 /// </summary> public int Index { get; set; } #endregion #region 길이 - Length /// <summary> /// 길이 /// </summary> public int Length { get; set; } #endregion #region 부모 범위 - ParentScope /// <summary> /// 부모 범위 /// </summary> public Scope ParentScope { get; set; } #endregion #region 자식 범위 리스트 - ChildScopeList /// <summary> /// 자식 범위 리스트 /// </summary> public IList<Scope> ChildScopeList { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - Scope(name, index, length) /// <summary> /// 생성자 /// </summary> /// <param name="name">범위명</param> /// <param name="index">인덱스</param> /// <param name="length">길이</param> public Scope(string name, int index, int length) { ArgumentHelper.EnsureIsNotNullAndNotEmpty(name, "name"); Name = name; Index = index; Length = length; ChildScopeList = new List<Scope>(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 자식 추가하기 - AddChild(childScope) /// <summary> /// 자식 추가하기 /// </summary> /// <param name="childScope">자식 범위</param> public void AddChild(Scope childScope) { if(childScope.ParentScope != null) { throw new InvalidOperationException("The child scope already has a parent."); } childScope.ParentScope = this; ChildScopeList.Add(childScope); } #endregion } |
▶ Style.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
namespace TestLibrary; /// <summary> /// 스타일 /// </summary> public class Style { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 배경색 - Background /// <summary> /// 배경색 /// </summary> public string Background { get; set; } #endregion #region 전경색 - Foreground /// <summary> /// 전경색 /// </summary> public string Foreground { get; set; } #endregion #region 범위명 - ScopeName /// <summary> /// 범위명 /// </summary> public string ScopeName { get; set; } #endregion #region 참조명 - ReferenceName /// <summary> /// 참조명 /// </summary> public string ReferenceName { get; set; } #endregion #region 이탤릭체 여부 - Italic /// <summary> /// 이탤릭체 여부 /// </summary> public bool Italic { get; set; } #endregion #region 볼드체 여부 - Bold /// <summary> /// 볼드체 여부 /// </summary> public bool Bold { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - Style(scopeName) /// <summary> /// 생성자 /// </summary> /// <param name="scopeName">범위명</param> public Style(string scopeName) { ArgumentHelper.EnsureIsNotNullAndNotEmpty(scopeName, "scopeName"); ScopeName = scopeName; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { return ScopeName ?? string.Empty; } #endregion } |
▶ StyleDictionary.cs
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 |
using System.Collections.ObjectModel; namespace TestLibrary; /// <summary> /// 스타일 딕셔너리 /// </summary> public partial class StyleDictionary : KeyedCollection<string, Style> { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field public const string Blue = "#ff0000ff"; public const string White = "#ffffffff"; public const string Black = "#ff000000"; public const string DullRed = "#ffa31515"; public const string Yellow = "#ffffff00"; public const string Green = "#ff008000"; public const string PowderBlue = "#ffb0e0e6"; public const string Teal = "#ff008080"; public const string Gray = "#ff808080"; public const string Navy = "#ff000080"; public const string OrangeRed = "#ffff4500"; public const string Purple = "#ff800080"; public const string Red = "#ffff0000"; public const string MediumTurqoise = "#ff48d1cc"; public const string Magenta = "#ffff00ff"; public const string OliveDrab = "#ff6b8e23"; public const string DarkOliveGreen = "#ff556b2f"; public const string DarkCyan = "#ff008b8b"; public const string DarkOrange = "#ffff8700"; public const string BrightGreen = "#ff00d700"; public const string BrightPurple = "#ffaf87ff"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 항목용 키 구하기 - GetKeyForItem(style) /// <summary> /// 항목용 키 구하기 /// </summary> /// <param name="style">스타일</param> /// <returns>항목용 키</returns> protected override string GetKeyForItem(Style style) { return style.ScopeName; } #endregion } |
▶ StyleDictionary.DefaultDark.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
namespace TestLibrary; /// <summary> /// 스타일 딕셔너리 /// </summary> public partial class StyleDictionary { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field private const string VSDarkBackground = "#ff1e1e1e"; private const string VSDarkPlainText = "#ffdadada"; private const string VSDarkXMLDelimeter = "#ff808080"; private const string VSDarkXMLName = "#ffe6e6e6"; private const string VSDarkXMLAttribute = "#ff92caf4"; private const string VSDarkXAMLCData = "#ffc0d088"; private const string VSDarkXMLComment = "#ff608b4e"; private const string VSDarkComment = "#ff57a64a"; private const string VSDarkKeyword = "#ff569cd6"; private const string VSDarkGray = "#ff9b9b9b"; private const string VSDarkNumber = "#ffb5cea8"; private const string VSDarkClass = "#ff4ec9b0"; private const string VSDarkString = "#ffd69d85"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 디폴트 DARK - DefaultDark /// <summary> /// 디폴트 DARK /// </summary> public static StyleDictionary DefaultDark { get { return new StyleDictionary { new Style(ScopeName.PlainText) { Foreground = VSDarkPlainText, Background = VSDarkBackground, ReferenceName = "plainText" }, new Style(ScopeName.HtmlServerSideScript) { Background = Yellow, ReferenceName = "htmlServerSideScript" }, new Style(ScopeName.HtmlComment) { Foreground = VSDarkComment, ReferenceName = "htmlComment" }, new Style(ScopeName.HtmlTagDelimiter) { Foreground = VSDarkKeyword, ReferenceName = "htmlTagDelimiter" }, new Style(ScopeName.HtmlElementName) { Foreground = DullRed, ReferenceName = "htmlElementName" }, new Style(ScopeName.HtmlAttributeName) { Foreground = Red, ReferenceName = "htmlAttributeName" }, new Style(ScopeName.HtmlAttributeValue) { Foreground = VSDarkKeyword, ReferenceName = "htmlAttributeValue" }, new Style(ScopeName.HtmlOperator) { Foreground = VSDarkKeyword, ReferenceName = "htmlOperator" }, new Style(ScopeName.Comment) { Foreground = VSDarkComment, ReferenceName = "comment" }, new Style(ScopeName.XmlDocTag) { Foreground = VSDarkXMLComment, ReferenceName = "xmlDocTag" }, new Style(ScopeName.XmlDocComment) { Foreground = VSDarkXMLComment, ReferenceName = "xmlDocComment" }, new Style(ScopeName.String) { Foreground = VSDarkString, ReferenceName = "string" }, new Style(ScopeName.StringCSharpVerbatim) { Foreground = VSDarkString, ReferenceName = "stringCSharpVerbatim" }, new Style(ScopeName.Keyword) { Foreground = VSDarkKeyword, ReferenceName = "keyword" }, new Style(ScopeName.PreprocessorKeyword) { Foreground = VSDarkKeyword, ReferenceName = "preprocessorKeyword" }, new Style(ScopeName.HtmlEntity) { Foreground = Red, ReferenceName = "htmlEntity" }, new Style(ScopeName.JsonKey) { Foreground = DarkOrange, ReferenceName = "jsonKey" }, new Style(ScopeName.JsonString) { Foreground = DarkCyan, ReferenceName = "jsonString" }, new Style(ScopeName.JsonNumber) { Foreground = BrightGreen, ReferenceName = "jsonNumber" }, new Style(ScopeName.JsonConst) { Foreground = BrightPurple, ReferenceName = "jsonConst" }, new Style(ScopeName.XmlAttribute) { Foreground = VSDarkXMLAttribute, ReferenceName = "xmlAttribute" }, new Style(ScopeName.XmlAttributeQuotes) { Foreground = VSDarkKeyword, ReferenceName = "xmlAttributeQuotes" }, new Style(ScopeName.XmlAttributeValue) { Foreground = VSDarkKeyword, ReferenceName = "xmlAttributeValue" }, new Style(ScopeName.XmlCDataSection) { Foreground = VSDarkXAMLCData, ReferenceName = "xmlCDataSection" }, new Style(ScopeName.XmlComment) { Foreground = VSDarkComment, ReferenceName = "xmlComment" }, new Style(ScopeName.XmlDelimiter) { Foreground = VSDarkXMLDelimeter, ReferenceName = "xmlDelimiter" }, new Style(ScopeName.XmlName) { Foreground = VSDarkXMLName, ReferenceName = "xmlName" }, new Style(ScopeName.ClassName) { Foreground = VSDarkClass, ReferenceName = "className" }, new Style(ScopeName.CssSelector) { Foreground = DullRed, ReferenceName = "cssSelector" }, new Style(ScopeName.CssPropertyName) { Foreground = Red, ReferenceName = "cssPropertyName" }, new Style(ScopeName.CssPropertyValue) { Foreground = VSDarkKeyword, ReferenceName = "cssPropertyValue" }, new Style(ScopeName.SqlSystemFunction) { Foreground = Magenta, ReferenceName = "sqlSystemFunction" }, new Style(ScopeName.PowerShellAttribute) { Foreground = PowderBlue, ReferenceName = "powershellAttribute" }, new Style(ScopeName.PowerShellOperator) { Foreground = VSDarkGray, ReferenceName = "powershellOperator" }, new Style(ScopeName.PowerShellType) { Foreground = Teal, ReferenceName = "powershellType" }, new Style(ScopeName.PowerShellVariable) { Foreground = OrangeRed, ReferenceName = "powershellVariable" }, new Style(ScopeName.PowerShellCommand) { Foreground = Yellow, ReferenceName = "powershellCommand" }, new Style(ScopeName.PowerShellParameter) { Foreground = VSDarkGray, ReferenceName = "powershellParameter" }, new Style(ScopeName.Type) { Foreground = Teal, ReferenceName = "type" }, new Style(ScopeName.TypeVariable) { Foreground = Teal, Italic = true, ReferenceName = "typeVariable" }, new Style(ScopeName.NameSpace) { Foreground = Navy, ReferenceName = "namespace" }, new Style(ScopeName.Constructor) { Foreground = Purple, ReferenceName = "constructor" }, new Style(ScopeName.Predefined) { Foreground = Navy, ReferenceName = "predefined" }, new Style(ScopeName.PseudoKeyword) { Foreground = Navy, ReferenceName = "pseudoKeyword" }, new Style(ScopeName.StringEscape) { Foreground = VSDarkGray, ReferenceName = "stringEscape" }, new Style(ScopeName.ControlKeyword) { Foreground = VSDarkKeyword, ReferenceName = "controlKeyword" }, new Style(ScopeName.Number) { ReferenceName = "number", Foreground = VSDarkNumber }, new Style(ScopeName.Operator) { ReferenceName = "operator" }, new Style(ScopeName.Delimiter) { ReferenceName = "delimiter" }, new Style(ScopeName.MarkdownHeader) { Foreground = VSDarkKeyword, Bold = true, ReferenceName = "markdownHeader" }, new Style(ScopeName.MarkdownCode) { Foreground = VSDarkString, ReferenceName = "markdownCode" }, new Style(ScopeName.MarkdownListItem) { Bold = true, ReferenceName = "markdownListItem" }, new Style(ScopeName.MarkdownEmph) { Italic = true, ReferenceName = "italic" }, new Style(ScopeName.MarkdownBold) { Bold = true, ReferenceName = "bold" }, new Style(ScopeName.BuiltinFunction) { Foreground = OliveDrab, Bold = true, ReferenceName = "builtinFunction" }, new Style(ScopeName.BuiltinValue) { Foreground = DarkOliveGreen, Bold = true, ReferenceName = "builtinValue" }, new Style(ScopeName.Attribute) { Foreground = DarkCyan, Italic = true, ReferenceName = "attribute" }, new Style(ScopeName.SpecialCharacter) { ReferenceName = "specialChar" }, }; } } #endregion } |
▶ StyleDictionary.DefaultLight.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
namespace TestLibrary; /// <summary> /// 스타일 딕셔너리 /// </summary> public partial class StyleDictionary { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 디폴트 LIGHT - DefaultLight /// <summary> /// 디폴트 LIGHT /// </summary> public static StyleDictionary DefaultLight { get { return new StyleDictionary { new Style(ScopeName.PlainText) { Foreground = Black, Background = White, ReferenceName = "plainText" }, new Style(ScopeName.HtmlServerSideScript) { Background = Yellow, ReferenceName = "htmlServerSideScript" }, new Style(ScopeName.HtmlComment) { Foreground = Green, ReferenceName = "htmlComment" }, new Style(ScopeName.HtmlTagDelimiter) { Foreground = Blue, ReferenceName = "htmlTagDelimiter" }, new Style(ScopeName.HtmlElementName) { Foreground = DullRed, ReferenceName = "htmlElementName" }, new Style(ScopeName.HtmlAttributeName) { Foreground = Red, ReferenceName = "htmlAttributeName" }, new Style(ScopeName.HtmlAttributeValue) { Foreground = Blue, ReferenceName = "htmlAttributeValue" }, new Style(ScopeName.HtmlOperator) { Foreground = Blue, ReferenceName = "htmlOperator" }, new Style(ScopeName.Comment) { Foreground = Green, ReferenceName = "comment" }, new Style(ScopeName.XmlDocTag) { Foreground = Gray, ReferenceName = "xmlDocTag" }, new Style(ScopeName.XmlDocComment) { Foreground = Green, ReferenceName = "xmlDocComment" }, new Style(ScopeName.String) { Foreground = DullRed, ReferenceName = "string" }, new Style(ScopeName.StringCSharpVerbatim) { Foreground = DullRed, ReferenceName = "stringCSharpVerbatim" }, new Style(ScopeName.Keyword) { Foreground = Blue, ReferenceName = "keyword" }, new Style(ScopeName.PreprocessorKeyword) { Foreground = Blue, ReferenceName = "preprocessorKeyword" }, new Style(ScopeName.HtmlEntity) { Foreground = Red, ReferenceName = "htmlEntity" }, new Style(ScopeName.JsonKey) { Foreground = DarkOrange, ReferenceName = "jsonKey" }, new Style(ScopeName.JsonString) { Foreground = DarkCyan, ReferenceName = "jsonString" }, new Style(ScopeName.JsonNumber) { Foreground = BrightGreen, ReferenceName = "jsonNumber" }, new Style(ScopeName.JsonConst) { Foreground = BrightPurple, ReferenceName = "jsonConst" }, new Style(ScopeName.XmlAttribute) { Foreground = Red, ReferenceName = "xmlAttribute" }, new Style(ScopeName.XmlAttributeQuotes) { Foreground = Black, ReferenceName = "xmlAttributeQuotes" }, new Style(ScopeName.XmlAttributeValue) { Foreground = Blue, ReferenceName = "xmlAttributeValue" }, new Style(ScopeName.XmlCDataSection) { Foreground = Gray, ReferenceName = "xmlCDataSection" }, new Style(ScopeName.XmlComment) { Foreground = Green, ReferenceName = "xmlComment" }, new Style(ScopeName.XmlDelimiter) { Foreground = Blue, ReferenceName = "xmlDelimiter" }, new Style(ScopeName.XmlName) { Foreground = DullRed, ReferenceName = "xmlName" }, new Style(ScopeName.ClassName) { Foreground = MediumTurqoise, ReferenceName = "className" }, new Style(ScopeName.CssSelector) { Foreground = DullRed, ReferenceName = "cssSelector" }, new Style(ScopeName.CssPropertyName) { Foreground = Red, ReferenceName = "cssPropertyName" }, new Style(ScopeName.CssPropertyValue) { Foreground = Blue, ReferenceName = "cssPropertyValue" }, new Style(ScopeName.SqlSystemFunction) { Foreground = Magenta, ReferenceName = "sqlSystemFunction" }, new Style(ScopeName.PowerShellAttribute) { Foreground = PowderBlue, ReferenceName = "powershellAttribute" }, new Style(ScopeName.PowerShellOperator) { Foreground = Gray, ReferenceName = "powershellOperator" }, new Style(ScopeName.PowerShellType) { Foreground = Teal, ReferenceName = "powershellType" }, new Style(ScopeName.PowerShellVariable) { Foreground = OrangeRed, ReferenceName = "powershellVariable" }, new Style(ScopeName.PowerShellCommand) { Foreground = Navy, ReferenceName = "powershellCommand" }, new Style(ScopeName.PowerShellParameter) { Foreground = Gray, ReferenceName = "powershellParameter" }, new Style(ScopeName.Type) { Foreground = Teal, ReferenceName = "type" }, new Style(ScopeName.TypeVariable) { Foreground = Teal, Italic = true, ReferenceName = "typeVariable" }, new Style(ScopeName.NameSpace) { Foreground = Navy, ReferenceName = "namespace" }, new Style(ScopeName.Constructor) { Foreground = Purple, ReferenceName = "constructor" }, new Style(ScopeName.Predefined) { Foreground = Navy, ReferenceName = "predefined" }, new Style(ScopeName.PseudoKeyword) { Foreground = Navy, ReferenceName = "pseudoKeyword" }, new Style(ScopeName.StringEscape) { Foreground = Gray, ReferenceName = "stringEscape" }, new Style(ScopeName.ControlKeyword) { Foreground = Blue, ReferenceName = "controlKeyword" }, new Style(ScopeName.Number) { ReferenceName = "number" }, new Style(ScopeName.Operator) { ReferenceName = "operator" }, new Style(ScopeName.Delimiter) { ReferenceName = "delimiter" }, new Style(ScopeName.MarkdownHeader) { Foreground = Blue, Bold = true, ReferenceName = "markdownHeader" }, new Style(ScopeName.MarkdownCode) { Foreground = Teal, ReferenceName = "markdownCode" }, new Style(ScopeName.MarkdownListItem) { Bold = true, ReferenceName = "markdownListItem" }, new Style(ScopeName.MarkdownEmph) { Italic = true, ReferenceName = "italic" }, new Style(ScopeName.MarkdownBold) { Bold = true, ReferenceName = "bold" }, new Style(ScopeName.BuiltinFunction) { Foreground = OliveDrab, Bold = true, ReferenceName = "builtinFunction" }, new Style(ScopeName.BuiltinValue) { Foreground = DarkOliveGreen, Bold = true, ReferenceName = "builtinValue" }, new Style(ScopeName.Attribute) { Foreground = DarkCyan, Italic = true, ReferenceName = "attribute" }, new Style(ScopeName.SpecialCharacter) { ReferenceName = "specialChar" }, }; } } #endregion } |
▶ CodeColorizerBase.cs
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 |
namespace TestLibrary; /// <summary> /// 코드 색상기 베이스 /// </summary> public abstract class CodeColorizerBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 스타일 딕셔너리 /// </summary> public readonly StyleDictionary StyleDictionary; #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region Field /// <summary> /// 언어 파서 인터페이스 /// </summary> protected readonly ILanguageParser languageParser; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CodeColorizerBase(styleDictionary, languageParser) /// <summary> /// 생성자 /// </summary> /// <param name="styleDictionary">스타일 딕셔너리</param> /// <param name="languageParser">언어 파서</param> public CodeColorizerBase(StyleDictionary styleDictionary, ILanguageParser languageParser) { this.languageParser = languageParser ?? new LanguageParser(new LanguageCompiler(LanguageHelper.CompiledLanguageDictionary, LanguageHelper.CompileReaderWriterLockSlim), LanguageHelper.LanguageRepository); StyleDictionary = styleDictionary ?? StyleDictionary.DefaultLight; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 쓰기 - Write(parsedSourceCode, scopeList) /// <summary> /// 쓰기 /// </summary> /// <param name="parsedSourceCode">파싱된 소스 코드</param> /// <param name="scopeList">범위 리스트</param> protected abstract void Write(string parsedSourceCode, IList<Scope> scopeList); #endregion } |
▶ HTMLClassFormatter.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
using System.Net; using System.Text; namespace TestLibrary; /// <summary> /// HTML 클래스 포매터 /// </summary> public class HTMLClassFormatter : CodeColorizerBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 텍스트 라이터 - Writer /// <summary> /// 텍스트 라이터 /// </summary> private TextWriter Writer { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - HTMLClassFormatter(styleDictionary, languageParser) /// <summary> /// 생성자 /// </summary> /// <param name="styleDictionary">스타일 딕셔너리</param> /// <param name="languageParser">언어 파서</param> public HTMLClassFormatter(StyleDictionary styleDictionary = null, ILanguageParser languageParser = null) : base(styleDictionary, languageParser) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region HTML 문자열 구하기 - GetHTMLString(sourceCode, language) /// <summary> /// HTML 문자열 구하기 /// </summary> /// <param name="sourceCode">소스 코드</param> /// <param name="language">언어 인터페이스</param> /// <returns>HTML 문자열</returns> public string GetHTMLString(string sourceCode, ILanguage language) { StringBuilder stringBuilder = new StringBuilder(sourceCode.Length * 2); using(TextWriter writer = new StringWriter(stringBuilder)) { Writer = writer; WriteHeader(language); this.languageParser.Parse(sourceCode, language, (parsedSourceCode, scopeList) => Write(parsedSourceCode, scopeList)); WriteFooter(language); writer.Flush(); } return stringBuilder.ToString(); } #endregion #region CSS 문자열 구하기 - GetCSSString() /// <summary> /// CSS 문자열 구하기 /// </summary> /// <returns>CSS 문자열</returns> public string GetCSSString() { StringBuilder stringBuilder = new StringBuilder(); Style plainTextStyle = StyleDictionary[ScopeName.PlainText]; if(!string.IsNullOrWhiteSpace(plainTextStyle?.Background)) { stringBuilder.Append($"body{{background-color:{plainTextStyle.Background};}}"); } foreach(Style style in StyleDictionary) { stringBuilder.Append($" .{style.ReferenceName}{{"); if(!string.IsNullOrWhiteSpace(style.Foreground)) { stringBuilder.Append($"color:{style.Foreground.ToHTMLColorString()};"); } if(!string.IsNullOrWhiteSpace(style.Background)) { stringBuilder.Append($"color:{style.Background.ToHTMLColorString()};"); } if(style.Italic) { stringBuilder.Append("font-style: italic;"); } if(style.Bold) { stringBuilder.Append("font-weight: bold;"); } stringBuilder.Append("}"); } return stringBuilder.ToString(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 쓰기 - Write(parsedSourceCode, scopeList) /// <summary> /// 쓰기 /// </summary> /// <param name="parsedSourceCode">파싱된 소스 코드</param> /// <param name="scopeList">범위 리스트</param> protected override void Write(string parsedSourceCode, IList<Scope> scopeList) { List<TextInsertion> textInsertionList = new List<TextInsertion>(); foreach(Scope scope in scopeList) { GetStyleInsertionsForCapturedStyle(scope, textInsertionList); } textInsertionList.SortStable((x, y) => x.Index.CompareTo(y.Index)); int offset = 0; foreach(TextInsertion textInsertion in textInsertionList) { Writer.Write(WebUtility.HtmlEncode(parsedSourceCode.Substring(offset, textInsertion.Index - offset))); if(string.IsNullOrEmpty(textInsertion.Text)) { BuildSpanForCapturedStyle(textInsertion.Scope); } else { Writer.Write(textInsertion.Text); } offset = textInsertion.Index; } Writer.Write(WebUtility.HtmlEncode(parsedSourceCode.Substring(offset))); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 엘리먼트 시작 태그 쓰기 - WriteElementStartTag(elementName, cssClassName) /// <summary> /// 엘리먼트 시작 태그 쓰기 /// </summary> /// <param name="elementName">엘리먼트명</param> /// <param name="cssClassName">CSS 클래스명</param> private void WriteElementStartTag(string elementName, string cssClassName) { Writer.Write("<{0}", elementName); if(!string.IsNullOrEmpty(cssClassName)) { Writer.Write(" class=\"{0}\"", cssClassName); } Writer.Write(">"); } #endregion #region 엘리먼트 시작 태그 쓰기 - WriteElementStartTag(elementName) /// <summary> /// 엘리먼트 시작 태그 쓰기 /// </summary> /// <param name="elementName">엘리먼트명</param> private void WriteElementStartTag(string elementName) { WriteElementStartTag(elementName, ""); } #endregion #region 머리말 PREV 시작 태그 쓰기 - WriteHeaderPreStartTag() /// <summary> /// 머리말 PREV 시작 태그 쓰기 /// </summary> private void WriteHeaderPreStartTag() { WriteElementStartTag("pre"); } #endregion #region 머리말 DIV 시작 태그 쓰기 - WriteHeaderDivStart(language) /// <summary> /// 머리말 DIV 시작 태그 쓰기 /// </summary> /// <param name="language">언어 인터페이스</param> private void WriteHeaderDivStart(ILanguage language) { WriteElementStartTag("div", language.CSSClassName); } #endregion #region 엘리먼트 종료 태그 쓰기 - WriteElementEndTag(elementName) /// <summary> /// 엘리먼트 종료 태그 쓰기 /// </summary> /// <param name="elementName">엘리먼트명</param> private void WriteElementEndTag(string elementName) { Writer.Write("</{0}>", elementName); } #endregion #region 머리말 DIV 종료 태그 쓰기 - WriteHeaderDivEndTag() /// <summary> /// 머리말 DIV 종료 태그 쓰기 /// </summary> private void WriteHeaderDivEndTag() { WriteElementEndTag("div"); } #endregion #region 머리말 PRE 종료 태그 쓰기 - WriteHeaderPreEndTag() /// <summary> /// 머리말 PRE 종료 태그 쓰기 /// </summary> private void WriteHeaderPreEndTag() { WriteElementEndTag("pre"); } #endregion #region 머리말 쓰기 - WriteHeader(language) /// <summary> /// 머리말 쓰기 /// </summary> /// <param name="language">언어 인터페이스</param> private void WriteHeader(ILanguage language) { ArgumentHelper.EnsureIsNotNull(language, "language"); WriteHeaderDivStart(language); WriteHeaderPreStartTag(); Writer.WriteLine(); } #endregion #region 꼬리말 쓰기 - WriteFooter(language) /// <summary> /// 꼬리말 쓰기 /// </summary> /// <param name="language">언어 인터페이스</param> private void WriteFooter(ILanguage language) { ArgumentHelper.EnsureIsNotNull(language, "language"); Writer.WriteLine(); WriteHeaderPreEndTag(); WriteHeaderDivEndTag(); } #endregion #region 캡처 스타일용 스타일 삽입 컬렉션 구하기 - GetStyleInsertionsForCapturedStyle(scope, textInsertionCollection) /// <summary> /// 캡처 스타일용 스타일 삽입 컬렉션 구하기 /// </summary> /// <param name="scope">범위</param> /// <param name="textInsertionCollection">텍스트 삽입 컬렉션</param> private static void GetStyleInsertionsForCapturedStyle(Scope scope, ICollection<TextInsertion> textInsertionCollection) { textInsertionCollection.Add ( new TextInsertion { Index = scope.Index, Scope = scope } ); foreach(Scope childScope in scope.ChildScopeList) { GetStyleInsertionsForCapturedStyle(childScope, textInsertionCollection); } textInsertionCollection.Add ( new TextInsertion { Index = scope.Index + scope.Length, Text = "</span>" } ); } #endregion #region 캡처 스타일용 SPAN 만들기 - BuildSpanForCapturedStyle(scope) /// <summary> /// 캡처 스타일용 SPAN 만들기 /// </summary> /// <param name="scope">범위</param> private void BuildSpanForCapturedStyle(Scope scope) { string cssClassName = ""; if(StyleDictionary.Contains(scope.Name)) { Style style = StyleDictionary[scope.Name]; cssClassName = style.ReferenceName; } WriteElementStartTag("span", cssClassName); } #endregion } |
▶ HTMLFormatter.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
using System.Net; using System.Text; namespace TestLibrary; /// <summary> /// HTML 포매터 /// </summary> public class HTMLFormatter : CodeColorizerBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 라이터 - Writer /// <summary> /// 라이터 /// </summary> private TextWriter Writer { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - HTMLFormatter(styleDictionary, languageParser) /// <summary> /// 생성자 /// </summary> /// <param name="styleDictionary">스타일 딕셔너리</param> /// <param name="languageParser">언어 파서</param> public HTMLFormatter(StyleDictionary styleDictionary = null, ILanguageParser languageParser = null) : base(styleDictionary, languageParser) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region HTML 문자열 구하기 - GetHTMLString(sourceCode, language) /// <summary> /// HTML 문자열 구하기 /// </summary> /// <param name="sourceCode">소스 코드</param> /// <param name="language">언어 인터페이스</param> /// <returns>HTML 문자열</returns> public string GetHTMLString(string sourceCode, ILanguage language) { StringBuilder stringBuilder = new StringBuilder(sourceCode.Length * 2); using(TextWriter writer = new StringWriter(stringBuilder)) { Writer = writer; WriteHeader(language); languageParser.Parse(sourceCode, language, (parsedSourceCode, scopeList) => Write(parsedSourceCode, scopeList)); WriteFooter(language); writer.Flush(); } return stringBuilder.ToString(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 쓰기 - Write(parsedSourceCode, scopeList) /// <summary> /// 쓰기 /// </summary> /// <param name="parsedSourceCode">파싱된 소스 코드</param> /// <param name="scopeList">범위 리스트</param> protected override void Write(string parsedSourceCode, IList<Scope> scopeList) { List<TextInsertion> textInsertionList = new List<TextInsertion>(); foreach(Scope scope in scopeList) { GetStyleInsertionsForCapturedStyle(scope, textInsertionList); } textInsertionList.SortStable((x, y) => x.Index.CompareTo(y.Index)); int offset = 0; foreach(TextInsertion textInsertion in textInsertionList) { string text = parsedSourceCode.Substring(offset, textInsertion.Index - offset); Writer.Write(WebUtility.HtmlEncode(text)); if(string.IsNullOrEmpty(textInsertion.Text)) { BuildSpanForCapturedStyle(textInsertion.Scope); } else { Writer.Write(textInsertion.Text); } offset = textInsertion.Index; } Writer.Write(WebUtility.HtmlEncode(parsedSourceCode.Substring(offset))); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 엘리먼트 시작 태그 쓰기 - WriteElementStartTag(elementName, foreground, background, italic, bold) /// <summary> /// 엘리먼트 시작 태그 쓰기 /// </summary> /// <param name="elementName">엘리먼트명</param> /// <param name="foreground">전경색</param> /// <param name="background">배경색</param> /// <param name="italic">이탤릭체 여부</param> /// <param name="bold">볼드체 여부</param> private void WriteElementStartTag(string elementName, string foreground = null, string background = null, bool italic = false, bool bold = false) { Writer.Write("<{0}", elementName); if(!string.IsNullOrWhiteSpace(foreground) || !string.IsNullOrWhiteSpace(background) || italic || bold) { Writer.Write(" style=\""); if(!string.IsNullOrWhiteSpace(foreground)) { Writer.Write("color:{0};", foreground.ToHTMLColorString()); } if(!string.IsNullOrWhiteSpace(background)) { Writer.Write("background-color:{0};", background.ToHTMLColorString()); } if(italic) { Writer.Write("font-style: italic;"); } if(bold) { Writer.Write("font-weight: bold;"); } Writer.Write("\""); } Writer.Write(">"); } #endregion #region 머리말 PRE 시작 태그 쓰기 - WriteHeaderPreStartTag() /// <summary> /// 머리말 PRE 시작 태그 쓰기 /// </summary> private void WriteHeaderPreStartTag() { WriteElementStartTag("pre"); } #endregion #region 머리말 DIV 시작 태그 쓰기 - WriteHeaderDivStartTag() /// <summary> /// 머리말 DIV 시작 태그 쓰기 /// </summary> private void WriteHeaderDivStartTag() { string foreground = string.Empty; string background = string.Empty; if(StyleDictionary.Contains(ScopeName.PlainText)) { Style plainTextStyle = StyleDictionary[ScopeName.PlainText]; foreground = plainTextStyle.Foreground; background = plainTextStyle.Background; } WriteElementStartTag("div", foreground, background); } #endregion #region 엘리먼트 종료 태그 쓰기 - WriteElementEndTag(elementName) /// <summary> /// 엘리먼트 종료 태그 쓰기 /// </summary> /// <param name="elementName">엘리먼트명</param> private void WriteElementEndTag(string elementName) { Writer.Write("</{0}>", elementName); } #endregion #region 머리말 DIV 종료 태그 쓰기 - WriteHeaderDivEndTag() /// <summary> /// 머리말 DIV 종료 태그 쓰기 /// </summary> private void WriteHeaderDivEndTag() { WriteElementEndTag("div"); } #endregion #region 머리말 PRE 종료 태그 쓰기 - WriteHeaderPreEndTag() /// <summary> /// 머리말 PRE 종료 태그 쓰기 /// </summary> private void WriteHeaderPreEndTag() { WriteElementEndTag("pre"); } #endregion #region 머리글 쓰기 - WriteHeader(language) /// <summary> /// 머리글 쓰기 /// </summary> /// <param name="language">언어 인터페이스</param> private void WriteHeader(ILanguage language) { WriteHeaderDivStartTag(); WriteHeaderPreStartTag(); Writer.WriteLine(); } #endregion #region 바닥글 쓰기 - WriteFooter(language) /// <summary> /// 바닥글 쓰기 /// </summary> /// <param name="language">언어 인터페이스</param> private void WriteFooter(ILanguage language) { Writer.WriteLine(); WriteHeaderPreEndTag(); WriteHeaderDivEndTag(); } #endregion #region 캡처 스타일용 스타일 삽입 컬렉션 구하기 - GetStyleInsertionsForCapturedStyle(scope, textInsertionCollection) /// <summary> /// 캡처 스타일용 스타일 삽입 컬렉션 구하기 /// </summary> /// <param name="scope">범위</param> /// <param name="textInsertionCollection">텍스트 삽입 컬렉션</param> private void GetStyleInsertionsForCapturedStyle(Scope scope, ICollection<TextInsertion> textInsertionCollection) { textInsertionCollection.Add ( new TextInsertion { Index = scope.Index, Scope = scope } ); foreach(Scope childScope in scope.ChildScopeList) { GetStyleInsertionsForCapturedStyle(childScope, textInsertionCollection); } textInsertionCollection.Add ( new TextInsertion { Index = scope.Index + scope.Length, Text = "</span>" } ); } #endregion #region 캡처 스타일용 SPAN 만들기 - BuildSpanForCapturedStyle(scope) /// <summary> /// 캡처 스타일용 SPAN 만들기 /// </summary> /// <param name="scope">범위</param> private void BuildSpanForCapturedStyle(Scope scope) { string foreground = string.Empty; string background = string.Empty; bool italic = false; bool bold = false; if(StyleDictionary.Contains(scope.Name)) { Style style = StyleDictionary[scope.Name]; foreground = style.Foreground; background = style.Background; italic = style.Italic; bold = style.Bold; } WriteElementStartTag("span", foreground, background, italic, bold); } #endregion } |
▶ ILanguage.cs
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 |
namespace TestLibrary; /// <summary> /// 언어 인터페이스 /// </summary> public interface ILanguage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property #region ID - ID /// <summary> /// ID /// </summary> string ID { get; } #endregion #region 첫번째 라인 패턴 - FirstLinePattern /// <summary> /// 첫번째 라인 패턴 /// </summary> string FirstLinePattern { get; } #endregion #region 언어명 - Name /// <summary> /// 언어명 /// </summary> string Name { get; } #endregion #region 언어 규칙 리스트 인터페이스 - LanguageRuleList /// <summary> /// 언어 규칙 리스트 인터페이스 /// </summary> IList<LanguageRule> LanguageRuleList { get; } #endregion #region CSS 클래스명 - CSSClassName /// <summary> /// CSS 클래스명 /// </summary> string CSSClassName { get; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method #region 별칭 여부 구하기 - HasAlias(languageID) /// <summary> /// 별칭 여부 구하기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>별칭 여부 구하기</returns> bool HasAlias(string languageID); #endregion } |
▶ LanguageHelper.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
namespace TestLibrary; /// <summary> /// 언어 헬퍼 /// </summary> public static class LanguageHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Internal #region Field /// <summary> /// 언어 저장소 /// </summary> internal static readonly LanguageRepository LanguageRepository; /// <summary> /// 언어 딕셔너리 /// </summary> internal static readonly Dictionary<string, ILanguage> LanguageDictionary; /// <summary> /// 컴파일된 언어 딕셔너리 /// </summary> internal static Dictionary<string, CompiledLanguage> CompiledLanguageDictionary; /// <summary> /// 컴파일 읽기/쓰기 잠금 슬림 /// </summary> internal static ReaderWriterLockSlim CompileReaderWriterLockSlim; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region ASHX - ASHX /// <summary> /// ASHX /// </summary> public static ILanguage ASHX { get { return LanguageRepository.FindByID(LanguageID.ASHX); } } #endregion #region ASAX - ASAX /// <summary> /// ASAX /// </summary> public static ILanguage ASAX { get { return LanguageRepository.FindByID(LanguageID.ASAX); } } #endregion #region ASPX - ASPX /// <summary> /// ASPX /// </summary> public static ILanguage ASPX { get { return LanguageRepository.FindByID(LanguageID.ASPX); } } #endregion #region ASPXCS - ASPXCS /// <summary> /// ASPXCS /// </summary> public static ILanguage ASPXCS { get { return LanguageRepository.FindByID(LanguageID.ASPXCS); } } #endregion #region ASPXVB - ASPXVB /// <summary> /// ASPXVB /// </summary> public static ILanguage ASPXVB { get { return LanguageRepository.FindByID(LanguageID.ASPXVB); } } #endregion #region CPP - CPP /// <summary> /// CPP /// </summary> public static ILanguage CPP { get { return LanguageRepository.FindByID(LanguageID.CPP); } } #endregion #region CSHARP - CSHARP /// <summary> /// CSHARP /// </summary> public static ILanguage CSHARP { get { return LanguageRepository.FindByID(LanguageID.CSHARP); } } #endregion #region CSS - CSS /// <summary> /// CSS /// </summary> public static ILanguage CSS { get { return LanguageRepository.FindByID(LanguageID.CSS); } } #endregion #region FORTRAN - FORTRAN /// <summary> /// FORTRAN /// </summary> public static ILanguage FORTRAN { get { return LanguageRepository.FindByID(LanguageID.FORTRAN); } } #endregion #region FSHARP - FSHARP /// <summary> /// FSHARP /// </summary> public static ILanguage FSHARP { get { return LanguageRepository.FindByID(LanguageID.FSHARP); } } #endregion #region HASKELL - HASKELL /// <summary> /// HASKELL /// </summary> public static ILanguage HASKELL { get { return LanguageRepository.FindByID(LanguageID.HASKELL); } } #endregion #region HTML - HTML /// <summary> /// HTML /// </summary> public static ILanguage HTML { get { return LanguageRepository.FindByID(LanguageID.HTML); } } #endregion #region JAVA - JAVA /// <summary> /// JAVA /// </summary> public static ILanguage JAVA { get { return LanguageRepository.FindByID(LanguageID.JAVA); } } #endregion #region JAVASCRIPT - JAVASCRIPT /// <summary> /// JAVASCRIPT /// </summary> public static ILanguage JAVASCRIPT { get { return LanguageRepository.FindByID(LanguageID.JAVASCRIPT); } } #endregion #region KOKA - KOKA /// <summary> /// KOKA /// </summary> public static ILanguage KOKA { get { return LanguageRepository.FindByID(LanguageID.KOKA); } } #endregion #region MARKDOWN - MARKDOWN /// <summary> /// MARKDOWN /// </summary> public static ILanguage MARKDOWN { get { return LanguageRepository.FindByID(LanguageID.MARKDOWN); } } #endregion #region MATLAB - MATLAB /// <summary> /// MATLAB /// </summary> public static ILanguage MATLAB { get { return LanguageRepository.FindByID(LanguageID.MATLAB); } } #endregion #region PHP - PHP /// <summary> /// PHP /// </summary> public static ILanguage PHP { get { return LanguageRepository.FindByID(LanguageID.PHP); } } #endregion #region POWERSHELL - POWERSHELL /// <summary> /// POWERSHELL /// </summary> public static ILanguage POWERSHELL { get { return LanguageRepository.FindByID(LanguageID.POWERSHELL); } } #endregion #region PYTHON - PYTHON /// <summary> /// PYTHON /// </summary> public static ILanguage PYTHON { get { return LanguageRepository.FindByID(LanguageID.PYTHON); } } #endregion #region SQL - SQL /// <summary> /// SQL /// </summary> public static ILanguage SQL { get { return LanguageRepository.FindByID(LanguageID.SQL); } } #endregion #region TYPESCRIPT - TYPESCRIPT /// <summary> /// TYPESCRIPT /// </summary> public static ILanguage TYPESCRIPT { get { return LanguageRepository.FindByID(LanguageID.TYPESCRIPT); } } #endregion #region VBDOTNET - VBDOTNET /// <summary> /// VBDOTNET /// </summary> public static ILanguage VBDOTNET { get { return LanguageRepository.FindByID(LanguageID.VBDOTNET); } } #endregion #region XML - XML /// <summary> /// XML /// </summary> public static ILanguage XML { get { return LanguageRepository.FindByID(LanguageID.XML); } } #endregion #region 언어 인터페이스 열거 가능형 - LanguageEnumerable /// <summary> /// 언어 인터페이스 열거 가능형 /// </summary> public static IEnumerable<ILanguage> LanguageEnumerable { get { return LanguageRepository.LanguageEnumerable; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Static #region 생성자 - LanguageHelper() /// <summary> /// 생성자 /// </summary> static LanguageHelper() { LanguageDictionary = new Dictionary<string, ILanguage>(); CompiledLanguageDictionary = new Dictionary<string, CompiledLanguage>(); LanguageRepository = new LanguageRepository(LanguageDictionary); CompileReaderWriterLockSlim = new ReaderWriterLockSlim(); Load<JAVASCRIPT>(); Load<HTML>(); Load<CSHARP>(); Load<VBDOTNET>(); Load<ASHX>(); Load<ASAX>(); Load<ASPX>(); Load<ASPXCS>(); Load<ASPXVB>(); Load<SQL>(); Load<XML>(); Load<PHP>(); Load<CSS>(); Load<CPP>(); Load<JAVA>(); Load<JSON>(); Load<POWERSHELL>(); Load<TYPESCRIPT>(); Load<FSHARP>(); Load<KOKA>(); Load<HASKELL>(); Load<MARKDOWN>(); Load<FORTRAN>(); Load<PYTHON>(); Load<MATLAB>(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region ID로 찾기 - FindByID(languageID) /// <summary> /// ID로 찾기 /// </summary> /// <param name="languageID">언어 ID</param> /// <returns>언어 인터페이스</returns> public static ILanguage FindByID(string languageID) { return LanguageRepository.FindByID(languageID); } #endregion #region 로드하기 - Load(language) /// <summary> /// 로드하기 /// </summary> /// <param name="language">언어</param> public static void Load(ILanguage language) { LanguageRepository.Load(language); } #endregion //////////////////////////////////////////////////////////////////////////////// Private #region 로드하기 - Load<T>() /// <summary> /// 로드하기 /// </summary> /// <typeparam name="TLanguage">언어 타입</typeparam> private static void Load<TLanguage>() where TLanguage : ILanguage, new() { Load(new TLanguage()); } #endregion } |
▶ LanguageRule.cs
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 |
namespace TestLibrary; /// <summary> /// 언어 규칙 /// </summary> public class LanguageRule { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 정규 표현식 - RegularExpression /// <summary> /// 정규 표현식 /// </summary> public string RegularExpression { get; private set; } #endregion #region 캡처 딕셔너리 - CaptureDictionary /// <summary> /// 캡처 딕셔너리 /// </summary> public IDictionary<int, string> CaptureDictionary { get; private set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - LanguageRule(regularExpression, captureDictionary) /// <summary> /// 생성자 /// </summary> /// <param name="regularExpression">정규 표현식</param> /// <param name="captureDictionary">캡처 딕셔너리</param> public LanguageRule(string regularExpression, IDictionary<int, string> captureDictionary) { ArgumentHelper.EnsureIsNotNullAndNotEmpty(regularExpression, "regularExpression"); ArgumentHelper.EnsureIsNotNullAndNotEmpty(captureDictionary, "captureDictionary"); RegularExpression = regularExpression; CaptureDictionary = captureDictionary; } #endregion } |
[TestProject 프로젝트]
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="utf-8"?> <Page x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" FontFamily="나눔고딕코딩" FontSize="16"> <Border Margin="10" BorderThickness="1" BorderBrush="Black"> <WebView2 Name="webView2" /> </Border> </Page> |
▶ MainPage.xaml.cs
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
using System; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using TestLibrary; namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); Loaded += Page_Loaded; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 페이지 로드시 처리하기 - Page_Loaded(sender, e) /// <summary> /// 페이지 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 ㅣㄴ자</param> private async void Page_Loaded(object sender, RoutedEventArgs e) { string sourceCode = @"using Microsoft.UI.Text; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; using ColorCode; namespace TestProject { /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); var paragraph = new Paragraph(); var csharpstring = ""public void Method()\n{\n}""; var formatter = new RichTextBlockFormatter(); formatter.FormatInlines(csharpstring, Languages.CSharp, paragraph.Inlines); this.richTextBlock.Blocks.Add(paragraph); } #endregion } }"; HTMLClassFormatter htmlClassFormatter = new HTMLClassFormatter(); string body = htmlClassFormatter.GetHTMLString(sourceCode, LanguageHelper.CSHARP); string css = htmlClassFormatter.GetCSSString(); string html = @$"<html> <style> {css} </style> <body> {body} </body> </html> "; await this.webView2.EnsureCoreWebView2Async(); this.webView2.NavigateToString(html); } #endregion } |