diff --git a/ColorCode.Core/Common/LanguageId.cs b/ColorCode.Core/Common/LanguageId.cs index 0546a29..20c1685 100644 --- a/ColorCode.Core/Common/LanguageId.cs +++ b/ColorCode.Core/Common/LanguageId.cs @@ -25,5 +25,6 @@ namespace ColorCode.Common public const string Koka = "koka"; public const string Haskell = "haskell"; public const string Markdown = "markdown"; + public const string Fortran = "fortran"; } } \ No newline at end of file diff --git a/ColorCode.Core/Common/ScopeName.cs b/ColorCode.Core/Common/ScopeName.cs index 932b9d3..7635baf 100644 --- a/ColorCode.Core/Common/ScopeName.cs +++ b/ColorCode.Core/Common/ScopeName.cs @@ -53,5 +53,12 @@ namespace ColorCode.Common public const string MarkdownListItem = "Markdown List Item"; public const string MarkdownEmph = "Markdown Emphasized"; public const string MarkdownBold = "Markdown Bold"; + public const string BuiltinFunction = "Built In Function"; + public const string BuiltinValue = "Built In Value"; + public const string Attribute = "Attribute"; + public const string SpecialCharacter = "Special Character"; + public const string Intrinsic = "Intrinsic"; + public const string Brackets = "Brackets"; + public const string Continuation = "Continuation"; } } \ No newline at end of file diff --git a/ColorCode.Core/Compilation/Languages/CSharp.cs b/ColorCode.Core/Compilation/Languages/CSharp.cs index 6578bca..aed2623 100644 --- a/ColorCode.Core/Compilation/Languages/CSharp.cs +++ b/ColorCode.Core/Compilation/Languages/CSharp.cs @@ -88,7 +88,7 @@ namespace ColorCode.Compilation.Languages { 1, ScopeName.PreprocessorKeyword } }), new LanguageRule( - @"\b(abstract|as|ascending|base|bool|break|by|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|equals|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|goto|group|if|implicit|in|int|into|interface|internal|is|join|let|lock|long|namespace|new|null|object|on|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|var|virtual|void|volatile|where|while|yield|async|await)\b", + @"\b(abstract|as|ascending|base|bool|break|by|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|equals|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|goto|group|if|implicit|in|int|into|interface|internal|is|join|let|lock|long|namespace|new|null|object|on|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|var|virtual|void|volatile|where|while|yield|async|await|warning|disable)\b", new Dictionary { { 1, ScopeName.Keyword } diff --git a/ColorCode.Core/Compilation/Languages/Fortran.cs b/ColorCode.Core/Compilation/Languages/Fortran.cs new file mode 100644 index 0000000..55e008c --- /dev/null +++ b/ColorCode.Core/Compilation/Languages/Fortran.cs @@ -0,0 +1,229 @@ +// Copyright (c) 2015 Christopher Pardi. + +// Copyright (c) Microsoft Corporation. All rights reserved. + +using System.Collections.Generic; +using ColorCode.Common; + +namespace ColorCode.Compilation.Languages +{ + public class Fortran : ILanguage + { + public string Id + { + get { return LanguageId.Fortran; } + } + + public string Name + { + get { return "Fortran"; } + } + + public string CssClassName + { + get { return "fortran"; } + } + + public string FirstLinePattern + { + get + { + return null; + } + } + + public IList Rules + { + get + { + return new List + { + // Comments + new LanguageRule( + @"!.*", + new Dictionary + { + { 0, ScopeName.Comment }, + }), + // String type 1 + new LanguageRule( + @""".*?""|'.*?'", + new Dictionary + { + { 0, ScopeName.String }, + }), + // Program keywords + new LanguageRule( + @"(?i)\b(?:program|endprogram)\b", + new Dictionary + { + { 0, ScopeName.Keyword }, + }), + // Module keywords + new LanguageRule( + @"(?i)\b(?:module|endmodule|contains)\b", + new Dictionary + { + { 0, ScopeName.Keyword }, + }), + // Type keywords + new LanguageRule( + @"(?i)\b(?:type|endtype|abstract)\b", + new Dictionary + { + { 0, ScopeName.Keyword }, + }), + // Interface definition keywords + new LanguageRule( + @"(?i)\b(?:interface|endinterface|operator|assignment)\b", + new Dictionary + { + { 0, ScopeName.Keyword }, + }), + // Procedure definition keywords + new LanguageRule( + @"(?i)\b(?:function|endfunction|subroutine|endsubroutine|elemental|recursive|pure)\b", + new Dictionary + { + { 0, ScopeName.Keyword }, + }), + // Variable keywords + new LanguageRule( + @"(?i)INTEGER|REAL|DOUBLE\s*PRECISION|COMPLEX|CHARACTER|LOGICAL|TYPE", + new Dictionary + { + { 0, ScopeName.Keyword }, + }), + // Attribute keywords + new LanguageRule( + @"(?i)\b(?:parameter|allocatable|optional|pointer|save|dimension|target)\b", + new Dictionary + { + { 0, ScopeName.Keyword }, + }), + // Intent keywords + new LanguageRule( + @"(?i)\b(intent)\s*(\()\s*(in|out|inout)\s*(\))", + new Dictionary + { + { 1, ScopeName.Keyword }, + { 2, ScopeName.Brackets }, + { 3, ScopeName.Keyword }, + { 4, ScopeName.Brackets }, + }), + // Namelist + new LanguageRule( + @"(?i)\b(namelist)(/)\w+(/)", + new Dictionary + { + { 1, ScopeName.Keyword }, + { 2, ScopeName.Brackets }, + { 3, ScopeName.Brackets }, + }), + // Intrinsic functions + new LanguageRule( + @"(?i)\b(PRESENT" + + "|INT|REAL|DBLE|CMPLX|AIMAG|CONJG|AINT|ANINT|NINT|ABS|MOD|SIGN|DIM|DPROD|MODULO|FLOOR|CEILING|MAX|MIN" + + "|SQRT|EXP|LOG|LOG10|SIN|COS|TAN|ASIN|ACOS|ATAN|ATAN2|SINH|COSH|TANH" + + "|ICHAR|CHAR|LGE|LGT|LLE|LLT|IACHAR|ACHAR|INDEX|VERIFY|ADJUSTL|ADJUSTR|SCAN|LEN_TRIM|REPEAT|TRIM" + + "|KIND|SELECTED_INT_KIND|SELECTED_REAL_KIND" + + "|LOGICAL" + + "|IOR|IAND|NOT|IEOR| ISHFT|ISHFTC|BTEST|IBSET|IBCLR|BITSIZE" + + "|TRANSFER" + + "|RADIX|DIGITS|MINEXPONENT|MAXEXPONENT|PRECISION|RANGE|HUGE|TINY|EPSILON" + + "|EXPONENT|SCALE|NEAREST|FRACTION|SET_EXPONENT|SPACING|RRSPACING" + + "|LBOUND|SIZE|UBOUND" + + "|MASK" + + "|MATMUL|DOT_PRODUCT" + + "|SUM|PRODUCT|MAXVAL|MINVAL|COUNT|ANY|ALL" + + "|ALLOCATED|SIZE|SHAPE|LBOUND|UBOUND" + + "|MERGE|SPREAD|PACK|UNPACK" + + "|RESHAPE" + + "|TRANSPOSE|EOSHIFT|CSHIFT" + + "|MAXLOC|MINLOC" + + @"|ASSOCIATED)\b(\()" + , + new Dictionary + { + {1, ScopeName.Intrinsic }, + {2, ScopeName.Brackets }, + }), + // Intrinsic functions + new LanguageRule( + @"(?i)(call)\s+(" + + "DATE_AND_TIME|SYSTEM_CLOCK" + + "|RANDOM_NUMBER|RANDOM_SEED" + + "|MVBITS" + + ")\b" + , + new Dictionary + { + {1, ScopeName.Keyword }, + {2, ScopeName.Intrinsic }, + }), + // Special Character + new LanguageRule( + @"\=|\*|\+|\\|\-|\.\w+\.|>|<|::|%|,|;|\?|\$", + new Dictionary + { + { 0, ScopeName.SpecialCharacter }, + }), + // Line Continuation + new LanguageRule( + @"&", + new Dictionary + { + { 0, ScopeName.Continuation }, + }), + // Number + new LanguageRule( + @"\b[0-9.]+(_\w+)?\b", + new Dictionary + { + { 0, ScopeName.Number }, + }), + // Brackets + new LanguageRule( + @"[\(\)\[\]]", + new Dictionary + { + { 0, ScopeName.Brackets }, + }), + // Preprocessor keywords + new LanguageRule( + @"(?i)(?:#define|#elif|#elifdef|#elifndef|#else|#endif|#error|#if|#ifdef|#ifndef|#include|#line|#pragma|#undef)\b", + new Dictionary + { + { 0, ScopeName.PreprocessorKeyword }, + }), + // General keywords + new LanguageRule( + @"(?i)\b(?:end|use|do|enddo|select|endselect|case|endcase|if|then|else|endif|implicit|none" + + @"|do\s+while|call|public|private|protected|where|go\s*to|file|block|data|blockdata" + + @"|end\s*blockdata|default|procedure|include|go\s*to|allocate|deallocate|open|close|write|stop|return)\b", + new Dictionary + { + { 0, ScopeName.Keyword }, + }) + }; + } + } + + public bool HasAlias(string lang) + { + switch (lang.ToLower()) + { + case "fortran": + return true; + + default: + return false; + } + } + + public override string ToString() + { + return Name; + } + } +} \ No newline at end of file diff --git a/ColorCode.Core/Languages.cs b/ColorCode.Core/Languages.cs index 0976474..7924e92 100644 --- a/ColorCode.Core/Languages.cs +++ b/ColorCode.Core/Languages.cs @@ -43,12 +43,13 @@ namespace ColorCode Load(); Load(); Load(); + Load(); } /// /// Gets an enumerable list of all loaded languages. /// - public static IEnumerable All + public static IEnumerable All { get { return LanguageRepository.All; } } @@ -221,7 +222,7 @@ namespace ColorCode /// Language support for Koka. public static ILanguage Koka { - get { return LanguageRepository.FindById(LanguageId.Koka); } + get { return LanguageRepository.FindById(LanguageId.Koka); } } /// @@ -242,6 +243,15 @@ namespace ColorCode get { return LanguageRepository.FindById(LanguageId.Markdown); } } + /// + /// Language support for Fortran. + /// + /// Language support for Fortran. + public static ILanguage Fortran + { + get { return LanguageRepository.FindById(LanguageId.Fortran); } + } + /// /// Finds a loaded language by the specified identifier. /// diff --git a/ColorCode.Core/Styling/StyleDictionary.cs b/ColorCode.Core/Styling/StyleDictionary.cs index fbd8f7b..753dba4 100644 --- a/ColorCode.Core/Styling/StyleDictionary.cs +++ b/ColorCode.Core/Styling/StyleDictionary.cs @@ -39,251 +39,277 @@ namespace ColorCode.Styling var red = "#FFFF0000"; var mediumTurqoise = "FF48D1CC"; var magenta = "FFFF00FF"; + var oliveDrab = "#FF6B8E23"; + var darkOliveGreen = "#FF556B2F"; + var darkCyan = "#FF008B8B"; return new StyleDictionary { new Style(ScopeName.PlainText) { - Foreground = black, - Background = white, - ReferenceName = "plainText" + Foreground = black, + Background = white, + ReferenceName = "plainText" }, new Style(ScopeName.HtmlServerSideScript) { - Background = yellow, - ReferenceName = "htmlServerSideScript" + Background = yellow, + ReferenceName = "htmlServerSideScript" }, new Style(ScopeName.HtmlComment) { - Foreground = green, - ReferenceName = "htmlComment" + Foreground = green, + ReferenceName = "htmlComment" }, new Style(ScopeName.HtmlTagDelimiter) { - Foreground = blue, - ReferenceName = "htmlTagDelimiter" + Foreground = blue, + ReferenceName = "htmlTagDelimiter" }, new Style(ScopeName.HtmlElementName) { - Foreground = dullRed, - ReferenceName = "htmlElementName" + Foreground = dullRed, + ReferenceName = "htmlElementName" }, new Style(ScopeName.HtmlAttributeName) { - Foreground = red, - ReferenceName = "htmlAttributeName" + Foreground = red, + ReferenceName = "htmlAttributeName" }, new Style(ScopeName.HtmlAttributeValue) { - Foreground = blue, - ReferenceName = "htmlAttributeValue" + Foreground = blue, + ReferenceName = "htmlAttributeValue" }, new Style(ScopeName.HtmlOperator) { - Foreground = blue, - ReferenceName = "htmlOperator" + Foreground = blue, + ReferenceName = "htmlOperator" }, new Style(ScopeName.Comment) { - Foreground = green, - ReferenceName = "comment" + Foreground = green, + ReferenceName = "comment" }, new Style(ScopeName.XmlDocTag) { - Foreground = gray, - ReferenceName = "xmlDocTag" + Foreground = gray, + ReferenceName = "xmlDocTag" }, new Style(ScopeName.XmlDocComment) { - Foreground = green, - ReferenceName = "xmlDocComment" + Foreground = green, + ReferenceName = "xmlDocComment" }, new Style(ScopeName.String) { - Foreground = dullRed, - ReferenceName = "string" + Foreground = dullRed, + ReferenceName = "string" }, new Style(ScopeName.StringCSharpVerbatim) { - Foreground = dullRed, - ReferenceName = "stringCSharpVerbatim" + Foreground = dullRed, + ReferenceName = "stringCSharpVerbatim" }, new Style(ScopeName.Keyword) { - Foreground = blue, - ReferenceName = "keyword" + Foreground = blue, + ReferenceName = "keyword" }, new Style(ScopeName.PreprocessorKeyword) { - Foreground = blue, - ReferenceName = "preprocessorKeyword" + Foreground = blue, + ReferenceName = "preprocessorKeyword" }, new Style(ScopeName.HtmlEntity) { - Foreground = red, - ReferenceName = "htmlEntity" + Foreground = red, + ReferenceName = "htmlEntity" }, new Style(ScopeName.XmlAttribute) { - Foreground = red, - ReferenceName = "xmlAttribute" + Foreground = red, + ReferenceName = "xmlAttribute" }, new Style(ScopeName.XmlAttributeQuotes) { - Foreground = black, - ReferenceName = "xmlAttributeQuotes" + Foreground = black, + ReferenceName = "xmlAttributeQuotes" }, new Style(ScopeName.XmlAttributeValue) { - Foreground = blue, - ReferenceName = "xmlAttributeValue" + Foreground = blue, + ReferenceName = "xmlAttributeValue" }, new Style(ScopeName.XmlCDataSection) { - Foreground = gray, - ReferenceName = "xmlCDataSection" + Foreground = gray, + ReferenceName = "xmlCDataSection" }, new Style(ScopeName.XmlComment) { - Foreground = green, - ReferenceName = "xmlComment" + Foreground = green, + ReferenceName = "xmlComment" }, new Style(ScopeName.XmlDelimiter) { - Foreground = blue, - ReferenceName = "xmlDelimiter" + Foreground = blue, + ReferenceName = "xmlDelimiter" }, new Style(ScopeName.XmlName) { - Foreground = dullRed, - ReferenceName = "xmlName" + Foreground = dullRed, + ReferenceName = "xmlName" }, new Style(ScopeName.ClassName) { - Foreground = mediumTurqoise, - ReferenceName = "className" + Foreground = mediumTurqoise, + ReferenceName = "className" }, new Style(ScopeName.CssSelector) { - Foreground = dullRed, - ReferenceName = "cssSelector" + Foreground = dullRed, + ReferenceName = "cssSelector" }, new Style(ScopeName.CssPropertyName) { - Foreground = red, - ReferenceName = "cssPropertyName" + Foreground = red, + ReferenceName = "cssPropertyName" }, new Style(ScopeName.CssPropertyValue) { - Foreground = blue, - ReferenceName = "cssPropertyValue" + Foreground = blue, + ReferenceName = "cssPropertyValue" }, new Style(ScopeName.SqlSystemFunction) { - Foreground = magenta, - ReferenceName = "sqlSystemFunction" + Foreground = magenta, + ReferenceName = "sqlSystemFunction" }, new Style(ScopeName.PowerShellAttribute) { - Foreground = powderBlue, - ReferenceName = "powershellAttribute" + Foreground = powderBlue, + ReferenceName = "powershellAttribute" }, new Style(ScopeName.PowerShellOperator) { - Foreground = gray, - ReferenceName = "powershellOperator" + Foreground = gray, + ReferenceName = "powershellOperator" }, new Style(ScopeName.PowerShellType) { - Foreground = teal, - ReferenceName = "powershellType" + Foreground = teal, + ReferenceName = "powershellType" }, new Style(ScopeName.PowerShellVariable) { - Foreground = orangeRed, - ReferenceName = "powershellVariable" + Foreground = orangeRed, + ReferenceName = "powershellVariable" }, new Style(ScopeName.Type) { - Foreground = teal, - ReferenceName = "type" + Foreground = teal, + ReferenceName = "type" }, new Style(ScopeName.TypeVariable) { - Foreground = teal, - Italic = true, - ReferenceName = "typeVariable" + Foreground = teal, + Italic = true, + ReferenceName = "typeVariable" }, new Style(ScopeName.NameSpace) { - Foreground = navy, - ReferenceName = "namespace" + Foreground = navy, + ReferenceName = "namespace" }, new Style(ScopeName.Constructor) { - Foreground = purple, - ReferenceName = "constructor" + Foreground = purple, + ReferenceName = "constructor" }, new Style(ScopeName.Predefined) { - Foreground = navy, - ReferenceName = "predefined" + Foreground = navy, + ReferenceName = "predefined" }, new Style(ScopeName.PseudoKeyword) { - Foreground = navy, - ReferenceName = "pseudoKeyword" + Foreground = navy, + ReferenceName = "pseudoKeyword" }, new Style(ScopeName.StringEscape) { - Foreground = gray, - ReferenceName = "stringEscape" + Foreground = gray, + ReferenceName = "stringEscape" }, new Style(ScopeName.ControlKeyword) { - Foreground = blue, - ReferenceName = "controlKeyword" + Foreground = blue, + ReferenceName = "controlKeyword" }, new Style(ScopeName.Number) { - ReferenceName = "number" + ReferenceName = "number" }, new Style(ScopeName.Operator) { - ReferenceName = "operator" + ReferenceName = "operator" }, new Style(ScopeName.Delimiter) { - ReferenceName = "delimiter" + ReferenceName = "delimiter" }, new Style(ScopeName.MarkdownHeader) { - Foreground = blue, - Bold = true, - ReferenceName = "markdownHeader" + Foreground = blue, + Bold = true, + ReferenceName = "markdownHeader" }, new Style(ScopeName.MarkdownCode) { - Foreground = teal, - ReferenceName = "markdownCode" + Foreground = teal, + ReferenceName = "markdownCode" }, new Style(ScopeName.MarkdownListItem) { - Bold = true, - ReferenceName = "markdownListItem" + Bold = true, + ReferenceName = "markdownListItem" }, new Style(ScopeName.MarkdownEmph) { - Italic = true, - ReferenceName = "italic" + Italic = true, + ReferenceName = "italic" }, new Style(ScopeName.MarkdownBold) { - Bold = true, - ReferenceName = "bold" - } + Bold = true, + ReferenceName = "bold" + }, + + new Style(ScopeName.BuiltinFunction) + { + Foreground = oliveDrab, + Bold = true, + ReferenceName = "builtinFunction" + }, + new Style(ScopeName.BuiltinValue) + { + Foreground = darkOliveGreen, + Bold = true, + ReferenceName = "builtinValue" + }, + new Style(ScopeName.Attribute) + { + Foreground = darkCyan, + Italic = true, + ReferenceName = "attribute" + }, + new Style(ScopeName.SpecialCharacter) + { + ReferenceName = "specialChar" + }, }; } } diff --git a/Tests/ColorCode.UWPTests/MainPage.xaml b/Tests/ColorCode.UWPTests/MainPage.xaml index e30936f..bec75e4 100644 --- a/Tests/ColorCode.UWPTests/MainPage.xaml +++ b/Tests/ColorCode.UWPTests/MainPage.xaml @@ -13,12 +13,11 @@ -