From c9fba74c156947a95546f53cb0a2c004a30f7bcc Mon Sep 17 00:00:00 2001 From: bashirs Date: Thu, 14 Feb 2013 13:06:41 -0800 Subject: [PATCH] Added support for Typescript colorizing --- ColorCode/ColorCode.csproj | 1 + ColorCode/Common/LanguageId.cs | 1 + ColorCode/Compilation/Languages/Typescript.cs | 90 +++++++++++++++++++ ColorCode/Languages.cs | 10 +++ 4 files changed, 102 insertions(+) create mode 100644 ColorCode/Compilation/Languages/Typescript.cs diff --git a/ColorCode/ColorCode.csproj b/ColorCode/ColorCode.csproj index 0c18a0b..8fd819d 100644 --- a/ColorCode/ColorCode.csproj +++ b/ColorCode/ColorCode.csproj @@ -88,6 +88,7 @@ + diff --git a/ColorCode/Common/LanguageId.cs b/ColorCode/Common/LanguageId.cs index ec5292d..254ef91 100644 --- a/ColorCode/Common/LanguageId.cs +++ b/ColorCode/Common/LanguageId.cs @@ -15,6 +15,7 @@ namespace ColorCode.Common public const string Html = "html"; public const string Java = "java"; public const string JavaScript = "javascript"; + public const string TypeScript = "typescript"; public const string Php = "php"; public const string PowerShell = "powershell"; public const string Sql = "sql"; diff --git a/ColorCode/Compilation/Languages/Typescript.cs b/ColorCode/Compilation/Languages/Typescript.cs new file mode 100644 index 0000000..48c55a8 --- /dev/null +++ b/ColorCode/Compilation/Languages/Typescript.cs @@ -0,0 +1,90 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. + +using System.Collections.Generic; +using ColorCode.Common; + +namespace ColorCode.Compilation.Languages +{ + public class Typescript : ILanguage + { + public string Id + { + get { return LanguageId.TypeScript; } + } + + public string Name + { + get { return "Typescript"; } + } + + public string CssClassName + { + get { return "typescript"; } + } + + public string FirstLinePattern + { + get + { + return null; + } + } + + public IList Rules + { + get + { + return new List + { + new LanguageRule( + @"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", + new Dictionary + { + { 0, ScopeName.Comment }, + }), + new LanguageRule( + @"(//.*?)\r?$", + new Dictionary + { + { 1, ScopeName.Comment }, + }), + new LanguageRule( + @"'[^\n]*?'", + new Dictionary + { + { 0, ScopeName.String }, + }), + new LanguageRule( + @"""[^\n]*?""", + new Dictionary + { + { 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 + { + { 1, ScopeName.Keyword }, + }), + }; + } + } + + public bool HasAlias(string lang) + { + switch (lang.ToLower()) + { + case "ts": + return true; + + default: + return false; + } + } + + public override string ToString() + { + return Name; + } + } +} \ No newline at end of file diff --git a/ColorCode/Languages.cs b/ColorCode/Languages.cs index f9e3dba..041fa99 100644 --- a/ColorCode/Languages.cs +++ b/ColorCode/Languages.cs @@ -38,6 +38,7 @@ namespace ColorCode Load(); Load(); Load(); + Load(); } /// @@ -192,6 +193,15 @@ namespace ColorCode get { return LanguageRepository.FindById(LanguageId.Cpp); } } + /// + /// Language support for Typescript. + /// + /// Language support for typescript. + public static ILanguage Typescript + { + get { return LanguageRepository.FindById(LanguageId.TypeScript); } + } + /// /// Finds a loaded language by the specified identifier. ///