-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Calman102/master
Added support for Python and MATLAB code
- Loading branch information
Showing
4 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using ColorCode.Common; | ||
|
||
namespace ColorCode.Compilation.Languages | ||
{ | ||
public class MatLab : ILanguage | ||
{ | ||
public string Id | ||
{ | ||
get { return LanguageId.MatLab; } | ||
} | ||
|
||
public string Name | ||
{ | ||
get { return "MATLAB"; } | ||
} | ||
|
||
public string CssClassName | ||
{ | ||
get { return "matlab"; } | ||
} | ||
|
||
public string FirstLinePattern | ||
{ | ||
get | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public IList<LanguageRule> Rules | ||
{ | ||
get | ||
{ | ||
return new List<LanguageRule> | ||
{ | ||
// regular comments | ||
new LanguageRule( | ||
@"(%.*)\r?", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.Comment }, | ||
}), | ||
|
||
// regular strings | ||
new LanguageRule( | ||
@"(?<!\.)('[^\n]*?')", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.String }, | ||
}), | ||
new LanguageRule( | ||
@"""[^\n]*?""", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.String }, | ||
}), | ||
|
||
// keywords | ||
new LanguageRule( | ||
@"(?i)\b(break|case|catch|continue|else|elseif|end|for|function|global|if|otherwise|persistent|return|switch|try|while)\b", | ||
new Dictionary<int, string> | ||
{ | ||
{ 1, ScopeName.Keyword }, | ||
}), | ||
|
||
// line continuation | ||
new LanguageRule( | ||
@"\.\.\.", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.Continuation }, | ||
}), | ||
|
||
// numbers | ||
new LanguageRule( | ||
@"\b([0-9.]|[0-9.]+(e-*)(?=[0-9]))+?\b", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.Number }, | ||
}), | ||
}; | ||
} | ||
} | ||
|
||
public bool HasAlias(string lang) | ||
{ | ||
switch (lang.ToLower()) | ||
{ | ||
case "m": | ||
return true; | ||
|
||
case "mat": | ||
return true; | ||
|
||
case "matlab": | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Name; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using ColorCode.Common; | ||
|
||
namespace ColorCode.Compilation.Languages | ||
{ | ||
public class Python : ILanguage | ||
{ | ||
public string Id | ||
{ | ||
get { return LanguageId.Python; } | ||
} | ||
|
||
public string Name | ||
{ | ||
get { return "Python"; } | ||
} | ||
|
||
public string CssClassName | ||
{ | ||
get { return "python"; } | ||
} | ||
|
||
public string FirstLinePattern | ||
{ | ||
get | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public IList<LanguageRule> Rules | ||
{ | ||
get | ||
{ | ||
return new List<LanguageRule> | ||
{ | ||
// docstring comments | ||
new LanguageRule( | ||
@"(?<=:\s*)(""{3})([^""]+)(""{3})", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.Comment }, | ||
}), | ||
new LanguageRule( | ||
@"(?<=:\s*)('{3})([^']+)('{3})", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.Comment }, | ||
}), | ||
|
||
// regular comments | ||
new LanguageRule( | ||
@"(#.*)\r?", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.Comment }, | ||
}), | ||
|
||
// multi-line strings | ||
new LanguageRule( | ||
@"(?<==\s*f*b*r*u*)(""{3})([^""]+)(""{3})", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.String }, | ||
}), | ||
new LanguageRule( | ||
@"(?<==\s*f*b*r*u*)('{3})([^']+)('{3})", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.String }, | ||
}), | ||
|
||
// regular strings | ||
new LanguageRule( | ||
@"'[^\n]*?'", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.String }, | ||
}), | ||
new LanguageRule( | ||
@"""[^\n]*?""", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.String }, | ||
}), | ||
|
||
// keywords | ||
new LanguageRule( | ||
@"(?i)\b(False|await|else|import|pass|None|break|except|in|raise|True|class|finally|is|return|and|continue|for|lambda|try|as|def|from|" + | ||
@"nonlocal|while|assert|del|global|not|with|async|elif|if|or|yield|self)\b", | ||
new Dictionary<int, string> | ||
{ | ||
{ 1, ScopeName.Keyword }, | ||
}), | ||
|
||
// intrinsic functions | ||
new LanguageRule( | ||
@"(?i)\b(abs|delattr|hash|memoryview|set|all|dict|help|min|setattr|any|dir|hex|next|slice|ascii|divmod|id|object|sorted|bin|enumerate" + | ||
"|input|oct|staticmethod|bool|eval|int|open|str|breakpoint|exec|isinstance|ord|sum|bytearray|filter|issubclass|pow|super|bytes|float" + | ||
"|iter|print|tuple|callable|format|len|property|type|chr|frozenset|list|range|vars|classmethod|getattr|locals|repr|zip|compile|globals" + | ||
@"|map|reversed|__import__|complex|hasattr|max|round)\b", | ||
new Dictionary<int, string> | ||
{ | ||
{ 1, ScopeName.Intrinsic }, | ||
}), | ||
|
||
// numbers | ||
new LanguageRule( | ||
@"\b([0-9.]|[0-9.]+(e-*)(?=[0-9]))+?\b", | ||
new Dictionary<int, string> | ||
{ | ||
{ 0, ScopeName.Number }, | ||
}), | ||
}; | ||
} | ||
} | ||
|
||
public bool HasAlias(string lang) | ||
{ | ||
switch (lang.ToLower()) | ||
{ | ||
case "py": | ||
return true; | ||
|
||
case "python": | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Name; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters