-Renamed ColorCode to ColorCode.Core. Moved TextInsertion back to the Core Library.
-Removed the depency on .NET Standard 2.0 from ColorCode.HTML, you can now use it from .NET Standard 1.4. -Removed StyleSheets, Moved Style and StyleDictionary back to ColorCode.Core, you can now use these to Style the Syntax Highlighting. Removed references to System.Drawing.Color, using Hex Colors instead. -Added GetCSSString() to HtmlClassFormatter, so that you can produce a CSS File. -Changed Method Structure of both Html formatters. -Created and completed the RichTextBlockFormatter. Use FormatRichTextBlock(), or FormatInlines(), to insert formatted code. -Added a .NETCore test app to test HTML creation, and a UWP Test App to test RichTextBlock formatting. -Added some basic documentation. -Added Readme.md.
|
@ -0,0 +1,40 @@
|
|||
using ColorCode.Compilation;
|
||||
using ColorCode.Parsing;
|
||||
using ColorCode.Styling;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="CodeColorizerBase"/>, for creating Syntax Highlighted code.
|
||||
/// </summary>
|
||||
/// <param name="Style">The Custom styles to Apply to the formatted Code.</param>
|
||||
/// <param name="languageParser">The language parser that the <see cref="CodeColorizerBase"/> instance will use for its lifetime.</param>
|
||||
public abstract class CodeColorizerBase
|
||||
{
|
||||
public CodeColorizerBase(StyleDictionary Styles, ILanguageParser languageParser)
|
||||
{
|
||||
this.languageParser = languageParser
|
||||
?? new LanguageParser(new LanguageCompiler(Languages.CompiledLanguages), Languages.LanguageRepository);
|
||||
|
||||
this.Styles = Styles ?? StyleDictionary.Default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the parsed source code to the ouput using the specified style sheet.
|
||||
/// </summary>
|
||||
/// <param name="parsedSourceCode">The parsed source code to format and write to the output.</param>
|
||||
/// <param name="scopes">The captured scopes for the parsed source code.</param>
|
||||
protected abstract void Write(string parsedSourceCode, IList<Scope> scopes);
|
||||
|
||||
/// <summary>
|
||||
/// The language parser that the <see cref="CodeColorizerBase"/> instance will use for its lifetime.
|
||||
/// </summary>
|
||||
protected readonly ILanguageParser languageParser;
|
||||
|
||||
/// <summary>
|
||||
/// The styles to Apply to the formatted Code.
|
||||
/// </summary>
|
||||
protected readonly StyleDictionary Styles;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.4</TargetFramework>
|
||||
<RootNamespace>ColorCode</RootNamespace>
|
||||
<AssemblyName>ColorCode.Core</AssemblyName>
|
||||
<Title>ColorCode-Universal</Title>
|
||||
<Description>The Core Library, containing the Parser, and the classes to create your own formatter.</Description>
|
||||
<PackageTags>ColorCode Syntax Highlighting SyntaxHighlighting Formatting</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -1,31 +1,31 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
{
|
||||
public static void SortStable<T>(this IList<T> list,
|
||||
Comparison<T> comparison)
|
||||
{
|
||||
Guard.ArgNotNull(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
{
|
||||
public static void SortStable<T>(this IList<T> list,
|
||||
Comparison<T> comparison)
|
||||
{
|
||||
Guard.ArgNotNull(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,40 +1,40 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public static class Guard
|
||||
{
|
||||
public static void ArgNotNull(object arg, string paramName)
|
||||
{
|
||||
if (arg == null)
|
||||
throw new ArgumentNullException(paramName);
|
||||
}
|
||||
|
||||
public static void ArgNotNullAndNotEmpty(string arg, string paramName)
|
||||
{
|
||||
if (arg == null)
|
||||
throw new ArgumentNullException(paramName);
|
||||
|
||||
if (string.IsNullOrEmpty(arg))
|
||||
throw new ArgumentException(string.Format("The {0} argument value must not be empty.", paramName), paramName);
|
||||
}
|
||||
|
||||
public static void EnsureParameterIsNotNullAndNotEmpty<TKey, TValue>(IDictionary<TKey, TValue> parameter, string parameterName)
|
||||
{
|
||||
if (parameter == null || parameter.Count == 0)
|
||||
throw new ArgumentNullException(parameterName);
|
||||
}
|
||||
|
||||
public static void ArgNotNullAndNotEmpty<T>(IList<T> arg, string paramName)
|
||||
{
|
||||
if (arg == null)
|
||||
throw new ArgumentNullException(paramName);
|
||||
|
||||
if (arg.Count == 0)
|
||||
throw new ArgumentException(string.Format("The {0} argument value must not be empty.", paramName), paramName);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public static class Guard
|
||||
{
|
||||
public static void ArgNotNull(object arg, string paramName)
|
||||
{
|
||||
if (arg == null)
|
||||
throw new ArgumentNullException(paramName);
|
||||
}
|
||||
|
||||
public static void ArgNotNullAndNotEmpty(string arg, string paramName)
|
||||
{
|
||||
if (arg == null)
|
||||
throw new ArgumentNullException(paramName);
|
||||
|
||||
if (string.IsNullOrEmpty(arg))
|
||||
throw new ArgumentException(string.Format("The {0} argument value must not be empty.", paramName), paramName);
|
||||
}
|
||||
|
||||
public static void EnsureParameterIsNotNullAndNotEmpty<TKey, TValue>(IDictionary<TKey, TValue> parameter, string parameterName)
|
||||
{
|
||||
if (parameter == null || parameter.Count == 0)
|
||||
throw new ArgumentNullException(parameterName);
|
||||
}
|
||||
|
||||
public static void ArgNotNullAndNotEmpty<T>(IList<T> arg, string paramName)
|
||||
{
|
||||
if (arg == null)
|
||||
throw new ArgumentNullException(paramName);
|
||||
|
||||
if (arg.Count == 0)
|
||||
throw new ArgumentException(string.Format("The {0} argument value must not be empty.", paramName), paramName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public interface ILanguageRepository
|
||||
{
|
||||
IEnumerable<ILanguage> All { get; }
|
||||
ILanguage FindById(string languageId);
|
||||
void Load(ILanguage language);
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public interface ILanguageRepository
|
||||
{
|
||||
IEnumerable<ILanguage> All { get; }
|
||||
ILanguage FindById(string languageId);
|
||||
void Load(ILanguage language);
|
||||
}
|
||||
}
|
|
@ -1,29 +1,29 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public static class LanguageId
|
||||
{
|
||||
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 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";
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public static class LanguageId
|
||||
{
|
||||
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 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";
|
||||
}
|
||||
}
|
|
@ -1,69 +1,69 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public class LanguageRepository : ILanguageRepository
|
||||
{
|
||||
private readonly Dictionary<string, ILanguage> loadedLanguages;
|
||||
private readonly ReaderWriterLockSlim loadLock;
|
||||
|
||||
public LanguageRepository(Dictionary<string, ILanguage> loadedLanguages)
|
||||
{
|
||||
this.loadedLanguages = loadedLanguages;
|
||||
loadLock = new ReaderWriterLockSlim();
|
||||
}
|
||||
|
||||
public IEnumerable<ILanguage> All
|
||||
{
|
||||
get { return loadedLanguages.Values; }
|
||||
}
|
||||
|
||||
public ILanguage FindById(string languageId)
|
||||
{
|
||||
Guard.ArgNotNullAndNotEmpty(languageId, "languageId");
|
||||
|
||||
ILanguage language = null;
|
||||
|
||||
loadLock.EnterReadLock();
|
||||
|
||||
try
|
||||
{
|
||||
// If we have a matching name for the language then use it
|
||||
// otherwise check if any languages have that string as an
|
||||
// alias. For example: "js" is an alias for Javascript.
|
||||
language = loadedLanguages.FirstOrDefault(x => (x.Key.ToLower() == languageId.ToLower()) ||
|
||||
(x.Value.HasAlias(languageId))).Value;
|
||||
}
|
||||
finally
|
||||
{
|
||||
loadLock.ExitReadLock();
|
||||
}
|
||||
|
||||
return language;
|
||||
}
|
||||
|
||||
public void Load(ILanguage language)
|
||||
{
|
||||
Guard.ArgNotNull(language, "language");
|
||||
|
||||
if (string.IsNullOrEmpty(language.Id))
|
||||
throw new ArgumentException("The language identifier must not be null or empty.", "language");
|
||||
|
||||
loadLock.EnterWriteLock();
|
||||
|
||||
try
|
||||
{
|
||||
loadedLanguages[language.Id] = language;
|
||||
}
|
||||
finally
|
||||
{
|
||||
loadLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public class LanguageRepository : ILanguageRepository
|
||||
{
|
||||
private readonly Dictionary<string, ILanguage> loadedLanguages;
|
||||
private readonly ReaderWriterLockSlim loadLock;
|
||||
|
||||
public LanguageRepository(Dictionary<string, ILanguage> loadedLanguages)
|
||||
{
|
||||
this.loadedLanguages = loadedLanguages;
|
||||
loadLock = new ReaderWriterLockSlim();
|
||||
}
|
||||
|
||||
public IEnumerable<ILanguage> All
|
||||
{
|
||||
get { return loadedLanguages.Values; }
|
||||
}
|
||||
|
||||
public ILanguage FindById(string languageId)
|
||||
{
|
||||
Guard.ArgNotNullAndNotEmpty(languageId, "languageId");
|
||||
|
||||
ILanguage language = null;
|
||||
|
||||
loadLock.EnterReadLock();
|
||||
|
||||
try
|
||||
{
|
||||
// If we have a matching name for the language then use it
|
||||
// otherwise check if any languages have that string as an
|
||||
// alias. For example: "js" is an alias for Javascript.
|
||||
language = loadedLanguages.FirstOrDefault(x => (x.Key.ToLower() == languageId.ToLower()) ||
|
||||
(x.Value.HasAlias(languageId))).Value;
|
||||
}
|
||||
finally
|
||||
{
|
||||
loadLock.ExitReadLock();
|
||||
}
|
||||
|
||||
return language;
|
||||
}
|
||||
|
||||
public void Load(ILanguage language)
|
||||
{
|
||||
Guard.ArgNotNull(language, "language");
|
||||
|
||||
if (string.IsNullOrEmpty(language.Id))
|
||||
throw new ArgumentException("The language identifier must not be null or empty.", "language");
|
||||
|
||||
loadLock.EnterWriteLock();
|
||||
|
||||
try
|
||||
{
|
||||
loadedLanguages[language.Id] = language;
|
||||
}
|
||||
finally
|
||||
{
|
||||
loadLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,57 +1,57 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public class ScopeName
|
||||
{
|
||||
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 Keyword = "Keyword";
|
||||
public const string LanguagePrefix = "&";
|
||||
public const string PlainText = "Plain Text";
|
||||
public const string PowerShellAttribute = "PowerShell PowerShellAttribute";
|
||||
public const string PowerShellOperator = "PowerShell Operator";
|
||||
public const string PowerShellType = "PowerShell Type";
|
||||
public const string PowerShellVariable = "PowerShell Variable";
|
||||
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";
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
namespace ColorCode.Common
|
||||
{
|
||||
public class ScopeName
|
||||
{
|
||||
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 Keyword = "Keyword";
|
||||
public const string LanguagePrefix = "&";
|
||||
public const string PlainText = "Plain Text";
|
||||
public const string PowerShellAttribute = "PowerShell PowerShellAttribute";
|
||||
public const string PowerShellOperator = "PowerShell Operator";
|
||||
public const string PowerShellType = "PowerShell Type";
|
||||
public const string PowerShellVariable = "PowerShell Variable";
|
||||
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";
|
||||
}
|
||||
}
|
|
@ -1,37 +1,37 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public class CompiledLanguage
|
||||
{
|
||||
public CompiledLanguage(string id,
|
||||
string name,
|
||||
Regex regex,
|
||||
IList<string> captures)
|
||||
{
|
||||
Guard.ArgNotNullAndNotEmpty(id, "id");
|
||||
Guard.ArgNotNullAndNotEmpty(name, "name");
|
||||
Guard.ArgNotNull(regex, "regex");
|
||||
Guard.ArgNotNullAndNotEmpty(captures, "captures");
|
||||
|
||||
Id = id;
|
||||
Name = name;
|
||||
Regex = regex;
|
||||
Captures = captures;
|
||||
}
|
||||
|
||||
public IList<string> Captures { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public Regex Regex { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public class CompiledLanguage
|
||||
{
|
||||
public CompiledLanguage(string id,
|
||||
string name,
|
||||
Regex regex,
|
||||
IList<string> captures)
|
||||
{
|
||||
Guard.ArgNotNullAndNotEmpty(id, "id");
|
||||
Guard.ArgNotNullAndNotEmpty(name, "name");
|
||||
Guard.ArgNotNull(regex, "regex");
|
||||
Guard.ArgNotNullAndNotEmpty(captures, "captures");
|
||||
|
||||
Id = id;
|
||||
Name = name;
|
||||
Regex = regex;
|
||||
Captures = captures;
|
||||
}
|
||||
|
||||
public IList<string> Captures { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public Regex Regex { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public interface ILanguageCompiler
|
||||
{
|
||||
CompiledLanguage Compile(ILanguage language);
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public interface ILanguageCompiler
|
||||
{
|
||||
CompiledLanguage Compile(ILanguage language);
|
||||
}
|
||||
}
|
|
@ -1,153 +1,153 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public class LanguageCompiler : ILanguageCompiler
|
||||
{
|
||||
private static readonly Regex numberOfCapturesRegex = new Regex(@"(?x)(?<!(\\|(?!\\)\(\?))\((?!\?)", RegexOptions.Compiled);
|
||||
private readonly Dictionary<string, CompiledLanguage> compiledLanguages;
|
||||
private readonly ReaderWriterLockSlim compileLock;
|
||||
|
||||
public LanguageCompiler(Dictionary<string, CompiledLanguage> compiledLanguages)
|
||||
{
|
||||
this.compiledLanguages = compiledLanguages;
|
||||
|
||||
compileLock = new ReaderWriterLockSlim();
|
||||
}
|
||||
|
||||
public CompiledLanguage Compile(ILanguage language)
|
||||
{
|
||||
Guard.ArgNotNull(language, "language");
|
||||
|
||||
if (string.IsNullOrEmpty(language.Id))
|
||||
throw new ArgumentException("The language identifier must not be null.", "language");
|
||||
|
||||
CompiledLanguage compiledLanguage;
|
||||
|
||||
compileLock.EnterReadLock();
|
||||
try
|
||||
{
|
||||
// for performance reasons we should first try with
|
||||
// only a read lock since the majority of the time
|
||||
// it'll be created already and upgradeable lock blocks
|
||||
if (compiledLanguages.ContainsKey(language.Id))
|
||||
return compiledLanguages[language.Id];
|
||||
}
|
||||
finally
|
||||
{
|
||||
compileLock.ExitReadLock();
|
||||
}
|
||||
|
||||
compileLock.EnterUpgradeableReadLock();
|
||||
try
|
||||
{
|
||||
if (compiledLanguages.ContainsKey(language.Id))
|
||||
compiledLanguage = compiledLanguages[language.Id];
|
||||
else
|
||||
{
|
||||
compileLock.EnterWriteLock();
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(language.Name))
|
||||
throw new ArgumentException("The language name must not be null or empty.", "language");
|
||||
|
||||
if (language.Rules == null || language.Rules.Count == 0)
|
||||
throw new ArgumentException("The language rules collection must not be empty.", "language");
|
||||
|
||||
compiledLanguage = CompileLanguage(language);
|
||||
|
||||
compiledLanguages.Add(compiledLanguage.Id, compiledLanguage);
|
||||
}
|
||||
finally
|
||||
{
|
||||
compileLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
compileLock.ExitUpgradeableReadLock();
|
||||
}
|
||||
|
||||
return compiledLanguage;
|
||||
}
|
||||
|
||||
private static CompiledLanguage CompileLanguage(ILanguage language)
|
||||
{
|
||||
string id = language.Id;
|
||||
string name = language.Name;
|
||||
Regex regex;
|
||||
IList<string> captures;
|
||||
|
||||
CompileRules(language.Rules, out regex, out captures);
|
||||
|
||||
return new CompiledLanguage(id, name, regex, captures);
|
||||
}
|
||||
|
||||
private static void CompileRules(IList<LanguageRule> rules,
|
||||
out Regex regex,
|
||||
out IList<string> captures)
|
||||
{
|
||||
StringBuilder regexBuilder = new StringBuilder();
|
||||
captures = new List<string>();
|
||||
|
||||
regexBuilder.AppendLine("(?x)");
|
||||
captures.Add(null);
|
||||
|
||||
CompileRule(rules[0], regexBuilder, captures, true);
|
||||
|
||||
for (int i = 1; i < rules.Count; i++)
|
||||
CompileRule(rules[i], regexBuilder, captures, false);
|
||||
|
||||
regex = new Regex(regexBuilder.ToString());
|
||||
}
|
||||
|
||||
|
||||
private static void CompileRule(LanguageRule languageRule,
|
||||
StringBuilder regex,
|
||||
ICollection<string> captures,
|
||||
bool isFirstRule)
|
||||
{
|
||||
if (!isFirstRule)
|
||||
{
|
||||
regex.AppendLine();
|
||||
regex.AppendLine();
|
||||
regex.AppendLine("|");
|
||||
regex.AppendLine();
|
||||
}
|
||||
|
||||
regex.AppendFormat("(?-xis)(?m)({0})(?x)", languageRule.Regex);
|
||||
|
||||
int numberOfCaptures = GetNumberOfCaptures(languageRule.Regex);
|
||||
|
||||
for (int i = 0; i <= numberOfCaptures; i++)
|
||||
{
|
||||
string scope = null;
|
||||
|
||||
foreach (int captureIndex in languageRule.Captures.Keys)
|
||||
{
|
||||
if (i == captureIndex)
|
||||
{
|
||||
scope = languageRule.Captures[captureIndex];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
captures.Add(scope);
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetNumberOfCaptures(string regex)
|
||||
{
|
||||
return numberOfCapturesRegex.Matches(regex).Count;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public class LanguageCompiler : ILanguageCompiler
|
||||
{
|
||||
private static readonly Regex numberOfCapturesRegex = new Regex(@"(?x)(?<!(\\|(?!\\)\(\?))\((?!\?)", RegexOptions.Compiled);
|
||||
private readonly Dictionary<string, CompiledLanguage> compiledLanguages;
|
||||
private readonly ReaderWriterLockSlim compileLock;
|
||||
|
||||
public LanguageCompiler(Dictionary<string, CompiledLanguage> compiledLanguages)
|
||||
{
|
||||
this.compiledLanguages = compiledLanguages;
|
||||
|
||||
compileLock = new ReaderWriterLockSlim();
|
||||
}
|
||||
|
||||
public CompiledLanguage Compile(ILanguage language)
|
||||
{
|
||||
Guard.ArgNotNull(language, "language");
|
||||
|
||||
if (string.IsNullOrEmpty(language.Id))
|
||||
throw new ArgumentException("The language identifier must not be null.", "language");
|
||||
|
||||
CompiledLanguage compiledLanguage;
|
||||
|
||||
compileLock.EnterReadLock();
|
||||
try
|
||||
{
|
||||
// for performance reasons we should first try with
|
||||
// only a read lock since the majority of the time
|
||||
// it'll be created already and upgradeable lock blocks
|
||||
if (compiledLanguages.ContainsKey(language.Id))
|
||||
return compiledLanguages[language.Id];
|
||||
}
|
||||
finally
|
||||
{
|
||||
compileLock.ExitReadLock();
|
||||
}
|
||||
|
||||
compileLock.EnterUpgradeableReadLock();
|
||||
try
|
||||
{
|
||||
if (compiledLanguages.ContainsKey(language.Id))
|
||||
compiledLanguage = compiledLanguages[language.Id];
|
||||
else
|
||||
{
|
||||
compileLock.EnterWriteLock();
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(language.Name))
|
||||
throw new ArgumentException("The language name must not be null or empty.", "language");
|
||||
|
||||
if (language.Rules == null || language.Rules.Count == 0)
|
||||
throw new ArgumentException("The language rules collection must not be empty.", "language");
|
||||
|
||||
compiledLanguage = CompileLanguage(language);
|
||||
|
||||
compiledLanguages.Add(compiledLanguage.Id, compiledLanguage);
|
||||
}
|
||||
finally
|
||||
{
|
||||
compileLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
compileLock.ExitUpgradeableReadLock();
|
||||
}
|
||||
|
||||
return compiledLanguage;
|
||||
}
|
||||
|
||||
private static CompiledLanguage CompileLanguage(ILanguage language)
|
||||
{
|
||||
string id = language.Id;
|
||||
string name = language.Name;
|
||||
Regex regex;
|
||||
IList<string> captures;
|
||||
|
||||
CompileRules(language.Rules, out regex, out captures);
|
||||
|
||||
return new CompiledLanguage(id, name, regex, captures);
|
||||
}
|
||||
|
||||
private static void CompileRules(IList<LanguageRule> rules,
|
||||
out Regex regex,
|
||||
out IList<string> captures)
|
||||
{
|
||||
StringBuilder regexBuilder = new StringBuilder();
|
||||
captures = new List<string>();
|
||||
|
||||
regexBuilder.AppendLine("(?x)");
|
||||
captures.Add(null);
|
||||
|
||||
CompileRule(rules[0], regexBuilder, captures, true);
|
||||
|
||||
for (int i = 1; i < rules.Count; i++)
|
||||
CompileRule(rules[i], regexBuilder, captures, false);
|
||||
|
||||
regex = new Regex(regexBuilder.ToString());
|
||||
}
|
||||
|
||||
|
||||
private static void CompileRule(LanguageRule languageRule,
|
||||
StringBuilder regex,
|
||||
ICollection<string> captures,
|
||||
bool isFirstRule)
|
||||
{
|
||||
if (!isFirstRule)
|
||||
{
|
||||
regex.AppendLine();
|
||||
regex.AppendLine();
|
||||
regex.AppendLine("|");
|
||||
regex.AppendLine();
|
||||
}
|
||||
|
||||
regex.AppendFormat("(?-xis)(?m)({0})(?x)", languageRule.Regex);
|
||||
|
||||
int numberOfCaptures = GetNumberOfCaptures(languageRule.Regex);
|
||||
|
||||
for (int i = 0; i <= numberOfCaptures; i++)
|
||||
{
|
||||
string scope = null;
|
||||
|
||||
foreach (int captureIndex in languageRule.Captures.Keys)
|
||||
{
|
||||
if (i == captureIndex)
|
||||
{
|
||||
scope = languageRule.Captures[captureIndex];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
captures.Add(scope);
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetNumberOfCaptures(string regex)
|
||||
{
|
||||
return numberOfCapturesRegex.Matches(regex).Count;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,114 +1,114 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Asax : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Asax; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASAX"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "asax"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 }
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Asax : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Asax; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASAX"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "asax"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 }
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,85 +1,85 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Ashx : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Ashx; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASHX"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "ashx"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 }
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Ashx : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Ashx; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASHX"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "ashx"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 }
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,132 +1,132 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Aspx : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Aspx; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASPX"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "aspx"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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(RuleFormats.JavaScript, RuleCaptures.JavaScript),
|
||||
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 }
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Aspx : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Aspx; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASPX"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "aspx"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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(RuleFormats.JavaScript, RuleCaptures.JavaScript),
|
||||
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 }
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,143 +1,143 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class AspxCs : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.AspxCs; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASPX (C#)"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "aspx-cs"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"(?xims)<%@\s*?(?:page|control|master|servicehost|webservice).*?(?:language=""c\#""|src="".+?.cs"").*?%>";
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageId.CSharp) },
|
||||
{ 3, ScopeName.HtmlServerSideScript }
|
||||
}),
|
||||
new LanguageRule(RuleFormats.ServerScript, RuleCaptures.CSharpScript),
|
||||
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(RuleFormats.JavaScript, RuleCaptures.JavaScript),
|
||||
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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "aspx-cs":
|
||||
case "aspx (cs)":
|
||||
case "aspx(cs)":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class AspxCs : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.AspxCs; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASPX (C#)"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "aspx-cs"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"(?xims)<%@\s*?(?:page|control|master|servicehost|webservice).*?(?:language=""c\#""|src="".+?.cs"").*?%>";
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageId.CSharp) },
|
||||
{ 3, ScopeName.HtmlServerSideScript }
|
||||
}),
|
||||
new LanguageRule(RuleFormats.ServerScript, RuleCaptures.CSharpScript),
|
||||
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(RuleFormats.JavaScript, RuleCaptures.JavaScript),
|
||||
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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "aspx-cs":
|
||||
case "aspx (cs)":
|
||||
case "aspx(cs)":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,155 +1,155 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class AspxVb : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.AspxVb; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASPX (VB.NET)"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "aspx-vb"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"(?xims)<%@\s*?(?:page|control|master|webhandler|servicehost|webservice).*?language=""vb"".*?%>";
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageId.VbDotNet) },
|
||||
{ 3, ScopeName.HtmlServerSideScript }
|
||||
}),
|
||||
new LanguageRule(RuleFormats.ServerScript, RuleCaptures.VbDotNetScript),
|
||||
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(RuleFormats.JavaScript, RuleCaptures.JavaScript),
|
||||
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, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageId.VbDotNet) },
|
||||
{ 9, ScopeName.HtmlServerSideScript },
|
||||
{ 10, ScopeName.HtmlAttributeName },
|
||||
{ 11, ScopeName.HtmlOperator },
|
||||
{ 12, ScopeName.HtmlServerSideScript },
|
||||
{ 13, string.Format("{0}{1}", 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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "aspx-vb":
|
||||
case "aspx (vb.net)":
|
||||
case "aspx(vb.net)":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class AspxVb : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.AspxVb; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ASPX (VB.NET)"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "aspx-vb"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"(?xims)<%@\s*?(?:page|control|master|webhandler|servicehost|webservice).*?language=""vb"".*?%>";
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageId.VbDotNet) },
|
||||
{ 3, ScopeName.HtmlServerSideScript }
|
||||
}),
|
||||
new LanguageRule(RuleFormats.ServerScript, RuleCaptures.VbDotNetScript),
|
||||
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(RuleFormats.JavaScript, RuleCaptures.JavaScript),
|
||||
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, string.Format("{0}{1}", ScopeName.LanguagePrefix, LanguageId.VbDotNet) },
|
||||
{ 9, ScopeName.HtmlServerSideScript },
|
||||
{ 10, ScopeName.HtmlAttributeName },
|
||||
{ 11, ScopeName.HtmlOperator },
|
||||
{ 12, ScopeName.HtmlServerSideScript },
|
||||
{ 13, string.Format("{0}{1}", 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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "aspx-vb":
|
||||
case "aspx (vb.net)":
|
||||
case "aspx(vb.net)":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,118 +1,118 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class CSharp : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.CSharp; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "C#"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "csharp"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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)\b",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{ 1, ScopeName.Keyword }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "cs":
|
||||
case "c#":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class CSharp : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.CSharp; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "C#"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "csharp"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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)\b",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{ 1, ScopeName.Keyword }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "cs":
|
||||
case "c#":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,85 +1,85 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Cpp : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Cpp; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "C++"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "cplusplus"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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},
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "c++":
|
||||
case "c":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Cpp : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Cpp; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "C++"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "cplusplus"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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},
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "c++":
|
||||
case "c":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,63 +1,63 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Css : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Css; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "CSS"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "css"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Css : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Css; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "CSS"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "css"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,129 +1,129 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class FSharp : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.FSharp; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "F#"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "FSharp"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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)\b",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{ 1, ScopeName.Keyword }
|
||||
}),
|
||||
new LanguageRule(
|
||||
@"(\w|\s)(->)(\w|\s)",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{ 2, ScopeName.Keyword }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "fs":
|
||||
case "f#":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class FSharp : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.FSharp; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "F#"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "FSharp"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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)\b",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{ 1, ScopeName.Keyword }
|
||||
}),
|
||||
new LanguageRule(
|
||||
@"(\w|\s)(->)(\w|\s)",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{ 2, ScopeName.Keyword }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "fs":
|
||||
case "f#":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,269 +1,269 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Haskell : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Haskell; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Haskell"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "haskell"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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 + @")*\)"
|
||||
+ ")*";
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "hs":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Haskell : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Haskell; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Haskell"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "haskell"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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 + @")*\)"
|
||||
+ ")*";
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "hs":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,143 +1,143 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Html : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Html; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "HTML"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "html"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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, string.Format("{0}{1}", 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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "htm":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Html : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Html; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "HTML"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "html"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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, string.Format("{0}{1}", 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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "htm":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,83 +1,83 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Java : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Java; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Java"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "java"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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},
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Java : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Java; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Java"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "java"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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},
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,93 +1,93 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class JavaScript : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.JavaScript; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "JavaScript"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "javascript"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "js":
|
||||
return true;
|
||||
|
||||
case "json":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class JavaScript : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.JavaScript; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "JavaScript"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "javascript"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "js":
|
||||
return true;
|
||||
|
||||
case "json":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,244 +1,244 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Koka : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Koka; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Koka"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "koka"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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})";
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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)[,])" + @")*)+" +
|
||||
@")*" +
|
||||
@"", //(?=(?:[,\)\{\}\]<>]|(" + keywords +")\b))",
|
||||
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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower()) {
|
||||
case "kk":
|
||||
case "kki":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Koka : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Koka; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Koka"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "koka"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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})";
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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)[,])" + @")*)+" +
|
||||
@")*" +
|
||||
@"", //(?=(?:[,\)\{\}\]<>]|(" + keywords +")\b))",
|
||||
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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower()) {
|
||||
case "kk":
|
||||
case "kki":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,178 +1,178 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Markdown : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Markdown; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Markdown"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "markdown"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private string link(string content = @"([^\]\n]+)")
|
||||
{
|
||||
return @"\!?\[" + content + @"\][ \t]*(\([^\)\n]*\)|\[[^\]\n]*\])";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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(
|
||||
link(link()) + "|" + link(), // 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 }, // nice gray
|
||||
}),
|
||||
|
||||
// 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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "md":
|
||||
case "markdown":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Markdown : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Markdown; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Markdown"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "markdown"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private string link(string content = @"([^\]\n]+)")
|
||||
{
|
||||
return @"\!?\[" + content + @"\][ \t]*(\([^\)\n]*\)|\[[^\]\n]*\])";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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(
|
||||
link(link()) + "|" + link(), // 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 }, // nice gray
|
||||
}),
|
||||
|
||||
// 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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "md":
|
||||
case "markdown":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,99 +1,99 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Php : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Php; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "PHP"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "php"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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(
|
||||
// from http://us.php.net/manual/en/reserved.keywords.php
|
||||
@"\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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "php3":
|
||||
case "php4":
|
||||
case "php5":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Php : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Php; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "PHP"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "php"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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(
|
||||
// from http://us.php.net/manual/en/reserved.keywords.php
|
||||
@"\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 },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "php3":
|
||||
case "php4":
|
||||
case "php5":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,144 +1,144 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class PowerShell : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.PowerShell; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "PowerShell"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "powershell"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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(
|
||||
@"\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(
|
||||
@"-(?: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(
|
||||
@"(?:\+=|-=|\*=|/=|%=|=|\+\+|--|\+|-|\*|/|%)",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{0, ScopeName.PowerShellOperator}
|
||||
}
|
||||
),
|
||||
new LanguageRule(
|
||||
@"(?:\>\>|2\>&1|\>|2\>\>|2\>)",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{0, ScopeName.PowerShellOperator}
|
||||
}
|
||||
),
|
||||
new LanguageRule(
|
||||
@"(?s)\[(CmdletBinding)[^\]]+\]",
|
||||
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}
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "posh":
|
||||
case "ps1":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class PowerShell : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.PowerShell; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "PowerShell"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "powershell"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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(
|
||||
@"\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(
|
||||
@"-(?: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(
|
||||
@"(?:\+=|-=|\*=|/=|%=|=|\+\+|--|\+|-|\*|/|%)",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{0, ScopeName.PowerShellOperator}
|
||||
}
|
||||
),
|
||||
new LanguageRule(
|
||||
@"(?:\>\>|2\>&1|\>|2\>\>|2\>)",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{0, ScopeName.PowerShellOperator}
|
||||
}
|
||||
),
|
||||
new LanguageRule(
|
||||
@"(?s)\[(CmdletBinding)[^\]]+\]",
|
||||
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}
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "posh":
|
||||
case "ps1":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,103 +1,103 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Sql : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Sql; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "SQL"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "sql"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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}
|
||||
}
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Sql : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Sql; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "SQL"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "sql"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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}
|
||||
}
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,94 +1,94 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class VbDotNet : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.VbDotNet; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "VB.NET"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "vb-net"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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)\b",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{ 1, ScopeName.Keyword },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "vb.net":
|
||||
case "vbnet":
|
||||
case "vb":
|
||||
case "visualbasic":
|
||||
case "visual basic":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class VbDotNet : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.VbDotNet; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "VB.NET"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "vb-net"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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)\b",
|
||||
new Dictionary<int, string>
|
||||
{
|
||||
{ 1, ScopeName.Keyword },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "vb.net":
|
||||
case "vbnet":
|
||||
case "vb":
|
||||
case "visualbasic":
|
||||
case "visual basic":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,142 +1,142 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Xml : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Xml; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "XML"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "xml"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation.Languages
|
||||
{
|
||||
public class Xml : ILanguage
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get { return LanguageId.Xml; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "XML"; }
|
||||
}
|
||||
|
||||
public string CssClassName
|
||||
{
|
||||
get { return "xml"; }
|
||||
}
|
||||
|
||||
public string FirstLinePattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LanguageRule> Rules
|
||||
{
|
||||
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 }
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAlias(string lang)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +1,58 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public static class RuleCaptures
|
||||
{
|
||||
public static IDictionary<int, string> JavaScript;
|
||||
public static IDictionary<int, string> CSharpScript;
|
||||
public static IDictionary<int, string> VbDotNetScript;
|
||||
|
||||
static RuleCaptures()
|
||||
{
|
||||
JavaScript = BuildCaptures(LanguageId.JavaScript);
|
||||
CSharpScript = BuildCaptures(LanguageId.CSharp);
|
||||
VbDotNetScript = BuildCaptures(LanguageId.VbDotNet);
|
||||
}
|
||||
|
||||
private static IDictionary<int, string> BuildCaptures(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, string.Format("{0}{1}", ScopeName.LanguagePrefix, languageId)},
|
||||
{28, ScopeName.HtmlTagDelimiter},
|
||||
{29, ScopeName.HtmlElementName},
|
||||
{30, ScopeName.HtmlTagDelimiter}
|
||||
};
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public static class RuleCaptures
|
||||
{
|
||||
public static IDictionary<int, string> JavaScript;
|
||||
public static IDictionary<int, string> CSharpScript;
|
||||
public static IDictionary<int, string> VbDotNetScript;
|
||||
|
||||
static RuleCaptures()
|
||||
{
|
||||
JavaScript = BuildCaptures(LanguageId.JavaScript);
|
||||
CSharpScript = BuildCaptures(LanguageId.CSharp);
|
||||
VbDotNetScript = BuildCaptures(LanguageId.VbDotNet);
|
||||
}
|
||||
|
||||
private static IDictionary<int, string> BuildCaptures(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, string.Format("{0}{1}", ScopeName.LanguagePrefix, languageId)},
|
||||
{28, ScopeName.HtmlTagDelimiter},
|
||||
{29, ScopeName.HtmlElementName},
|
||||
{30, ScopeName.HtmlTagDelimiter}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,26 +1,26 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public static class RuleFormats
|
||||
{
|
||||
public static string JavaScript;
|
||||
public static string ServerScript;
|
||||
|
||||
static RuleFormats()
|
||||
{
|
||||
const string script = @"(?xs)(<)(script)
|
||||
{0}[\s\n]+({1})[\s\n]*(=)[\s\n]*(""{2}""){0}[\s\n]*(>)
|
||||
(.*?)
|
||||
(</)(script)(>)";
|
||||
|
||||
const string attributes = @"(?:[\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(script, attributes, "type|language", "[^\n]*javascript");
|
||||
ServerScript = string.Format(script, attributes, "runat", "server");
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
namespace ColorCode.Compilation
|
||||
{
|
||||
public static class RuleFormats
|
||||
{
|
||||
public static string JavaScript;
|
||||
public static string ServerScript;
|
||||
|
||||
static RuleFormats()
|
||||
{
|
||||
const string script = @"(?xs)(<)(script)
|
||||
{0}[\s\n]+({1})[\s\n]*(=)[\s\n]*(""{2}""){0}[\s\n]*(>)
|
||||
(.*?)
|
||||
(</)(script)(>)";
|
||||
|
||||
const string attributes = @"(?:[\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(script, attributes, "type|language", "[^\n]*javascript");
|
||||
ServerScript = string.Format(script, attributes, "runat", "server");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +1,42 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines how ColorCode will parse the source code of a given language.
|
||||
/// </summary>
|
||||
public interface ILanguage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the identifier of the language (e.g., csharp).
|
||||
/// </summary>
|
||||
string Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first line pattern (regex) to use when determining if the language matches a source text.
|
||||
/// </summary>
|
||||
string FirstLinePattern { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the "friendly" name of the language (e.g., C#).
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of language rules in the language.
|
||||
/// </summary>
|
||||
IList<LanguageRule> Rules { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the CSS class name to use for a language
|
||||
/// </summary>
|
||||
string CssClassName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the specified string is an alias for the language
|
||||
/// </summary>
|
||||
bool HasAlias(string lang);
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines how ColorCode will parse the source code of a given language.
|
||||
/// </summary>
|
||||
public interface ILanguage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the identifier of the language (e.g., csharp).
|
||||
/// </summary>
|
||||
string Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first line pattern (regex) to use when determining if the language matches a source text.
|
||||
/// </summary>
|
||||
string FirstLinePattern { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the "friendly" name of the language (e.g., C#).
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of language rules in the language.
|
||||
/// </summary>
|
||||
IList<LanguageRule> Rules { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the CSS class name to use for a language
|
||||
/// </summary>
|
||||
string CssClassName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the specified string is an alias for the language
|
||||
/// </summary>
|
||||
bool HasAlias(string lang);
|
||||
}
|
||||
}
|
|
@ -1,39 +1,39 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a single rule for a language. For instance a language rule might define string literals for a given language.
|
||||
/// </summary>
|
||||
public class LanguageRule
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LanguageRule"/> class.
|
||||
/// </summary>
|
||||
/// <param name="regex">The regular expression that defines what the language rule matches and captures.</param>
|
||||
/// <param name="captures">The scope indices and names of the regular expression's captures.</param>
|
||||
public LanguageRule(string regex,
|
||||
IDictionary<int, string> captures)
|
||||
{
|
||||
Guard.ArgNotNullAndNotEmpty(regex, "regex");
|
||||
Guard.EnsureParameterIsNotNullAndNotEmpty(captures, "captures");
|
||||
|
||||
Regex = regex;
|
||||
Captures = captures;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the regular expression that defines what the language rule matches and captures.
|
||||
/// </summary>
|
||||
/// <value>The regular expression that defines what the language rule matches and captures.</value>
|
||||
public string Regex { get; private set; }
|
||||
/// <summary>
|
||||
/// Gets the scope indices and names of the regular expression's captures.
|
||||
/// </summary>
|
||||
/// <value>The scope indices and names of the regular expression's captures.</value>
|
||||
public IDictionary<int, string> Captures { get; private set; }
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a single rule for a language. For instance a language rule might define string literals for a given language.
|
||||
/// </summary>
|
||||
public class LanguageRule
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LanguageRule"/> class.
|
||||
/// </summary>
|
||||
/// <param name="regex">The regular expression that defines what the language rule matches and captures.</param>
|
||||
/// <param name="captures">The scope indices and names of the regular expression's captures.</param>
|
||||
public LanguageRule(string regex,
|
||||
IDictionary<int, string> captures)
|
||||
{
|
||||
Guard.ArgNotNullAndNotEmpty(regex, "regex");
|
||||
Guard.EnsureParameterIsNotNullAndNotEmpty(captures, "captures");
|
||||
|
||||
Regex = regex;
|
||||
Captures = captures;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the regular expression that defines what the language rule matches and captures.
|
||||
/// </summary>
|
||||
/// <value>The regular expression that defines what the language rule matches and captures.</value>
|
||||
public string Regex { get; private set; }
|
||||
/// <summary>
|
||||
/// Gets the scope indices and names of the regular expression's captures.
|
||||
/// </summary>
|
||||
/// <value>The scope indices and names of the regular expression's captures.</value>
|
||||
public IDictionary<int, string> Captures { get; private set; }
|
||||
}
|
||||
}
|
|
@ -1,273 +1,273 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
using ColorCode.Compilation;
|
||||
using ColorCode.Compilation.Languages;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides easy access to ColorCode's built-in languages, as well as methods to load and find custom languages.
|
||||
/// </summary>
|
||||
public static class Languages
|
||||
{
|
||||
internal static readonly LanguageRepository LanguageRepository;
|
||||
internal static readonly Dictionary<string, ILanguage> LoadedLanguages;
|
||||
internal static Dictionary<string, CompiledLanguage> CompiledLanguages;
|
||||
|
||||
static Languages()
|
||||
{
|
||||
LoadedLanguages = new Dictionary<string, ILanguage>();
|
||||
CompiledLanguages = new Dictionary<string, CompiledLanguage>();
|
||||
LanguageRepository = new LanguageRepository(LoadedLanguages);
|
||||
|
||||
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<PowerShell>();
|
||||
Load<Typescript>();
|
||||
Load<FSharp>();
|
||||
Load<Koka>();
|
||||
Load<Haskell>();
|
||||
Load<Markdown>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an enumerable list of all loaded languages.
|
||||
/// </summary>
|
||||
public static IEnumerable<ILanguage> All
|
||||
{
|
||||
get { return LanguageRepository.All; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET HTTP Handlers (.ashx files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET HTTP Handlers (.ashx files).</value>
|
||||
public static ILanguage Ashx
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Ashx); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET application files (.asax files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET application files (.asax files).</value>
|
||||
public static ILanguage Asax
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Asax); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET pages (.aspx files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET pages (.aspx files).</value>
|
||||
public static ILanguage Aspx
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Aspx); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET C# code-behind files (.aspx.cs files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET C# code-behind files (.aspx.cs files).</value>
|
||||
public static ILanguage AspxCs
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.AspxCs); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET Visual Basic.NET code-behind files (.aspx.vb files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET Visual Basic.NET code-behind files (.aspx.vb files).</value>
|
||||
public static ILanguage AspxVb
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.AspxVb); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for C#.
|
||||
/// </summary>
|
||||
/// <value>Language support for C#.</value>
|
||||
public static ILanguage CSharp
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.CSharp); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for HTML.
|
||||
/// </summary>
|
||||
/// <value>Language support for HTML.</value>
|
||||
public static ILanguage Html
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Html); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Java.
|
||||
/// </summary>
|
||||
/// <value>Language support for Java.</value>
|
||||
public static ILanguage Java
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Java); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for JavaScript.
|
||||
/// </summary>
|
||||
/// <value>Language support for JavaScript.</value>
|
||||
public static ILanguage JavaScript
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.JavaScript); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for PowerShell
|
||||
/// </summary>
|
||||
/// <value>Language support for PowerShell.</value>
|
||||
public static ILanguage PowerShell
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.PowerShell); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for SQL.
|
||||
/// </summary>
|
||||
/// <value>Language support for SQL.</value>
|
||||
public static ILanguage Sql
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Sql); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Visual Basic.NET.
|
||||
/// </summary>
|
||||
/// <value>Language support for Visual Basic.NET.</value>
|
||||
public static ILanguage VbDotNet
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.VbDotNet); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for XML.
|
||||
/// </summary>
|
||||
/// <value>Language support for XML.</value>
|
||||
public static ILanguage Xml
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Xml); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for PHP.
|
||||
/// </summary>
|
||||
/// <value>Language support for PHP.</value>
|
||||
public static ILanguage Php
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Php); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for CSS.
|
||||
/// </summary>
|
||||
/// <value>Language support for CSS.</value>
|
||||
public static ILanguage Css
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Css); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for C++.
|
||||
/// </summary>
|
||||
/// <value>Language support for C++.</value>
|
||||
public static ILanguage Cpp
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Cpp); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Typescript.
|
||||
/// </summary>
|
||||
/// <value>Language support for typescript.</value>
|
||||
public static ILanguage Typescript
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.TypeScript); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for F#.
|
||||
/// </summary>
|
||||
/// <value>Language support for F#.</value>
|
||||
public static ILanguage FSharp
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.FSharp); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Koka.
|
||||
/// </summary>
|
||||
/// <value>Language support for Koka.</value>
|
||||
public static ILanguage Koka
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Koka); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Haskell.
|
||||
/// </summary>
|
||||
/// <value>Language support for Haskell.</value>
|
||||
public static ILanguage Haskell
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Haskell); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Markdown.
|
||||
/// </summary>
|
||||
/// <value>Language support for Markdown.</value>
|
||||
public static ILanguage Markdown
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Markdown); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds a loaded language by the specified identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the language to find.</param>
|
||||
/// <returns>An <see cref="ILanguage" /> instance if the specified identifier matches a loaded language; otherwise, null.</returns>
|
||||
public static ILanguage FindById(string id)
|
||||
{
|
||||
return LanguageRepository.FindById(id);
|
||||
}
|
||||
|
||||
private static void Load<T>()
|
||||
where T : ILanguage, new()
|
||||
{
|
||||
Load(new T());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the specified language.
|
||||
/// </summary>
|
||||
/// <param name="language">The language to load.</param>
|
||||
/// <remarks>
|
||||
/// If a language with the same identifier has already been loaded, the existing loaded language will be replaced by the new specified language.
|
||||
/// </remarks>
|
||||
public static void Load(ILanguage language)
|
||||
{
|
||||
LanguageRepository.Load(language);
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
using ColorCode.Compilation;
|
||||
using ColorCode.Compilation.Languages;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides easy access to ColorCode's built-in languages, as well as methods to load and find custom languages.
|
||||
/// </summary>
|
||||
public static class Languages
|
||||
{
|
||||
internal static readonly LanguageRepository LanguageRepository;
|
||||
internal static readonly Dictionary<string, ILanguage> LoadedLanguages;
|
||||
internal static Dictionary<string, CompiledLanguage> CompiledLanguages;
|
||||
|
||||
static Languages()
|
||||
{
|
||||
LoadedLanguages = new Dictionary<string, ILanguage>();
|
||||
CompiledLanguages = new Dictionary<string, CompiledLanguage>();
|
||||
LanguageRepository = new LanguageRepository(LoadedLanguages);
|
||||
|
||||
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<PowerShell>();
|
||||
Load<Typescript>();
|
||||
Load<FSharp>();
|
||||
Load<Koka>();
|
||||
Load<Haskell>();
|
||||
Load<Markdown>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an enumerable list of all loaded languages.
|
||||
/// </summary>
|
||||
public static IEnumerable<ILanguage> All
|
||||
{
|
||||
get { return LanguageRepository.All; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET HTTP Handlers (.ashx files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET HTTP Handlers (.ashx files).</value>
|
||||
public static ILanguage Ashx
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Ashx); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET application files (.asax files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET application files (.asax files).</value>
|
||||
public static ILanguage Asax
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Asax); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET pages (.aspx files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET pages (.aspx files).</value>
|
||||
public static ILanguage Aspx
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Aspx); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET C# code-behind files (.aspx.cs files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET C# code-behind files (.aspx.cs files).</value>
|
||||
public static ILanguage AspxCs
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.AspxCs); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for ASP.NET Visual Basic.NET code-behind files (.aspx.vb files).
|
||||
/// </summary>
|
||||
/// <value>Language support for ASP.NET Visual Basic.NET code-behind files (.aspx.vb files).</value>
|
||||
public static ILanguage AspxVb
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.AspxVb); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for C#.
|
||||
/// </summary>
|
||||
/// <value>Language support for C#.</value>
|
||||
public static ILanguage CSharp
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.CSharp); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for HTML.
|
||||
/// </summary>
|
||||
/// <value>Language support for HTML.</value>
|
||||
public static ILanguage Html
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Html); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Java.
|
||||
/// </summary>
|
||||
/// <value>Language support for Java.</value>
|
||||
public static ILanguage Java
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Java); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for JavaScript.
|
||||
/// </summary>
|
||||
/// <value>Language support for JavaScript.</value>
|
||||
public static ILanguage JavaScript
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.JavaScript); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for PowerShell
|
||||
/// </summary>
|
||||
/// <value>Language support for PowerShell.</value>
|
||||
public static ILanguage PowerShell
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.PowerShell); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for SQL.
|
||||
/// </summary>
|
||||
/// <value>Language support for SQL.</value>
|
||||
public static ILanguage Sql
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Sql); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Visual Basic.NET.
|
||||
/// </summary>
|
||||
/// <value>Language support for Visual Basic.NET.</value>
|
||||
public static ILanguage VbDotNet
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.VbDotNet); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for XML.
|
||||
/// </summary>
|
||||
/// <value>Language support for XML.</value>
|
||||
public static ILanguage Xml
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Xml); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for PHP.
|
||||
/// </summary>
|
||||
/// <value>Language support for PHP.</value>
|
||||
public static ILanguage Php
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Php); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for CSS.
|
||||
/// </summary>
|
||||
/// <value>Language support for CSS.</value>
|
||||
public static ILanguage Css
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Css); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for C++.
|
||||
/// </summary>
|
||||
/// <value>Language support for C++.</value>
|
||||
public static ILanguage Cpp
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Cpp); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Typescript.
|
||||
/// </summary>
|
||||
/// <value>Language support for typescript.</value>
|
||||
public static ILanguage Typescript
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.TypeScript); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for F#.
|
||||
/// </summary>
|
||||
/// <value>Language support for F#.</value>
|
||||
public static ILanguage FSharp
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.FSharp); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Koka.
|
||||
/// </summary>
|
||||
/// <value>Language support for Koka.</value>
|
||||
public static ILanguage Koka
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Koka); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Haskell.
|
||||
/// </summary>
|
||||
/// <value>Language support for Haskell.</value>
|
||||
public static ILanguage Haskell
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Haskell); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language support for Markdown.
|
||||
/// </summary>
|
||||
/// <value>Language support for Markdown.</value>
|
||||
public static ILanguage Markdown
|
||||
{
|
||||
get { return LanguageRepository.FindById(LanguageId.Markdown); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds a loaded language by the specified identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the language to find.</param>
|
||||
/// <returns>An <see cref="ILanguage" /> instance if the specified identifier matches a loaded language; otherwise, null.</returns>
|
||||
public static ILanguage FindById(string id)
|
||||
{
|
||||
return LanguageRepository.FindById(id);
|
||||
}
|
||||
|
||||
private static void Load<T>()
|
||||
where T : ILanguage, new()
|
||||
{
|
||||
Load(new T());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the specified language.
|
||||
/// </summary>
|
||||
/// <param name="language">The language to load.</param>
|
||||
/// <remarks>
|
||||
/// If a language with the same identifier has already been loaded, the existing loaded language will be replaced by the new specified language.
|
||||
/// </remarks>
|
||||
public static void Load(ILanguage language)
|
||||
{
|
||||
LanguageRepository.Load(language);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode.Parsing
|
||||
{
|
||||
public interface ILanguageParser
|
||||
{
|
||||
void Parse(string sourceCode,
|
||||
ILanguage language,
|
||||
Action<string, IList<Scope>> parseHandler);
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode.Parsing
|
||||
{
|
||||
public interface ILanguageParser
|
||||
{
|
||||
void Parse(string sourceCode,
|
||||
ILanguage language,
|
||||
Action<string, IList<Scope>> parseHandler);
|
||||
}
|
||||
}
|
|
@ -1,199 +1,199 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using ColorCode.Common;
|
||||
using ColorCode.Compilation;
|
||||
|
||||
namespace ColorCode.Parsing
|
||||
{
|
||||
public class LanguageParser : ILanguageParser
|
||||
{
|
||||
private readonly ILanguageCompiler languageCompiler;
|
||||
private readonly ILanguageRepository languageRepository;
|
||||
|
||||
public LanguageParser(ILanguageCompiler languageCompiler,
|
||||
ILanguageRepository languageRepository)
|
||||
{
|
||||
this.languageCompiler = languageCompiler;
|
||||
this.languageRepository = languageRepository;
|
||||
}
|
||||
|
||||
public void Parse(string sourceCode,
|
||||
ILanguage language,
|
||||
Action<string, IList<Scope>> parseHandler)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sourceCode))
|
||||
return;
|
||||
|
||||
CompiledLanguage compiledLanguage = languageCompiler.Compile(language);
|
||||
|
||||
Parse(sourceCode, compiledLanguage, parseHandler);
|
||||
}
|
||||
|
||||
private void Parse(string sourceCode,
|
||||
CompiledLanguage compiledLanguage,
|
||||
Action<string, IList<Scope>> parseHandler)
|
||||
{
|
||||
Match regexMatch = compiledLanguage.Regex.Match(sourceCode);
|
||||
|
||||
if (!regexMatch.Success)
|
||||
parseHandler(sourceCode, new List<Scope>());
|
||||
else
|
||||
{
|
||||
int currentIndex = 0;
|
||||
|
||||
while (regexMatch.Success)
|
||||
{
|
||||
string sourceCodeBeforeMatch = sourceCode.Substring(currentIndex, regexMatch.Index - currentIndex);
|
||||
if (!string.IsNullOrEmpty(sourceCodeBeforeMatch))
|
||||
parseHandler(sourceCodeBeforeMatch, new List<Scope>());
|
||||
|
||||
string matchedSourceCode = sourceCode.Substring(regexMatch.Index, regexMatch.Length);
|
||||
if (!string.IsNullOrEmpty(matchedSourceCode))
|
||||
{
|
||||
List<Scope> capturedStylesForMatchedFragment = GetCapturedStyles(regexMatch, regexMatch.Index, compiledLanguage);
|
||||
List<Scope> capturedStyleTree = CreateCapturedStyleTree(capturedStylesForMatchedFragment);
|
||||
parseHandler(matchedSourceCode, capturedStyleTree);
|
||||
}
|
||||
|
||||
currentIndex = regexMatch.Index + regexMatch.Length;
|
||||
regexMatch = regexMatch.NextMatch();
|
||||
}
|
||||
|
||||
string sourceCodeAfterAllMatches = sourceCode.Substring(currentIndex);
|
||||
if (!string.IsNullOrEmpty(sourceCodeAfterAllMatches))
|
||||
parseHandler(sourceCodeAfterAllMatches, new List<Scope>());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Scope> CreateCapturedStyleTree(IList<Scope> capturedStyles)
|
||||
{
|
||||
capturedStyles.SortStable((x, y) => x.Index.CompareTo(y.Index));
|
||||
|
||||
var capturedStyleTree = new List<Scope>(capturedStyles.Count);
|
||||
Scope currentScope = null;
|
||||
|
||||
foreach (Scope capturedStyle in capturedStyles)
|
||||
{
|
||||
if (currentScope == null)
|
||||
{
|
||||
capturedStyleTree.Add(capturedStyle);
|
||||
currentScope = capturedStyle;
|
||||
continue;
|
||||
}
|
||||
|
||||
AddScopeToNestedScopes(capturedStyle, ref currentScope, capturedStyleTree);
|
||||
}
|
||||
|
||||
return capturedStyleTree;
|
||||
}
|
||||
|
||||
private static void AddScopeToNestedScopes(Scope scope,
|
||||
ref Scope currentScope,
|
||||
ICollection<Scope> capturedStyleTree)
|
||||
{
|
||||
if (scope.Index >= currentScope.Index && (scope.Index + scope.Length <= currentScope.Index + currentScope.Length))
|
||||
{
|
||||
currentScope.AddChild(scope);
|
||||
currentScope = scope;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentScope = currentScope.Parent;
|
||||
|
||||
if (currentScope != null)
|
||||
AddScopeToNestedScopes(scope, ref currentScope, capturedStyleTree);
|
||||
else
|
||||
capturedStyleTree.Add(scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<Scope> GetCapturedStyles(Match regexMatch,
|
||||
int currentIndex,
|
||||
CompiledLanguage compiledLanguage)
|
||||
{
|
||||
var capturedStyles = new List<Scope>();
|
||||
|
||||
for (int i = 0; i < regexMatch.Groups.Count; i++)
|
||||
{
|
||||
Group regexGroup = regexMatch.Groups[i];
|
||||
if (regexGroup.Length > 0 && i < compiledLanguage.Captures.Count) { //note: i can be >= Captures.Count due to named groups; these do capture a group but always get added after all non-named groups (which is why we do not count them in numberOfCaptures)
|
||||
string styleName = compiledLanguage.Captures[i];
|
||||
if (!String.IsNullOrEmpty(styleName)) {
|
||||
foreach (Capture regexCapture in regexGroup.Captures)
|
||||
AppendCapturedStylesForRegexCapture(regexCapture, currentIndex, styleName, capturedStyles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return capturedStyles;
|
||||
}
|
||||
|
||||
private void AppendCapturedStylesForRegexCapture(Capture regexCapture,
|
||||
int currentIndex,
|
||||
string styleName,
|
||||
ICollection<Scope> capturedStyles)
|
||||
{
|
||||
if (styleName.StartsWith(ScopeName.LanguagePrefix))
|
||||
{
|
||||
string nestedGrammarId = styleName.Substring(1);
|
||||
AppendCapturedStylesForNestedLanguage(regexCapture, regexCapture.Index - currentIndex, nestedGrammarId, capturedStyles);
|
||||
}
|
||||
else
|
||||
capturedStyles.Add(new Scope(styleName, regexCapture.Index - currentIndex, regexCapture.Length));
|
||||
}
|
||||
|
||||
private void AppendCapturedStylesForNestedLanguage(Capture regexCapture,
|
||||
int offset,
|
||||
string nestedLanguageId,
|
||||
ICollection<Scope> capturedStyles)
|
||||
{
|
||||
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 regexMatch = nestedCompiledLanguage.Regex.Match(regexCapture.Value, 0, regexCapture.Value.Length);
|
||||
|
||||
if (!regexMatch.Success)
|
||||
return;
|
||||
else
|
||||
{
|
||||
while (regexMatch.Success)
|
||||
{
|
||||
List<Scope> capturedStylesForMatchedFragment = GetCapturedStyles(regexMatch, 0, nestedCompiledLanguage);
|
||||
List<Scope> capturedStyleTree = CreateCapturedStyleTree(capturedStylesForMatchedFragment);
|
||||
|
||||
foreach (Scope nestedCapturedStyle in capturedStyleTree)
|
||||
{
|
||||
IncreaseCapturedStyleIndicies(capturedStyleTree, offset);
|
||||
capturedStyles.Add(nestedCapturedStyle);
|
||||
}
|
||||
|
||||
regexMatch = regexMatch.NextMatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void IncreaseCapturedStyleIndicies(IList<Scope> capturedStyles,
|
||||
int amountToIncrease)
|
||||
{
|
||||
for (int i = 0; i < capturedStyles.Count; i++)
|
||||
{
|
||||
Scope scope = capturedStyles[i];
|
||||
|
||||
scope.Index += amountToIncrease;
|
||||
|
||||
if (scope.Children.Count > 0)
|
||||
IncreaseCapturedStyleIndicies(scope.Children, amountToIncrease);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using ColorCode.Common;
|
||||
using ColorCode.Compilation;
|
||||
|
||||
namespace ColorCode.Parsing
|
||||
{
|
||||
public class LanguageParser : ILanguageParser
|
||||
{
|
||||
private readonly ILanguageCompiler languageCompiler;
|
||||
private readonly ILanguageRepository languageRepository;
|
||||
|
||||
public LanguageParser(ILanguageCompiler languageCompiler,
|
||||
ILanguageRepository languageRepository)
|
||||
{
|
||||
this.languageCompiler = languageCompiler;
|
||||
this.languageRepository = languageRepository;
|
||||
}
|
||||
|
||||
public void Parse(string sourceCode,
|
||||
ILanguage language,
|
||||
Action<string, IList<Scope>> parseHandler)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sourceCode))
|
||||
return;
|
||||
|
||||
CompiledLanguage compiledLanguage = languageCompiler.Compile(language);
|
||||
|
||||
Parse(sourceCode, compiledLanguage, parseHandler);
|
||||
}
|
||||
|
||||
private void Parse(string sourceCode,
|
||||
CompiledLanguage compiledLanguage,
|
||||
Action<string, IList<Scope>> parseHandler)
|
||||
{
|
||||
Match regexMatch = compiledLanguage.Regex.Match(sourceCode);
|
||||
|
||||
if (!regexMatch.Success)
|
||||
parseHandler(sourceCode, new List<Scope>());
|
||||
else
|
||||
{
|
||||
int currentIndex = 0;
|
||||
|
||||
while (regexMatch.Success)
|
||||
{
|
||||
string sourceCodeBeforeMatch = sourceCode.Substring(currentIndex, regexMatch.Index - currentIndex);
|
||||
if (!string.IsNullOrEmpty(sourceCodeBeforeMatch))
|
||||
parseHandler(sourceCodeBeforeMatch, new List<Scope>());
|
||||
|
||||
string matchedSourceCode = sourceCode.Substring(regexMatch.Index, regexMatch.Length);
|
||||
if (!string.IsNullOrEmpty(matchedSourceCode))
|
||||
{
|
||||
List<Scope> capturedStylesForMatchedFragment = GetCapturedStyles(regexMatch, regexMatch.Index, compiledLanguage);
|
||||
List<Scope> capturedStyleTree = CreateCapturedStyleTree(capturedStylesForMatchedFragment);
|
||||
parseHandler(matchedSourceCode, capturedStyleTree);
|
||||
}
|
||||
|
||||
currentIndex = regexMatch.Index + regexMatch.Length;
|
||||
regexMatch = regexMatch.NextMatch();
|
||||
}
|
||||
|
||||
string sourceCodeAfterAllMatches = sourceCode.Substring(currentIndex);
|
||||
if (!string.IsNullOrEmpty(sourceCodeAfterAllMatches))
|
||||
parseHandler(sourceCodeAfterAllMatches, new List<Scope>());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Scope> CreateCapturedStyleTree(IList<Scope> capturedStyles)
|
||||
{
|
||||
capturedStyles.SortStable((x, y) => x.Index.CompareTo(y.Index));
|
||||
|
||||
var capturedStyleTree = new List<Scope>(capturedStyles.Count);
|
||||
Scope currentScope = null;
|
||||
|
||||
foreach (Scope capturedStyle in capturedStyles)
|
||||
{
|
||||
if (currentScope == null)
|
||||
{
|
||||
capturedStyleTree.Add(capturedStyle);
|
||||
currentScope = capturedStyle;
|
||||
continue;
|
||||
}
|
||||
|
||||
AddScopeToNestedScopes(capturedStyle, ref currentScope, capturedStyleTree);
|
||||
}
|
||||
|
||||
return capturedStyleTree;
|
||||
}
|
||||
|
||||
private static void AddScopeToNestedScopes(Scope scope,
|
||||
ref Scope currentScope,
|
||||
ICollection<Scope> capturedStyleTree)
|
||||
{
|
||||
if (scope.Index >= currentScope.Index && (scope.Index + scope.Length <= currentScope.Index + currentScope.Length))
|
||||
{
|
||||
currentScope.AddChild(scope);
|
||||
currentScope = scope;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentScope = currentScope.Parent;
|
||||
|
||||
if (currentScope != null)
|
||||
AddScopeToNestedScopes(scope, ref currentScope, capturedStyleTree);
|
||||
else
|
||||
capturedStyleTree.Add(scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<Scope> GetCapturedStyles(Match regexMatch,
|
||||
int currentIndex,
|
||||
CompiledLanguage compiledLanguage)
|
||||
{
|
||||
var capturedStyles = new List<Scope>();
|
||||
|
||||
for (int i = 0; i < regexMatch.Groups.Count; i++)
|
||||
{
|
||||
Group regexGroup = regexMatch.Groups[i];
|
||||
if (regexGroup.Length > 0 && i < compiledLanguage.Captures.Count) { //note: i can be >= Captures.Count due to named groups; these do capture a group but always get added after all non-named groups (which is why we do not count them in numberOfCaptures)
|
||||
string styleName = compiledLanguage.Captures[i];
|
||||
if (!String.IsNullOrEmpty(styleName)) {
|
||||
foreach (Capture regexCapture in regexGroup.Captures)
|
||||
AppendCapturedStylesForRegexCapture(regexCapture, currentIndex, styleName, capturedStyles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return capturedStyles;
|
||||
}
|
||||
|
||||
private void AppendCapturedStylesForRegexCapture(Capture regexCapture,
|
||||
int currentIndex,
|
||||
string styleName,
|
||||
ICollection<Scope> capturedStyles)
|
||||
{
|
||||
if (styleName.StartsWith(ScopeName.LanguagePrefix))
|
||||
{
|
||||
string nestedGrammarId = styleName.Substring(1);
|
||||
AppendCapturedStylesForNestedLanguage(regexCapture, regexCapture.Index - currentIndex, nestedGrammarId, capturedStyles);
|
||||
}
|
||||
else
|
||||
capturedStyles.Add(new Scope(styleName, regexCapture.Index - currentIndex, regexCapture.Length));
|
||||
}
|
||||
|
||||
private void AppendCapturedStylesForNestedLanguage(Capture regexCapture,
|
||||
int offset,
|
||||
string nestedLanguageId,
|
||||
ICollection<Scope> capturedStyles)
|
||||
{
|
||||
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 regexMatch = nestedCompiledLanguage.Regex.Match(regexCapture.Value, 0, regexCapture.Value.Length);
|
||||
|
||||
if (!regexMatch.Success)
|
||||
return;
|
||||
else
|
||||
{
|
||||
while (regexMatch.Success)
|
||||
{
|
||||
List<Scope> capturedStylesForMatchedFragment = GetCapturedStyles(regexMatch, 0, nestedCompiledLanguage);
|
||||
List<Scope> capturedStyleTree = CreateCapturedStyleTree(capturedStylesForMatchedFragment);
|
||||
|
||||
foreach (Scope nestedCapturedStyle in capturedStyleTree)
|
||||
{
|
||||
IncreaseCapturedStyleIndicies(capturedStyleTree, offset);
|
||||
capturedStyles.Add(nestedCapturedStyle);
|
||||
}
|
||||
|
||||
regexMatch = regexMatch.NextMatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void IncreaseCapturedStyleIndicies(IList<Scope> capturedStyles,
|
||||
int amountToIncrease)
|
||||
{
|
||||
for (int i = 0; i < capturedStyles.Count; i++)
|
||||
{
|
||||
Scope scope = capturedStyles[i];
|
||||
|
||||
scope.Index += amountToIncrease;
|
||||
|
||||
if (scope.Children.Count > 0)
|
||||
IncreaseCapturedStyleIndicies(scope.Children, amountToIncrease);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,39 +1,39 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Parsing
|
||||
{
|
||||
public class Scope
|
||||
{
|
||||
public Scope(string name,
|
||||
int index,
|
||||
int length)
|
||||
{
|
||||
Guard.ArgNotNullAndNotEmpty(name, "name");
|
||||
|
||||
Name = name;
|
||||
Index = index;
|
||||
Length = length;
|
||||
Children = new List<Scope>();
|
||||
}
|
||||
|
||||
public IList<Scope> Children { get; set; }
|
||||
public int Index { get; set; }
|
||||
public int Length { get; set; }
|
||||
public Scope Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public void AddChild(Scope childScope)
|
||||
{
|
||||
if (childScope.Parent != null)
|
||||
throw new InvalidOperationException("The child scope already has a parent.");
|
||||
|
||||
childScope.Parent = this;
|
||||
|
||||
Children.Add(childScope);
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Parsing
|
||||
{
|
||||
public class Scope
|
||||
{
|
||||
public Scope(string name,
|
||||
int index,
|
||||
int length)
|
||||
{
|
||||
Guard.ArgNotNullAndNotEmpty(name, "name");
|
||||
|
||||
Name = name;
|
||||
Index = index;
|
||||
Length = length;
|
||||
Children = new List<Scope>();
|
||||
}
|
||||
|
||||
public IList<Scope> Children { get; set; }
|
||||
public int Index { get; set; }
|
||||
public int Length { get; set; }
|
||||
public Scope Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public void AddChild(Scope childScope)
|
||||
{
|
||||
if (childScope.Parent != null)
|
||||
throw new InvalidOperationException("The child scope already has a parent.");
|
||||
|
||||
childScope.Parent = this;
|
||||
|
||||
Children.Add(childScope);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Drawing;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode
|
||||
namespace ColorCode.Styling
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the styling for a given scope.
|
||||
|
@ -17,7 +16,7 @@ namespace ColorCode
|
|||
public Style(string scopeName)
|
||||
{
|
||||
Guard.ArgNotNullAndNotEmpty(scopeName, "scopeName");
|
||||
|
||||
|
||||
ScopeName = scopeName;
|
||||
}
|
||||
|
||||
|
@ -25,22 +24,25 @@ namespace ColorCode
|
|||
/// Gets or sets the background color.
|
||||
/// </summary>
|
||||
/// <value>The background color.</value>
|
||||
public Color Background { get; set; }
|
||||
public string Background { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the foreground color.
|
||||
/// </summary>
|
||||
/// <value>The foreground color.</value>
|
||||
public Color Foreground { get; set; }
|
||||
public string Foreground { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the scope the style defines.
|
||||
/// </summary>
|
||||
/// <value>The name of the scope the style defines.</value>
|
||||
public string ScopeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the CSS class.
|
||||
/// Gets or sets the reference name of the scope, such as in CSS.
|
||||
/// </summary>
|
||||
/// <value>The CSS class name.</value>
|
||||
public string CssClassName { get; set; }
|
||||
/// <value>The plain text Reference name.</value>
|
||||
public string ReferenceName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets italic font style.
|
|
@ -0,0 +1,291 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using ColorCode.Common;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace ColorCode.Styling
|
||||
{
|
||||
/// <summary>
|
||||
/// A dictionary of <see cref="Style" /> instances, keyed by the styles' scope name.
|
||||
/// </summary>
|
||||
public class StyleDictionary : KeyedCollection<string, Style>
|
||||
{
|
||||
/// <summary>
|
||||
/// When implemented in a derived class, extracts the key from the specified element.
|
||||
/// </summary>
|
||||
/// <param name="item">The element from which to extract the key.</param>
|
||||
/// <returns>The key for the specified element.</returns>
|
||||
protected override string GetKeyForItem(Style item)
|
||||
{
|
||||
return item.ScopeName;
|
||||
}
|
||||
|
||||
public static StyleDictionary Default
|
||||
{
|
||||
get
|
||||
{
|
||||
var blue = "#FF0000FF";
|
||||
var white = "#FFFFFFFF";
|
||||
var black = "#FF000000";
|
||||
var dullRed = "#FFA31515";
|
||||
var yellow = "#FFFFFF00";
|
||||
var green = "#FF008000";
|
||||
var powderBlue = "#FFB0E0E6";
|
||||
var teal = "#FF008080";
|
||||
var gray = "#FF808080";
|
||||
var navy = "#FF000080";
|
||||
var orangeRed = "#FFFF4500";
|
||||
var purple = "#FF800080";
|
||||
var red = "#FFFF0000";
|
||||
var mediumTurqoise = "FF48D1CC";
|
||||
var magenta = "FFFF00FF";
|
||||
|
||||
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.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.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"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netstandard1.4</TargetFramework>
|
||||
<RootNamespace>ColorCode</RootNamespace>
|
||||
<AssemblyName>ColorCode.HTML</AssemblyName>
|
||||
<Title>ColorCode.HTML</Title>
|
||||
<Description>Contains the HtmlFormatter, and the HtmlClassFormatter, for rendering Html from the Colorized Code.</Description>
|
||||
<PackageTags>ColorCode Syntax Highlighting SyntaxHighlighting HTML SyntaxToHTML HTMLFormatting Formatting</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ColorCode\ColorCode.csproj" />
|
||||
<ProjectReference Include="..\ColorCode.Core\ColorCode.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,22 +1,16 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ColorCode.HTML.Common
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
{
|
||||
public static string ToHtmlColor(this Color color)
|
||||
public static string ToHtmlColor(this string color)
|
||||
{
|
||||
if (color == Color.Empty)
|
||||
throw new ArgumentException("You may not create a hex string from an empty color.");
|
||||
if (color == null) return null;
|
||||
|
||||
return string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}",
|
||||
color.A,
|
||||
color.R,
|
||||
color.G,
|
||||
color.B);
|
||||
var length = 6;
|
||||
var start = color.Length - length;
|
||||
return "#" + color.Substring(start, length);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,28 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using ColorCode.Common;
|
||||
using ColorCode.Parsing;
|
||||
using System.Text;
|
||||
using ColorCode.Styling;
|
||||
using System.Net;
|
||||
using ColorCode.HTML.Common;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="HtmlClassFormatter"/>, for creating HTML to display Syntax Highlighted code.
|
||||
/// </summary>
|
||||
public class HtmlClassFormatter : CodeColorizerBase
|
||||
{
|
||||
public HtmlClassFormatter(IStyleSheet styleSheet = null) : base()
|
||||
/// <summary>
|
||||
/// Creates a <see cref="HtmlClassFormatter"/>, for creating HTML to display Syntax Highlighted code, with Styles applied via CSS.
|
||||
/// </summary>
|
||||
/// <param name="Style">The Custom styles to Apply to the formatted Code.</param>
|
||||
/// <param name="languageParser">The language parser that the <see cref="HtmlClassFormatter"/> instance will use for its lifetime.</param>
|
||||
public HtmlClassFormatter(StyleDictionary Style = null, ILanguageParser languageParser = null) : base(Style, languageParser)
|
||||
{
|
||||
StyleSheet = styleSheet ?? StyleSheets.Default;
|
||||
}
|
||||
|
||||
public HtmlClassFormatter(ILanguageParser Parser, IStyleSheet styleSheet = null) : base(Parser)
|
||||
{
|
||||
StyleSheet = styleSheet ?? StyleSheets.Default;
|
||||
}
|
||||
|
||||
public IStyleSheet StyleSheet { get; }
|
||||
private TextWriter Writer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates the HTML Markup, which can be saved to a .html file.
|
||||
/// </summary>
|
||||
/// <param name="sourceCode">The source code to colorize.</param>
|
||||
/// <param name="language">The language to use to colorize the source code.</param>
|
||||
/// <returns>Colorised HTML Markup.</returns>
|
||||
public string GetHtmlString(string sourceCode, ILanguage language)
|
||||
{
|
||||
var buffer = new StringBuilder(sourceCode.Length * 2);
|
||||
|
@ -42,6 +51,37 @@ namespace ColorCode
|
|||
return buffer.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the CSS Markup, which can be saved to a .CSS file. <para/>
|
||||
/// This is required for Coloring the Html output. Be sure to reference the File from the HTML, or insert it inline to the Head.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetCSSString()
|
||||
{
|
||||
var str = new StringBuilder();
|
||||
|
||||
foreach (var style in Styles)
|
||||
{
|
||||
str.Append($" .{style.ReferenceName}{{");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(style.Foreground))
|
||||
str.Append($"color:{style.Foreground.ToHtmlColor()};");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(style.Background))
|
||||
str.Append($"color:{style.Background.ToHtmlColor()};");
|
||||
|
||||
if (style.Italic)
|
||||
str.Append("font-style: italic;");
|
||||
|
||||
if (style.Bold)
|
||||
str.Append("font-weight: bold;");
|
||||
|
||||
str.Append("}");
|
||||
}
|
||||
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
protected override void Write(string parsedSourceCode, IList<Scope> scopes)
|
||||
{
|
||||
var styleInsertions = new List<TextInsertion>();
|
||||
|
@ -55,15 +95,15 @@ namespace ColorCode
|
|||
|
||||
foreach (TextInsertion styleInsertion in styleInsertions)
|
||||
{
|
||||
Writer.Write(HttpUtility.HtmlEncode(parsedSourceCode.Substring(offset, styleInsertion.Index - offset)));
|
||||
Writer.Write(WebUtility.HtmlEncode(parsedSourceCode.Substring(offset, styleInsertion.Index - offset)));
|
||||
if (string.IsNullOrEmpty(styleInsertion.Text))
|
||||
BuildSpanForCapturedStyle(styleInsertion.Scope, StyleSheet, Writer);
|
||||
BuildSpanForCapturedStyle(styleInsertion.Scope);
|
||||
else
|
||||
Writer.Write(styleInsertion.Text);
|
||||
offset = styleInsertion.Index;
|
||||
}
|
||||
|
||||
Writer.Write(HttpUtility.HtmlEncode(parsedSourceCode.Substring(offset)));
|
||||
Writer.Write(WebUtility.HtmlEncode(parsedSourceCode.Substring(offset)));
|
||||
}
|
||||
|
||||
private void WriteFooter(ILanguage language)
|
||||
|
@ -71,16 +111,16 @@ namespace ColorCode
|
|||
Guard.ArgNotNull(language, "language");
|
||||
|
||||
Writer.WriteLine();
|
||||
WriteHeaderPreEnd(Writer);
|
||||
WriteHeaderDivEnd(Writer);
|
||||
WriteHeaderPreEnd();
|
||||
WriteHeaderDivEnd();
|
||||
}
|
||||
|
||||
private void WriteHeader(ILanguage language)
|
||||
{
|
||||
Guard.ArgNotNull(language, "language");
|
||||
|
||||
WriteHeaderDivStart(StyleSheet, language, Writer);
|
||||
WriteHeaderPreStart(Writer);
|
||||
WriteHeaderDivStart(language);
|
||||
WriteHeaderPreStart();
|
||||
Writer.WriteLine();
|
||||
}
|
||||
|
||||
|
@ -102,66 +142,58 @@ namespace ColorCode
|
|||
});
|
||||
}
|
||||
|
||||
private static void BuildSpanForCapturedStyle(Scope scope,
|
||||
IStyleSheet styleSheet,
|
||||
TextWriter writer)
|
||||
private void BuildSpanForCapturedStyle(Scope scope)
|
||||
{
|
||||
string cssClassName = "";
|
||||
|
||||
if (styleSheet.Styles.Contains(scope.Name))
|
||||
if (Styles.Contains(scope.Name))
|
||||
{
|
||||
Style style = styleSheet.Styles[scope.Name];
|
||||
Style style = Styles[scope.Name];
|
||||
|
||||
cssClassName = style.CssClassName;
|
||||
cssClassName = style.ReferenceName;
|
||||
}
|
||||
|
||||
WriteElementStart("span", cssClassName, writer);
|
||||
WriteElementStart("span", cssClassName);
|
||||
}
|
||||
|
||||
private static void WriteHeaderDivEnd(TextWriter writer)
|
||||
private void WriteHeaderDivEnd()
|
||||
{
|
||||
WriteElementEnd("div", writer);
|
||||
WriteElementEnd("div");
|
||||
}
|
||||
|
||||
private static void WriteElementEnd(string elementName,
|
||||
TextWriter writer)
|
||||
private void WriteElementEnd(string elementName)
|
||||
{
|
||||
writer.Write("</{0}>", elementName);
|
||||
Writer.Write("</{0}>", elementName);
|
||||
}
|
||||
|
||||
private static void WriteHeaderPreEnd(TextWriter writer)
|
||||
private void WriteHeaderPreEnd()
|
||||
{
|
||||
WriteElementEnd("pre", writer);
|
||||
WriteElementEnd("pre");
|
||||
}
|
||||
|
||||
private static void WriteHeaderPreStart(TextWriter writer)
|
||||
private void WriteHeaderPreStart()
|
||||
{
|
||||
WriteElementStart("pre", writer);
|
||||
WriteElementStart("pre");
|
||||
}
|
||||
|
||||
private static void WriteHeaderDivStart(IStyleSheet styleSheet,
|
||||
ILanguage language,
|
||||
TextWriter writer)
|
||||
private void WriteHeaderDivStart(ILanguage language)
|
||||
{
|
||||
WriteElementStart("div", language.CssClassName, writer);
|
||||
WriteElementStart("div", language.CssClassName);
|
||||
}
|
||||
|
||||
private static void WriteElementStart(string elementName,
|
||||
TextWriter writer)
|
||||
private void WriteElementStart(string elementName)
|
||||
{
|
||||
WriteElementStart(elementName, "", writer);
|
||||
WriteElementStart(elementName, "");
|
||||
}
|
||||
|
||||
private static void WriteElementStart(string elementName,
|
||||
string cssClassName,
|
||||
TextWriter writer)
|
||||
private void WriteElementStart(string elementName, string cssClassName)
|
||||
{
|
||||
writer.Write("<{0}", elementName);
|
||||
Writer.Write("<{0}", elementName);
|
||||
if (!String.IsNullOrEmpty(cssClassName))
|
||||
{
|
||||
writer.Write(" class=\"{0}\"", cssClassName);
|
||||
Writer.Write(" class=\"{0}\"", cssClassName);
|
||||
}
|
||||
writer.Write(">");
|
||||
Writer.Write(">");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +1,38 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using ColorCode.Common;
|
||||
using ColorCode.Parsing;
|
||||
using System.Text;
|
||||
using ColorCode.HTML.Common;
|
||||
using ColorCode.Styling;
|
||||
using System.Net;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="HtmlFormatter"/>, for creating HTML to display Syntax Highlighted code.
|
||||
/// </summary>
|
||||
public class HtmlFormatter : CodeColorizerBase
|
||||
{
|
||||
public HtmlFormatter(IStyleSheet styleSheet = null) : base()
|
||||
/// <summary>
|
||||
/// Creates a <see cref="HtmlFormatter"/>, for creating HTML to display Syntax Highlighted code.
|
||||
/// </summary>
|
||||
/// <param name="Style">The Custom styles to Apply to the formatted Code.</param>
|
||||
/// <param name="languageParser">The language parser that the <see cref="HtmlFormatter"/> instance will use for its lifetime.</param>
|
||||
public HtmlFormatter(StyleDictionary Style = null, ILanguageParser languageParser = null) : base(Style, languageParser)
|
||||
{
|
||||
StyleSheet = styleSheet ?? StyleSheets.Default;
|
||||
}
|
||||
|
||||
public HtmlFormatter(ILanguageParser Parser, IStyleSheet styleSheet = null) : base(Parser)
|
||||
{
|
||||
StyleSheet = styleSheet ?? StyleSheets.Default;
|
||||
}
|
||||
|
||||
public IStyleSheet StyleSheet { get; }
|
||||
private TextWriter Writer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates the HTML Markup, which can be saved to a .html file.
|
||||
/// </summary>
|
||||
/// <param name="sourceCode">The source code to colorize.</param>
|
||||
/// <param name="language">The language to use to colorize the source code.</param>
|
||||
/// <returns>Colorised HTML Markup.</returns>
|
||||
public string GetHtmlString(string sourceCode, ILanguage language)
|
||||
{
|
||||
var buffer = new StringBuilder(sourceCode.Length * 2);
|
||||
|
@ -58,32 +65,33 @@ namespace ColorCode
|
|||
|
||||
foreach (TextInsertion styleInsertion in styleInsertions)
|
||||
{
|
||||
Writer.Write(HttpUtility.HtmlEncode(parsedSourceCode.Substring(offset, styleInsertion.Index - offset)));
|
||||
var text = parsedSourceCode.Substring(offset, styleInsertion.Index - offset);
|
||||
Writer.Write(WebUtility.HtmlEncode(text));
|
||||
if (string.IsNullOrEmpty(styleInsertion.Text))
|
||||
BuildSpanForCapturedStyle(styleInsertion.Scope, StyleSheet, Writer);
|
||||
BuildSpanForCapturedStyle(styleInsertion.Scope);
|
||||
else
|
||||
Writer.Write(styleInsertion.Text);
|
||||
offset = styleInsertion.Index;
|
||||
}
|
||||
|
||||
Writer.Write(HttpUtility.HtmlEncode(parsedSourceCode.Substring(offset)));
|
||||
Writer.Write(WebUtility.HtmlEncode(parsedSourceCode.Substring(offset)));
|
||||
}
|
||||
|
||||
private void WriteFooter(ILanguage language)
|
||||
{
|
||||
Writer.WriteLine();
|
||||
WriteHeaderPreEnd(Writer);
|
||||
WriteHeaderDivEnd(Writer);
|
||||
WriteHeaderPreEnd();
|
||||
WriteHeaderDivEnd();
|
||||
}
|
||||
|
||||
private void WriteHeader(ILanguage language)
|
||||
{
|
||||
WriteHeaderDivStart(StyleSheet, Writer);
|
||||
WriteHeaderPreStart(Writer);
|
||||
WriteHeaderDivStart();
|
||||
WriteHeaderPreStart();
|
||||
Writer.WriteLine();
|
||||
}
|
||||
|
||||
private static void GetStyleInsertionsForCapturedStyle(Scope scope, ICollection<TextInsertion> styleInsertions)
|
||||
private void GetStyleInsertionsForCapturedStyle(Scope scope, ICollection<TextInsertion> styleInsertions)
|
||||
{
|
||||
styleInsertions.Add(new TextInsertion
|
||||
{
|
||||
|
@ -101,16 +109,16 @@ namespace ColorCode
|
|||
});
|
||||
}
|
||||
|
||||
private static void BuildSpanForCapturedStyle(Scope scope, IStyleSheet styleSheet, TextWriter writer)
|
||||
private void BuildSpanForCapturedStyle(Scope scope)
|
||||
{
|
||||
Color foreground = Color.Empty;
|
||||
Color background = Color.Empty;
|
||||
string foreground = string.Empty;
|
||||
string background = string.Empty;
|
||||
bool italic = false;
|
||||
bool bold = false;
|
||||
|
||||
if (styleSheet.Styles.Contains(scope.Name))
|
||||
if (Styles.Contains(scope.Name))
|
||||
{
|
||||
Style style = styleSheet.Styles[scope.Name];
|
||||
Style style = Styles[scope.Name];
|
||||
|
||||
foreground = style.Foreground;
|
||||
background = style.Background;
|
||||
|
@ -118,74 +126,69 @@ namespace ColorCode
|
|||
bold = style.Bold;
|
||||
}
|
||||
|
||||
WriteElementStart(writer, "span", foreground, background, italic, bold);
|
||||
WriteElementStart("span", foreground, background, italic, bold);
|
||||
}
|
||||
|
||||
private static void WriteHeaderDivEnd(TextWriter writer)
|
||||
private void WriteHeaderDivEnd()
|
||||
{
|
||||
WriteElementEnd("div", writer);
|
||||
WriteElementEnd("div");
|
||||
}
|
||||
|
||||
private static void WriteElementEnd(string elementName, TextWriter writer)
|
||||
private void WriteElementEnd(string elementName)
|
||||
{
|
||||
writer.Write("</{0}>", elementName);
|
||||
Writer.Write("</{0}>", elementName);
|
||||
}
|
||||
|
||||
private static void WriteHeaderPreEnd(TextWriter writer)
|
||||
private void WriteHeaderPreEnd()
|
||||
{
|
||||
WriteElementEnd("pre", writer);
|
||||
WriteElementEnd("pre");
|
||||
}
|
||||
|
||||
private static void WriteHeaderPreStart(TextWriter writer)
|
||||
private void WriteHeaderPreStart()
|
||||
{
|
||||
WriteElementStart(writer, "pre");
|
||||
WriteElementStart("pre");
|
||||
}
|
||||
|
||||
private static void WriteHeaderDivStart(IStyleSheet styleSheet, TextWriter writer)
|
||||
private void WriteHeaderDivStart()
|
||||
{
|
||||
Color foreground = Color.Empty;
|
||||
Color background = Color.Empty;
|
||||
string foreground = string.Empty;
|
||||
string background = string.Empty;
|
||||
|
||||
if (styleSheet.Styles.Contains(ScopeName.PlainText))
|
||||
if (Styles.Contains(ScopeName.PlainText))
|
||||
{
|
||||
Style plainTextStyle = styleSheet.Styles[ScopeName.PlainText];
|
||||
Style plainTextStyle = Styles[ScopeName.PlainText];
|
||||
|
||||
foreground = plainTextStyle.Foreground;
|
||||
background = plainTextStyle.Background;
|
||||
}
|
||||
|
||||
WriteElementStart(writer, "div", foreground, background);
|
||||
WriteElementStart("div", foreground, background);
|
||||
}
|
||||
|
||||
private static void WriteElementStart(TextWriter writer, string elementName)
|
||||
private void WriteElementStart(string elementName, string foreground = null, string background = null, bool italic = false, bool bold = false)
|
||||
{
|
||||
WriteElementStart(writer, elementName, Color.Empty, Color.Empty);
|
||||
}
|
||||
Writer.Write("<{0}", elementName);
|
||||
|
||||
private static void WriteElementStart(TextWriter writer, string elementName, Color foreground, Color background, bool italic = false, bool bold = false)
|
||||
{
|
||||
writer.Write("<{0}", elementName);
|
||||
|
||||
if (foreground != Color.Empty || background != Color.Empty || italic || bold)
|
||||
if (!string.IsNullOrWhiteSpace(foreground) || !string.IsNullOrWhiteSpace(background) || italic || bold)
|
||||
{
|
||||
writer.Write(" style=\"");
|
||||
Writer.Write(" style=\"");
|
||||
|
||||
if (foreground != Color.Empty)
|
||||
writer.Write("color:{0};", foreground.ToHtmlColor());
|
||||
if (!string.IsNullOrWhiteSpace(foreground))
|
||||
Writer.Write("color:{0};", foreground.ToHtmlColor());
|
||||
|
||||
if (background != Color.Empty)
|
||||
writer.Write("background-color:{0};", background.ToHtmlColor());
|
||||
if (!string.IsNullOrWhiteSpace(background))
|
||||
Writer.Write("background-color:{0};", background.ToHtmlColor());
|
||||
|
||||
if (italic)
|
||||
writer.Write("font-style: italic;");
|
||||
Writer.Write("font-style: italic;");
|
||||
|
||||
if (bold)
|
||||
writer.Write("font-weight: bold;");
|
||||
Writer.Write("font-weight: bold;");
|
||||
|
||||
writer.Write("\"");
|
||||
Writer.Write("\"");
|
||||
}
|
||||
|
||||
writer.Write(">");
|
||||
Writer.Write(">");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using ColorCode.Styling;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the contract for a style sheet.
|
||||
/// </summary>
|
||||
public interface IStyleSheet
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the dictionary of styles for the style sheet.
|
||||
/// </summary>
|
||||
StyleDictionary Styles { get; }
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// A dictionary of <see cref="Style" /> instances, keyed by the styles' scope name.
|
||||
/// </summary>
|
||||
public class StyleDictionary : KeyedCollection<string, Style>
|
||||
{
|
||||
/// <summary>
|
||||
/// When implemented in a derived class, extracts the key from the specified element.
|
||||
/// </summary>
|
||||
/// <param name="item">The element from which to extract the key.</param>
|
||||
/// <returns>The key for the specified element.</returns>
|
||||
protected override string GetKeyForItem(Style item)
|
||||
{
|
||||
return item.ScopeName;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using ColorCode.Styling.StyleSheets;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides easy access to ColorCode's built-in style sheets.
|
||||
/// </summary>
|
||||
public static class StyleSheets
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the default style sheet.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The default style sheet mimics the default colorization scheme used by Visual Studio 2008 to the extent possible.
|
||||
/// </remarks>
|
||||
public static IStyleSheet Default { get { return new DefaultStyleSheet(); }}
|
||||
}
|
||||
}
|
|
@ -1,272 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
using System.Drawing;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode.Styling.StyleSheets
|
||||
{
|
||||
public class DefaultStyleSheet : IStyleSheet
|
||||
{
|
||||
public static readonly Color DullRed = Color.FromArgb(163, 21, 21);
|
||||
private static readonly StyleDictionary styles;
|
||||
|
||||
static DefaultStyleSheet()
|
||||
{
|
||||
styles = new StyleDictionary
|
||||
{
|
||||
new Style(ScopeName.PlainText)
|
||||
{
|
||||
Foreground = Color.Black,
|
||||
Background = Color.White,
|
||||
CssClassName = "plainText"
|
||||
},
|
||||
new Style(ScopeName.HtmlServerSideScript)
|
||||
{
|
||||
Background = Color.Yellow,
|
||||
CssClassName = "htmlServerSideScript"
|
||||
},
|
||||
new Style(ScopeName.HtmlComment)
|
||||
{
|
||||
Foreground = Color.Green,
|
||||
CssClassName = "htmlComment"
|
||||
},
|
||||
new Style(ScopeName.HtmlTagDelimiter)
|
||||
{
|
||||
Foreground = Color.Blue,
|
||||
CssClassName = "htmlTagDelimiter"
|
||||
},
|
||||
new Style(ScopeName.HtmlElementName)
|
||||
{
|
||||
Foreground = DullRed,
|
||||
CssClassName = "htmlElementName"
|
||||
},
|
||||
new Style(ScopeName.HtmlAttributeName)
|
||||
{
|
||||
Foreground = Color.Red,
|
||||
CssClassName = "htmlAttributeName"
|
||||
},
|
||||
new Style(ScopeName.HtmlAttributeValue)
|
||||
{
|
||||
Foreground = Color.Blue,
|
||||
CssClassName = "htmlAttributeValue"
|
||||
},
|
||||
new Style(ScopeName.HtmlOperator)
|
||||
{
|
||||
Foreground = Color.Blue,
|
||||
CssClassName = "htmlOperator"
|
||||
},
|
||||
new Style(ScopeName.Comment)
|
||||
{
|
||||
Foreground = Color.Green,
|
||||
CssClassName = "comment"
|
||||
},
|
||||
new Style(ScopeName.XmlDocTag)
|
||||
{
|
||||
Foreground = Color.Gray,
|
||||
CssClassName = "xmlDocTag"
|
||||
},
|
||||
new Style(ScopeName.XmlDocComment)
|
||||
{
|
||||
Foreground = Color.Green,
|
||||
CssClassName = "xmlDocComment"
|
||||
},
|
||||
new Style(ScopeName.String)
|
||||
{
|
||||
Foreground = DullRed,
|
||||
CssClassName = "string"
|
||||
},
|
||||
new Style(ScopeName.StringCSharpVerbatim)
|
||||
{
|
||||
Foreground = DullRed,
|
||||
CssClassName = "stringCSharpVerbatim"
|
||||
},
|
||||
new Style(ScopeName.Keyword)
|
||||
{
|
||||
Foreground = Color.Blue,
|
||||
CssClassName = "keyword"
|
||||
},
|
||||
new Style(ScopeName.PreprocessorKeyword)
|
||||
{
|
||||
Foreground = Color.Blue,
|
||||
CssClassName = "preprocessorKeyword"
|
||||
},
|
||||
new Style(ScopeName.HtmlEntity)
|
||||
{
|
||||
Foreground = Color.Red,
|
||||
CssClassName = "htmlEntity"
|
||||
},
|
||||
new Style(ScopeName.XmlAttribute)
|
||||
{
|
||||
Foreground = Color.Red,
|
||||
CssClassName = "xmlAttribute"
|
||||
},
|
||||
new Style(ScopeName.XmlAttributeQuotes)
|
||||
{
|
||||
Foreground = Color.Black,
|
||||
CssClassName = "xmlAttributeQuotes"
|
||||
},
|
||||
new Style(ScopeName.XmlAttributeValue)
|
||||
{
|
||||
Foreground = Color.Blue,
|
||||
CssClassName = "xmlAttributeValue"
|
||||
},
|
||||
new Style(ScopeName.XmlCDataSection)
|
||||
{
|
||||
Foreground = Color.Gray,
|
||||
CssClassName = "xmlCDataSection"
|
||||
},
|
||||
new Style(ScopeName.XmlComment)
|
||||
{
|
||||
Foreground = Color.Green,
|
||||
CssClassName = "xmlComment"
|
||||
},
|
||||
new Style(ScopeName.XmlDelimiter)
|
||||
{
|
||||
Foreground = Color.Blue,
|
||||
CssClassName = "xmlDelimiter"
|
||||
},
|
||||
new Style(ScopeName.XmlName)
|
||||
{
|
||||
Foreground = DullRed,
|
||||
CssClassName = "xmlName"
|
||||
},
|
||||
new Style(ScopeName.ClassName)
|
||||
{
|
||||
Foreground = Color.MediumTurquoise,
|
||||
CssClassName = "className"
|
||||
},
|
||||
new Style(ScopeName.CssSelector)
|
||||
{
|
||||
Foreground = DullRed,
|
||||
CssClassName = "cssSelector"
|
||||
},
|
||||
new Style(ScopeName.CssPropertyName)
|
||||
{
|
||||
Foreground = Color.Red,
|
||||
CssClassName = "cssPropertyName"
|
||||
},
|
||||
new Style(ScopeName.CssPropertyValue)
|
||||
{
|
||||
Foreground = Color.Blue,
|
||||
CssClassName = "cssPropertyValue"
|
||||
},
|
||||
new Style(ScopeName.SqlSystemFunction)
|
||||
{
|
||||
Foreground = Color.Magenta,
|
||||
CssClassName = "sqlSystemFunction"
|
||||
},
|
||||
new Style(ScopeName.PowerShellAttribute)
|
||||
{
|
||||
Foreground = Color.PowderBlue,
|
||||
CssClassName = "powershellAttribute"
|
||||
},
|
||||
new Style(ScopeName.PowerShellOperator)
|
||||
{
|
||||
Foreground = Color.Gray,
|
||||
CssClassName = "powershellOperator"
|
||||
},
|
||||
new Style(ScopeName.PowerShellType)
|
||||
{
|
||||
Foreground = Color.Teal,
|
||||
CssClassName = "powershellType"
|
||||
},
|
||||
new Style(ScopeName.PowerShellVariable)
|
||||
{
|
||||
Foreground = Color.OrangeRed,
|
||||
CssClassName = "powershellVariable"
|
||||
},
|
||||
|
||||
new Style(ScopeName.Type)
|
||||
{
|
||||
Foreground = Color.Teal,
|
||||
CssClassName = "type"
|
||||
},
|
||||
new Style(ScopeName.TypeVariable)
|
||||
{
|
||||
Foreground = Color.Teal,
|
||||
Italic = true,
|
||||
CssClassName = "typeVariable"
|
||||
},
|
||||
new Style(ScopeName.NameSpace)
|
||||
{
|
||||
Foreground = Color.Navy,
|
||||
CssClassName = "namespace"
|
||||
},
|
||||
new Style(ScopeName.Constructor)
|
||||
{
|
||||
Foreground = Color.Purple,
|
||||
CssClassName = "constructor"
|
||||
},
|
||||
new Style(ScopeName.Predefined)
|
||||
{
|
||||
Foreground = Color.Navy,
|
||||
CssClassName = "predefined"
|
||||
},
|
||||
new Style(ScopeName.PseudoKeyword)
|
||||
{
|
||||
Foreground = Color.Navy,
|
||||
CssClassName = "pseudoKeyword"
|
||||
},
|
||||
new Style(ScopeName.StringEscape)
|
||||
{
|
||||
Foreground = Color.Gray,
|
||||
CssClassName = "stringEscape"
|
||||
},
|
||||
new Style(ScopeName.ControlKeyword)
|
||||
{
|
||||
Foreground = Color.Blue,
|
||||
CssClassName = "controlKeyword"
|
||||
},
|
||||
new Style(ScopeName.Number)
|
||||
{
|
||||
CssClassName = "number"
|
||||
},
|
||||
new Style(ScopeName.Operator)
|
||||
{
|
||||
CssClassName = "operator"
|
||||
},
|
||||
new Style(ScopeName.Delimiter)
|
||||
{
|
||||
CssClassName = "delimiter"
|
||||
},
|
||||
|
||||
new Style(ScopeName.MarkdownHeader)
|
||||
{
|
||||
// Foreground = Color.Blue,
|
||||
Bold = true,
|
||||
CssClassName = "markdownHeader"
|
||||
},
|
||||
new Style(ScopeName.MarkdownCode)
|
||||
{
|
||||
Foreground = Color.Teal,
|
||||
CssClassName = "markdownCode"
|
||||
},
|
||||
new Style(ScopeName.MarkdownListItem)
|
||||
{
|
||||
Bold = true,
|
||||
CssClassName = "markdownListItem"
|
||||
},
|
||||
new Style(ScopeName.MarkdownEmph)
|
||||
{
|
||||
Italic = true,
|
||||
CssClassName = "italic"
|
||||
},
|
||||
new Style(ScopeName.MarkdownBold)
|
||||
{
|
||||
Bold = true,
|
||||
CssClassName = "bold"
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "DefaultStyleSheet"; }
|
||||
}
|
||||
|
||||
public StyleDictionary Styles
|
||||
{
|
||||
get { return styles; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
|
@ -5,11 +6,17 @@
|
|||
<RootNamespace>ColorCode</RootNamespace>
|
||||
<AssemblyName>ColorCode.UWP</AssemblyName>
|
||||
<Title>ColorCode.UWP</Title>
|
||||
<Description>Contains the RichTextBlockFormatter, for rendering the Colorized Code to a RichTextBlock.</Description>
|
||||
<PackageTags>ColorCode Syntax Highlighting SyntaxHighlighting Formatting UWP RichTextBlock Document InlineCollection</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ColorCode\ColorCode.csproj" />
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ColorCode.Core\ColorCode.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
|
||||
</Project>
|
||||
</Project>
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
||||
namespace ColorCode.UWP.Common
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
{
|
||||
public static SolidColorBrush GetSolidColorBrush(this string hex)
|
||||
{
|
||||
hex = hex.Replace("#", string.Empty);
|
||||
|
||||
byte a = 255;
|
||||
int index = 0;
|
||||
|
||||
if (hex.Length == 8)
|
||||
{
|
||||
a = (byte)(Convert.ToUInt32(hex.Substring(index, 2), 16));
|
||||
index += 2;
|
||||
}
|
||||
|
||||
byte r = (byte)(Convert.ToUInt32(hex.Substring(index, 2), 16));
|
||||
index += 2;
|
||||
byte g = (byte)(Convert.ToUInt32(hex.Substring(index, 2), 16));
|
||||
index += 2;
|
||||
byte b = (byte)(Convert.ToUInt32(hex.Substring(index, 2), 16));
|
||||
SolidColorBrush myBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(a, r, g, b));
|
||||
return myBrush;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This file contains Runtime Directives, specifications about types your application accesses
|
||||
through reflection and other dynamic code patterns. Runtime Directives are used to control the
|
||||
.NET Native optimizer and ensure that it does not remove code accessed by your library. If your
|
||||
library does not do any reflection, then you generally do not need to edit this file. However,
|
||||
if your library reflects over types, especially types passed to it or derived from its types,
|
||||
then you should write Runtime Directives.
|
||||
|
||||
The most common use of reflection in libraries is to discover information about types passed
|
||||
to the library. Runtime Directives have three ways to express requirements on types passed to
|
||||
your library.
|
||||
|
||||
1. Parameter, GenericParameter, TypeParameter, TypeEnumerableParameter
|
||||
Use these directives to reflect over types passed as a parameter.
|
||||
|
||||
2. SubTypes
|
||||
Use a SubTypes directive to reflect over types derived from another type.
|
||||
|
||||
3. AttributeImplies
|
||||
Use an AttributeImplies directive to indicate that your library needs to reflect over
|
||||
types or methods decorated with an attribute.
|
||||
|
||||
For more information on writing Runtime Directives for libraries, please visit
|
||||
https://go.microsoft.com/fwlink/?LinkID=391919
|
||||
-->
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Library Name="ColorCode.UWP">
|
||||
|
||||
<!-- add directives for your library here -->
|
||||
|
||||
</Library>
|
||||
</Directives>
|
|
@ -0,0 +1,148 @@
|
|||
using System.Collections.Generic;
|
||||
using ColorCode.Parsing;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Documents;
|
||||
using ColorCode.Styling;
|
||||
using Windows.UI.Text;
|
||||
using ColorCode.UWP.Common;
|
||||
using ColorCode.Common;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RichTextBlockFormatter"/>, for rendering Syntax Highlighted code to a RichTextBlock.
|
||||
/// </summary>
|
||||
public class RichTextBlockFormatter : CodeColorizerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RichTextBlockFormatter"/>, for rendering Syntax Highlighted code to a RichTextBlock.
|
||||
/// </summary>
|
||||
/// <param name="Style">The Custom styles to Apply to the formatted Code.</param>
|
||||
/// <param name="languageParser">The language parser that the <see cref="RichTextBlockFormatter"/> instance will use for its lifetime.</param>
|
||||
public RichTextBlockFormatter(StyleDictionary Style = null, ILanguageParser languageParser = null) : base(Style, languageParser)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds Syntax Highlighted Source Code to the provided RichTextBlock.
|
||||
/// </summary>
|
||||
/// <param name="sourceCode">The source code to colorize.</param>
|
||||
/// <param name="language">The language to use to colorize the source code.</param>
|
||||
/// <param name="RichText">The Control to add the Text to.</param>
|
||||
public void FormatRichTextBlock(string sourceCode, ILanguage Language, RichTextBlock RichText)
|
||||
{
|
||||
var paragraph = new Paragraph();
|
||||
RichText.Blocks.Add(paragraph);
|
||||
FormatInlines(sourceCode, Language, paragraph.Inlines);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds Syntax Highlighted Source Code to the provided InlineCollection.
|
||||
/// </summary>
|
||||
/// <param name="sourceCode">The source code to colorize.</param>
|
||||
/// <param name="language">The language to use to colorize the source code.</param>
|
||||
/// <param name="InlineCollection">InlineCollection to add the Text to.</param>
|
||||
public void FormatInlines(string sourceCode, ILanguage Language, InlineCollection InlineCollection)
|
||||
{
|
||||
this.InlineCollection = InlineCollection;
|
||||
languageParser.Parse(sourceCode, Language, (parsedSourceCode, captures) => Write(parsedSourceCode, captures));
|
||||
}
|
||||
|
||||
private InlineCollection InlineCollection { get; set; }
|
||||
|
||||
protected override void Write(string parsedSourceCode, IList<Scope> scopes)
|
||||
{
|
||||
var styleInsertions = new List<TextInsertion>();
|
||||
|
||||
foreach (Scope scope in scopes)
|
||||
GetStyleInsertionsForCapturedStyle(scope, styleInsertions);
|
||||
|
||||
styleInsertions.SortStable((x, y) => x.Index.CompareTo(y.Index));
|
||||
|
||||
int offset = 0;
|
||||
|
||||
Scope PreviousScope = null;
|
||||
|
||||
foreach (var styleinsertion in styleInsertions)
|
||||
{
|
||||
var text = parsedSourceCode.Substring(offset, styleinsertion.Index - offset);
|
||||
CreateSpan(text, PreviousScope);
|
||||
if (!string.IsNullOrWhiteSpace(styleinsertion.Text))
|
||||
{
|
||||
CreateSpan(text, PreviousScope);
|
||||
}
|
||||
offset = styleinsertion.Index;
|
||||
|
||||
PreviousScope = styleinsertion.Scope;
|
||||
}
|
||||
|
||||
var remaining = parsedSourceCode.Substring(offset);
|
||||
// Ensures that those loose carriages don't run away!
|
||||
if (remaining != "\r")
|
||||
{
|
||||
CreateSpan(remaining, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateSpan(string Text, Scope scope)
|
||||
{
|
||||
var span = new Span();
|
||||
var run = new Run
|
||||
{
|
||||
Text = Text
|
||||
};
|
||||
|
||||
// Styles and writes the text to the span.
|
||||
if (scope != null) StyleRun(run, scope);
|
||||
span.Inlines.Add(run);
|
||||
|
||||
InlineCollection.Add(span);
|
||||
}
|
||||
|
||||
private void StyleRun(Run Run, Scope Scope)
|
||||
{
|
||||
string foreground = null;
|
||||
string background = null;
|
||||
bool italic = false;
|
||||
bool bold = false;
|
||||
|
||||
if (Styles.Contains(Scope.Name))
|
||||
{
|
||||
Style style = Styles[Scope.Name];
|
||||
|
||||
foreground = style.Foreground;
|
||||
background = style.Background;
|
||||
italic = style.Italic;
|
||||
bold = style.Bold;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(foreground))
|
||||
Run.Foreground = foreground.GetSolidColorBrush();
|
||||
|
||||
//Background isn't supported, but a workaround could be created.
|
||||
|
||||
if (italic)
|
||||
Run.FontStyle = FontStyle.Italic;
|
||||
|
||||
if (bold)
|
||||
Run.FontWeight = FontWeights.Bold;
|
||||
}
|
||||
|
||||
private void GetStyleInsertionsForCapturedStyle(Scope scope, ICollection<TextInsertion> styleInsertions)
|
||||
{
|
||||
styleInsertions.Add(new TextInsertion
|
||||
{
|
||||
Index = scope.Index,
|
||||
Scope = scope
|
||||
});
|
||||
|
||||
foreach (Scope childScope in scope.Children)
|
||||
GetStyleInsertionsForCapturedStyle(childScope, styleInsertions);
|
||||
|
||||
styleInsertions.Add(new TextInsertion
|
||||
{
|
||||
Index = scope.Index + scope.Length
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
112
ColorCode.sln
|
@ -3,34 +3,122 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27004.2010
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorCode", "ColorCode\ColorCode.csproj", "{37438935-D221-4FD8-A10E-4EC5356B0F94}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorCode.UWP", "ColorCode.UWP\ColorCode.UWP.csproj", "{486C91A9-26DD-4F9F-A81D-508AE2D24858}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorCode.HTML", "ColorCode.HTML\ColorCode.HTML.csproj", "{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{5B9F207C-2EAB-4F77-95C7-206D65C87137}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorCode.UWP", "ColorCode.UWP\ColorCode.UWP.csproj", "{A482CFCC-D474-4C43-A812-1B0B4E6E484F}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorCode.Core", "ColorCode.Core\ColorCode.Core.csproj", "{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorCode.BasicTests", "Tests\ColorCode.BasicTests\ColorCode.BasicTests.csproj", "{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorCode.UWPTests", "Tests\ColorCode.UWPTests\ColorCode.UWPTests.csproj", "{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|ARM = Debug|ARM
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|ARM = Release|ARM
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{37438935-D221-4FD8-A10E-4EC5356B0F94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{37438935-D221-4FD8-A10E-4EC5356B0F94}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{37438935-D221-4FD8-A10E-4EC5356B0F94}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{37438935-D221-4FD8-A10E-4EC5356B0F94}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{486C91A9-26DD-4F9F-A81D-508AE2D24858}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{486C91A9-26DD-4F9F-A81D-508AE2D24858}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{486C91A9-26DD-4F9F-A81D-508AE2D24858}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{486C91A9-26DD-4F9F-A81D-508AE2D24858}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Release|x64.Build.0 = Release|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}.Release|x86.Build.0 = Release|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A482CFCC-D474-4C43-A812-1B0B4E6E484F}.Release|x86.Build.0 = Release|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{F6DE802C-9BD7-4BFA-9553-BCBF51E0556B}.Release|x86.Build.0 = Release|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10}.Release|x86.Build.0 = Release|Any CPU
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|ARM.Deploy.0 = Debug|ARM
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|x64.Build.0 = Debug|x64
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|x64.Deploy.0 = Debug|x64
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|x86.Build.0 = Debug|x86
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Debug|x86.Deploy.0 = Debug|x86
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|ARM.Build.0 = Release|ARM
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|ARM.Deploy.0 = Release|ARM
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|x64.ActiveCfg = Release|x64
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|x64.Build.0 = Release|x64
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|x64.Deploy.0 = Release|x64
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|x86.ActiveCfg = Release|x86
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|x86.Build.0 = Release|x86
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}.Release|x86.Deploy.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{A3E27CD2-6D33-44D3-962F-E56C4CD25F10} = {5B9F207C-2EAB-4F77-95C7-206D65C87137}
|
||||
{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3} = {5B9F207C-2EAB-4F77-95C7-206D65C87137}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5A764590-3191-47F4-9257-5D5F63BC5713}
|
||||
EndGlobalSection
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
using ColorCode.Common;
|
||||
using ColorCode.Compilation;
|
||||
using ColorCode.Parsing;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public abstract class CodeColorizerBase
|
||||
{
|
||||
protected readonly ILanguageParser languageParser;
|
||||
|
||||
public CodeColorizerBase()
|
||||
{
|
||||
languageParser = new LanguageParser(new LanguageCompiler(Languages.CompiledLanguages), Languages.LanguageRepository);
|
||||
}
|
||||
|
||||
public CodeColorizerBase(ILanguageParser languageParser)
|
||||
{
|
||||
Guard.ArgNotNull(languageParser, "languageParser");
|
||||
this.languageParser = languageParser;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the parsed source code to the ouput using the specified style sheet.
|
||||
/// </summary>
|
||||
/// <param name="parsedSourceCode">The parsed source code to format and write to the output.</param>
|
||||
/// <param name="scopes">The captured scopes for the parsed source code.</param>
|
||||
protected abstract void Write(string parsedSourceCode, IList<Scope> scopes);
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.4</TargetFramework>
|
||||
<RootNamespace>ColorCode</RootNamespace>
|
||||
<AssemblyName>ColorCode</AssemblyName>
|
||||
<Title>ColorCode-Universal</Title>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -1,20 +1,18 @@
|
|||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<DefaultLanguage>en-NZ</DefaultLanguage>
|
||||
<!-- Package Config -->
|
||||
<Authors>Microsoft, William Bradley</Authors>
|
||||
<NoPackageAnalysis>true</NoPackageAnalysis>
|
||||
<PackageProjectUrl>https://github.com/WilliamABradley/ColorCode-Universal</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://github.com/WilliamABradley/ColorCode-Universal/blob/master/LICENSE</PackageLicenseUrl>
|
||||
<Copyright>Copyright © Microsoft Corporation, William Bradley</Copyright>
|
||||
<Copyright>Copyright © Microsoft Corporation, William Bradley 2017</Copyright>
|
||||
<!-- Project States -->
|
||||
<IsUwpProject>$(MSBuildProjectName.Contains('UWP'))</IsUwpProject>
|
||||
<IsAndroidProject>$(MSBuildProjectName.Contains('Android'))</IsAndroidProject>
|
||||
<!-- UWP Config -->
|
||||
<UwpMetaPackageVersion>6.0.1</UwpMetaPackageVersion>
|
||||
<DefaultTargetPlatformVersion>16299</DefaultTargetPlatformVersion>
|
||||
<DefaultTargetPlatformMinVersion>14393</DefaultTargetPlatformMinVersion>
|
||||
<TargetPlatformVersion>10.0.16299.0</TargetPlatformVersion>
|
||||
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
<Project>
|
||||
|
||||
<Choose>
|
||||
<When Condition="'$(TargetFramework)' == 'uap10.0' or '$(TargetFramework)' == 'native'">
|
||||
<!-- UAP versions for uap10.0 where TPMV isn't implied -->
|
||||
<PropertyGroup>
|
||||
<TargetPlatformVersion>10.0.$(DefaultTargetPlatformVersion).0</TargetPlatformVersion>
|
||||
<TargetPlatformMinVersion>10.0.$(DefaultTargetPlatformMinVersion).0</TargetPlatformMinVersion>
|
||||
<DebugType>Full</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Condition="'$(UseUwpMetaPackage)' == 'true'" Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="$(UwpMetaPackageVersion)" />
|
||||
|
||||
<SDKReference Condition="'$(UseWindowsDesktopSdk)' == 'true' " Include="WindowsDesktop, Version=$(TargetPlatformVersion)">
|
||||
<Name>Windows Desktop Extensions for the UWP</Name>
|
||||
</SDKReference>
|
||||
<SDKReference Condition="'$(UseWindowsMobileSdk)' == 'true' " Include="WindowsMobile, Version=$(TargetPlatformVersion)">
|
||||
<Name>Windows Mobile Extensions for the UWP</Name>
|
||||
</SDKReference>
|
||||
</ItemGroup>
|
||||
|
||||
</When>
|
||||
</Choose>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ColorCode.HTML\ColorCode.HTML.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
|
||||
namespace ColorCode.BasicTests
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
var csharpstring = "public void Method()\n{\n}";
|
||||
var formatter = new HtmlClassFormatter();
|
||||
var html = formatter.GetHtmlString(csharpstring, Languages.CSharp);
|
||||
var css = formatter.GetCSSString();
|
||||
|
||||
Console.WriteLine("Original:");
|
||||
Console.WriteLine(csharpstring);
|
||||
|
||||
Console.WriteLine("HTML:");
|
||||
Console.WriteLine(html);
|
||||
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<Application
|
||||
x:Class="ColorCode.UWPTests.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ColorCode.UWPTests"
|
||||
RequestedTheme="Light">
|
||||
|
||||
</Application>
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
namespace ColorCode.UWPTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
/// </summary>
|
||||
sealed partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
/// </summary>
|
||||
public App()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Suspending += OnSuspending;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the application is launched normally by the end user. Other entry points
|
||||
/// will be used such as when the application is launched to open a specific file.
|
||||
/// </summary>
|
||||
/// <param name="e">Details about the launch request and process.</param>
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs e)
|
||||
{
|
||||
Frame rootFrame = Window.Current.Content as Frame;
|
||||
|
||||
// Do not repeat app initialization when the Window already has content,
|
||||
// just ensure that the window is active
|
||||
if (rootFrame == null)
|
||||
{
|
||||
// Create a Frame to act as the navigation context and navigate to the first page
|
||||
rootFrame = new Frame();
|
||||
|
||||
rootFrame.NavigationFailed += OnNavigationFailed;
|
||||
|
||||
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
|
||||
{
|
||||
//TODO: Load state from previously suspended application
|
||||
}
|
||||
|
||||
// Place the frame in the current Window
|
||||
Window.Current.Content = rootFrame;
|
||||
}
|
||||
|
||||
if (e.PrelaunchActivated == false)
|
||||
{
|
||||
if (rootFrame.Content == null)
|
||||
{
|
||||
// When the navigation stack isn't restored navigate to the first page,
|
||||
// configuring the new page by passing required information as a navigation
|
||||
// parameter
|
||||
rootFrame.Navigate(typeof(MainPage), e.Arguments);
|
||||
}
|
||||
// Ensure the current window is active
|
||||
Window.Current.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when Navigation to a certain page fails
|
||||
/// </summary>
|
||||
/// <param name="sender">The Frame which failed navigation</param>
|
||||
/// <param name="e">Details about the navigation failure</param>
|
||||
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
|
||||
{
|
||||
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when application execution is being suspended. Application state is saved
|
||||
/// without knowing whether the application will be terminated or resumed with the contents
|
||||
/// of memory still intact.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the suspend request.</param>
|
||||
/// <param name="e">Details about the suspend request.</param>
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
//TODO: Save application state and stop any background activity
|
||||
deferral.Complete();
|
||||
}
|
||||
}
|
||||
}
|
После Ширина: | Высота: | Размер: 1.4 KiB |
После Ширина: | Высота: | Размер: 7.5 KiB |
После Ширина: | Высота: | Размер: 2.9 KiB |
После Ширина: | Высота: | Размер: 1.6 KiB |
Двоичные данные
Tests/ColorCode.UWPTests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
Normal file
После Ширина: | Высота: | Размер: 1.2 KiB |
После Ширина: | Высота: | Размер: 1.4 KiB |
После Ширина: | Высота: | Размер: 3.1 KiB |
|
@ -0,0 +1,157 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProjectGuid>{A3D5A8A5-1D1F-412D-A829-C3DC1C7D4DF3}</ProjectGuid>
|
||||
<OutputType>AppContainerExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ColorCode.UWPTests</RootNamespace>
|
||||
<AssemblyName>ColorCode.UWPTests</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
|
||||
<PackageCertificateKeyFile>ColorCode.UWPTests_TemporaryKey.pfx</PackageCertificateKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\ARM\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
|
||||
<OutputPath>bin\ARM\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
<SubType>Designer</SubType>
|
||||
</AppxManifest>
|
||||
<None Include="ColorCode.UWPTests_TemporaryKey.pfx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Properties\Default.rd.xml" />
|
||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||
<Content Include="Assets\Square150x150Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||
<Content Include="Assets\StoreLogo.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||
<Version>6.0.2</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ColorCode.Core\ColorCode.Core.csproj">
|
||||
<Project>{f6de802c-9bd7-4bfa-9553-bcbf51e0556b}</Project>
|
||||
<Name>ColorCode.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\ColorCode.HTML\ColorCode.HTML.csproj">
|
||||
<Project>{33a3fb96-f1eb-4af0-94e0-f629e1f574a8}</Project>
|
||||
<Name>ColorCode.HTML</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\ColorCode.UWP\ColorCode.UWP.csproj">
|
||||
<Project>{a482cfcc-d474-4c43-a812-1b0b4e6e484f}</Project>
|
||||
<Name>ColorCode.UWP</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,24 @@
|
|||
<Page
|
||||
x:Class="ColorCode.UWPTests.MainPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ColorCode.UWPTests"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel>
|
||||
<TextBox x:Name="LanguageBox" Header="Language" Text="C#" />
|
||||
<Button Content="Render to Rich Text Block" Click="Load_Click" />
|
||||
<Button Content="Create HTML" Click="MakeHTML" />
|
||||
</StackPanel>
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<RichTextBlock x:Name="PresentationBlock" />
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Page>
|
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
|
||||
|
||||
namespace ColorCode.UWPTests
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
public MainPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private async void Load_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PresentationBlock.Blocks.Clear();
|
||||
|
||||
var result = await GetCodeFileText();
|
||||
if (result == null) return;
|
||||
|
||||
var formatter = new RichTextBlockFormatter();
|
||||
formatter.FormatRichTextBlock(result.Item1, result.Item2, PresentationBlock);
|
||||
}
|
||||
|
||||
private async Task<Tuple<string, ILanguage>> GetCodeFileText()
|
||||
{
|
||||
var picker = new FileOpenPicker();
|
||||
picker.FileTypeFilter.Add("*");
|
||||
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
if (file == null) return null;
|
||||
var text = await FileIO.ReadTextAsync(file);
|
||||
|
||||
ILanguage Language = Languages.CSharp;
|
||||
|
||||
if (LanguageBox.Text != null)
|
||||
{
|
||||
Language = Languages.FindById(LanguageBox.Text) ?? Languages.CSharp;
|
||||
}
|
||||
return new Tuple<string, ILanguage>(text, Language);
|
||||
}
|
||||
|
||||
private async void MakeHTML(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var result = await GetCodeFileText();
|
||||
if (result == null) return;
|
||||
|
||||
var formatter = new HtmlFormatter();
|
||||
var html = formatter.GetHtmlString(result.Item1, result.Item2);
|
||||
|
||||
var tempfile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("HTMLResult.html", CreationCollisionOption.ReplaceExisting);
|
||||
await FileIO.WriteTextAsync(tempfile, html);
|
||||
|
||||
try
|
||||
{
|
||||
await Launcher.LaunchFileAsync(tempfile);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity
|
||||
Name="2e00dea4-7f3d-40f9-9c90-654e40cdcd3a"
|
||||
Publisher="CN=Willi"
|
||||
Version="1.0.0.0" />
|
||||
|
||||
<mp:PhoneIdentity PhoneProductId="2e00dea4-7f3d-40f9-9c90-654e40cdcd3a" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
|
||||
<Properties>
|
||||
<DisplayName>ColorCode.UWPTests</DisplayName>
|
||||
<PublisherDisplayName>Willi</PublisherDisplayName>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
|
||||
<Resources>
|
||||
<Resource Language="x-generate"/>
|
||||
</Resources>
|
||||
|
||||
<Applications>
|
||||
<Application Id="App"
|
||||
Executable="$targetnametoken$.exe"
|
||||
EntryPoint="ColorCode.UWPTests.App">
|
||||
<uap:VisualElements
|
||||
DisplayName="ColorCode.UWPTests"
|
||||
Square150x150Logo="Assets\Square150x150Logo.png"
|
||||
Square44x44Logo="Assets\Square44x44Logo.png"
|
||||
Description="ColorCode.UWPTests"
|
||||
BackgroundColor="transparent">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient" />
|
||||
</Capabilities>
|
||||
</Package>
|
|
@ -0,0 +1,15 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ColorCode.UWPTests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ColorCode.UWPTests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
This file contains Runtime Directives used by .NET Native. The defaults here are suitable for most
|
||||
developers. However, you can modify these parameters to modify the behavior of the .NET Native
|
||||
optimizer.
|
||||
|
||||
Runtime Directives are documented at https://go.microsoft.com/fwlink/?LinkID=391919
|
||||
|
||||
To fully enable reflection for App1.MyClass and all of its public/private members
|
||||
<Type Name="App1.MyClass" Dynamic="Required All"/>
|
||||
|
||||
To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32
|
||||
<TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" />
|
||||
|
||||
Using the Namespace directive to apply reflection policy to all the types in a particular namespace
|
||||
<Namespace Name="DataClasses.ViewModels" Serialize="All" />
|
||||
-->
|
||||
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Application>
|
||||
<!--
|
||||
An Assembly element with Name="*Application*" applies to all assemblies in
|
||||
the application package. The asterisks are not wildcards.
|
||||
-->
|
||||
<Assembly Name="*Application*" Dynamic="Required All" />
|
||||
|
||||
|
||||
<!-- Add your application specific runtime directives here. -->
|
||||
|
||||
|
||||
</Application>
|
||||
</Directives>
|
|
@ -0,0 +1,106 @@
|
|||
#addin "Cake.Powershell"
|
||||
|
||||
using System;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ARGUMENTS
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
var target = Argument("target", "Default");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// PREPARATION
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
var baseDir = MakeAbsolute(Directory("../")).ToString();
|
||||
var buildDir = baseDir + "/build";
|
||||
var toolsDir = buildDir + "/tools";
|
||||
|
||||
var Solution = baseDir + "/ColorCode.sln";
|
||||
var nupkgDir = buildDir + "/nupkg";
|
||||
|
||||
var gitVersioningVersion = "2.0.41";
|
||||
var versionClient = toolsDir + "/nerdbank.gitversioning/tools/Get-Version.ps1";
|
||||
string Version = null;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// TASKS
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
Task("Clean")
|
||||
.Does(() =>
|
||||
{
|
||||
Information("\nCleaning Package Directory");
|
||||
CleanDirectory(nupkgDir);
|
||||
});
|
||||
|
||||
Task("Restore-NuGet-Packages")
|
||||
.IsDependentOn("Clean")
|
||||
.Does(() =>
|
||||
{
|
||||
NuGetRestore(Solution);
|
||||
});
|
||||
|
||||
Task("Version")
|
||||
.Description("Updates the version information in all Projects")
|
||||
.IsDependentOn("Restore-NuGet-Packages")
|
||||
.Does(() =>
|
||||
{
|
||||
Information("\nDownloading NerdBank GitVersioning...");
|
||||
var installSettings = new NuGetInstallSettings {
|
||||
ExcludeVersion = true,
|
||||
Version = gitVersioningVersion,
|
||||
OutputDirectory = toolsDir
|
||||
};
|
||||
|
||||
NuGetInstall(new []{"nerdbank.gitversioning"}, installSettings);
|
||||
|
||||
Information("\nRetrieving version...");
|
||||
var results = StartPowershellFile(versionClient);
|
||||
Version = results[1].Properties["NuGetPackageVersion"].Value.ToString();
|
||||
Information("\nBuild Version: " + Version);
|
||||
});
|
||||
|
||||
Task("Build")
|
||||
.IsDependentOn("Version")
|
||||
.Does(() =>
|
||||
{
|
||||
Information("\nBuilding Solution");
|
||||
var buildSettings = new MSBuildSettings
|
||||
{
|
||||
MaxCpuCount = 0
|
||||
}
|
||||
.SetConfiguration("Release")
|
||||
.WithTarget("Restore");
|
||||
|
||||
// Force a restore again to get proper version numbers https://github.com/NuGet/Home/issues/4337
|
||||
MSBuild(Solution, buildSettings);
|
||||
MSBuild(Solution, buildSettings);
|
||||
|
||||
EnsureDirectoryExists(nupkgDir);
|
||||
|
||||
buildSettings = new MSBuildSettings
|
||||
{
|
||||
MaxCpuCount = 0
|
||||
}
|
||||
.SetConfiguration("Release")
|
||||
.WithTarget("Build")
|
||||
.WithProperty("IncludeSymbols", "true")
|
||||
.WithProperty("GenerateLibraryLayout", "true")
|
||||
.WithProperty("PackageOutputPath", nupkgDir)
|
||||
.WithProperty("GeneratePackageOnBuild", "true");
|
||||
|
||||
MSBuild(Solution, buildSettings);
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// TASK TARGETS
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
Task("Default")
|
||||
.IsDependentOn("Build");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// EXECUTION
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
RunTarget(target);
|
|
@ -0,0 +1,182 @@
|
|||
##########################################################################
|
||||
# This is the Cake bootstrapper script for PowerShell.
|
||||
# This file was downloaded from https://github.com/cake-build/resources
|
||||
# Feel free to change this file to fit your needs.
|
||||
##########################################################################
|
||||
|
||||
<#
|
||||
|
||||
.SYNOPSIS
|
||||
This is a Powershell script to bootstrap a Cake build.
|
||||
|
||||
.DESCRIPTION
|
||||
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
|
||||
and execute your Cake build script with the parameters you provide.
|
||||
|
||||
.PARAMETER Script
|
||||
The build script to execute.
|
||||
.PARAMETER Target
|
||||
The build script target to run.
|
||||
.PARAMETER Configuration
|
||||
The build configuration to use.
|
||||
.PARAMETER Verbosity
|
||||
Specifies the amount of information to be displayed.
|
||||
.PARAMETER Experimental
|
||||
Tells Cake to use the latest Roslyn release.
|
||||
.PARAMETER WhatIf
|
||||
Performs a dry run of the build script.
|
||||
No tasks will be executed.
|
||||
.PARAMETER Mono
|
||||
Tells Cake to use the Mono scripting engine.
|
||||
.PARAMETER SkipToolPackageRestore
|
||||
Skips restoring of packages.
|
||||
.PARAMETER ScriptArgs
|
||||
Remaining arguments are added here.
|
||||
|
||||
.LINK
|
||||
http://cakebuild.net
|
||||
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[string]$Script = "build.cake",
|
||||
[string]$Target = "Default",
|
||||
[ValidateSet("Release", "Debug")]
|
||||
[string]$Configuration = "Release",
|
||||
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
|
||||
[string]$Verbosity = "Verbose",
|
||||
[switch]$Experimental,
|
||||
[Alias("DryRun","Noop")]
|
||||
[switch]$WhatIf,
|
||||
[switch]$Mono,
|
||||
[switch]$SkipToolPackageRestore,
|
||||
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
|
||||
[string[]]$ScriptArgs
|
||||
)
|
||||
|
||||
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
|
||||
function MD5HashFile([string] $filePath)
|
||||
{
|
||||
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
|
||||
{
|
||||
return $null
|
||||
}
|
||||
|
||||
[System.IO.Stream] $file = $null;
|
||||
[System.Security.Cryptography.MD5] $md5 = $null;
|
||||
try
|
||||
{
|
||||
$md5 = [System.Security.Cryptography.MD5]::Create()
|
||||
$file = [System.IO.File]::OpenRead($filePath)
|
||||
return [System.BitConverter]::ToString($md5.ComputeHash($file))
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ($file -ne $null)
|
||||
{
|
||||
$file.Dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Preparing to run build script..."
|
||||
|
||||
if(!$PSScriptRoot){
|
||||
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
|
||||
}
|
||||
|
||||
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
|
||||
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
|
||||
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
|
||||
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
|
||||
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
|
||||
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
|
||||
|
||||
# Should we use mono?
|
||||
$UseMono = "";
|
||||
if($Mono.IsPresent) {
|
||||
Write-Verbose -Message "Using the Mono based scripting engine."
|
||||
$UseMono = "-mono"
|
||||
}
|
||||
|
||||
# Should we use the new Roslyn?
|
||||
$UseExperimental = "";
|
||||
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
|
||||
Write-Verbose -Message "Using experimental version of Roslyn."
|
||||
$UseExperimental = "-experimental"
|
||||
}
|
||||
|
||||
# Is this a dry run?
|
||||
$UseDryRun = "";
|
||||
if($WhatIf.IsPresent) {
|
||||
$UseDryRun = "-dryrun"
|
||||
}
|
||||
|
||||
# Make sure tools folder exists
|
||||
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
|
||||
Write-Verbose -Message "Creating tools directory..."
|
||||
New-Item -Path $TOOLS_DIR -Type directory | out-null
|
||||
}
|
||||
|
||||
# Make sure that packages.config exist.
|
||||
if (!(Test-Path $PACKAGES_CONFIG)) {
|
||||
Write-Verbose -Message "Downloading packages.config..."
|
||||
try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
|
||||
Throw "Could not download packages.config."
|
||||
}
|
||||
}
|
||||
|
||||
# Try download NuGet.exe if not exists
|
||||
if (!(Test-Path $NUGET_EXE)) {
|
||||
Write-Verbose -Message "Downloading NuGet.exe..."
|
||||
try {
|
||||
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
|
||||
} catch {
|
||||
Throw "Could not download NuGet.exe."
|
||||
}
|
||||
}
|
||||
|
||||
# Save nuget.exe path to environment to be available to child processed
|
||||
$ENV:NUGET_EXE = $NUGET_EXE
|
||||
|
||||
# Restore tools from NuGet?
|
||||
if(-Not $SkipToolPackageRestore.IsPresent) {
|
||||
Push-Location
|
||||
Set-Location $TOOLS_DIR
|
||||
|
||||
# Check for changes in packages.config and remove installed tools if true.
|
||||
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
|
||||
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
|
||||
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
|
||||
Write-Verbose -Message "Missing or changed package.config hash..."
|
||||
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
|
||||
}
|
||||
|
||||
Write-Verbose -Message "Restoring tools from NuGet..."
|
||||
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Throw "An error occured while restoring NuGet tools."
|
||||
}
|
||||
else
|
||||
{
|
||||
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
|
||||
}
|
||||
Write-Verbose -Message ($NuGetOutput | out-string)
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# Make sure that Cake has been installed.
|
||||
if (!(Test-Path $CAKE_EXE)) {
|
||||
Throw "Could not find Cake.exe at $CAKE_EXE"
|
||||
}
|
||||
|
||||
# Start Cake
|
||||
Write-Host "Running build script..."
|
||||
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
|
||||
|
||||
Write-Host "Press any key to continue ..."
|
||||
$fin = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
|
||||
|
||||
exit $LASTEXITCODE
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Cake" version="0.22.2" />
|
||||
</packages>
|
|
@ -0,0 +1,79 @@
|
|||
# ColorCode-Universal
|
||||
|
||||
This is a port of [ColorCode](https://colorcode.codeplex.com/) to .NET Standard. The original Html only formatter has been separated from the Logic, so now it can produce Syntax Highlighted code for any output.
|
||||
|
||||
This Project can currently produce HTML, and Render to UWP RichTextBlocks.
|
||||
|
||||
## Usage
|
||||
|
||||
### HTML
|
||||
|
||||
To use ColorCode to create colorised HTML, ensure you have installed the ColorCode.HTML NuGet package, then you can use the following code:
|
||||
|
||||
```c#
|
||||
var csharpstring = "public void Method()\n{\n}";
|
||||
var formatter = new HtmlFormatter();
|
||||
var html = formatter.GetHtmlString(csharpstring, Languages.CSharp);
|
||||
```
|
||||
|
||||
This will create the formatting into the HTML, via inline styling. To use CSS to format the HTML instead, use the following:
|
||||
|
||||
```c#
|
||||
var csharpstring = "public void Method()\n{\n}";
|
||||
var formatter = new HtmlClassFormatter();
|
||||
var html = formatter.GetHtmlString(csharpstring, Languages.CSharp);
|
||||
var css = formatter.GetCSSString();
|
||||
```
|
||||
|
||||
You will then have to manually reference the css, from the HTML head.
|
||||
|
||||
### UWP
|
||||
|
||||
To use ColorCode to render colorized code to a RichTextBlock, then you can use the following code:
|
||||
|
||||
```C#
|
||||
var csharpstring = "public void Method()\n{\n}";
|
||||
var formatter = new RichTextBlockFormatter();
|
||||
formatter.FormatRichTextBlock(csharpstring, Languages.CSharp, PresentationBlock);
|
||||
```
|
||||
|
||||
Or you can append onto an existing InlineCollection, with the following code:
|
||||
|
||||
```C#
|
||||
var paragraph = new Paragraph();
|
||||
var csharpstring = "public void Method()\n{\n}";
|
||||
var formatter = new RichTextBlockFormatter();
|
||||
formatter.FormatInlines(csharpstring, Languages.CSharp, paragraph.Inlines);
|
||||
```
|
||||
|
||||
## Determining the Programming Language
|
||||
|
||||
To get the Programming Language manually, you can provide the identifier name, with the following code:
|
||||
|
||||
```C#
|
||||
var language = ColorCode.Languages.FindById("java");
|
||||
```
|
||||
See [LanguageId.cs](ColorCode/Common/LanguageId.cs) for the list of available Languages to parse.
|
||||
|
||||
## NuGet Packages
|
||||
|
||||
| NuGet Package | Description |
|
||||
| --- | --- |
|
||||
| [ColorCode.Core](https://www.nuget.org/packages/ColorCode.Core) | The Core Library, containing the Parser, and the classes to create your own formatter. |
|
||||
| [ColorCode.HTML](https://www.nuget.org/packages/ColorCode.UWP) | The Library containing the HtmlFormatter, and the HtmlClassFormatter, for rendering Html from the Colorized Code. |
|
||||
| [ColorCode.UWP](https://www.nuget.org/packages/ColorCode.HTML) | The Library containing the RichTextBlockFormatter, for rendering the Colorized Code to a RichTextBlock. |
|
||||
|
||||
## Supported SDKs
|
||||
|
||||
Requires .NET Standard 1.4 support.
|
||||
|
||||
### UWP
|
||||
|
||||
Tested against 10.0.14393.0 and up.
|
||||
|
||||
## Feedback and Requests
|
||||
|
||||
Please use [GitHub issues](https://github.com/WilliamABradley/ColorCode-Universal/issues) for bug reports and feature requests.
|
||||
|
||||
## Contributing
|
||||
Want to help out and add some more parsing support, or add a new Formatter platform? Submit a PR!
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "2.0.0-build.{height}",
|
||||
"version": "2.0.0",
|
||||
"publicReleaseRefSpec": [
|
||||
"^refs/heads/master$", // we release out of master
|
||||
"^refs/heads/v\\d+\\.\\d+" // we also release branches starting with vN.N
|
||||
|
|