Skip to content

Commit

Permalink
Refactoring only
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierGuinart committed Jan 15, 2017
1 parent 22df541 commit 6933f48
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 137 deletions.
12 changes: 6 additions & 6 deletions Coloring/Classification/ClassificationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ internal static class OrdinaryClassificationDefinition
/// </summary>
[Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32Opcode)]
internal static ClassificationTypeDefinition opcode = null;
internal static ClassificationTypeDefinition Opcode = null;

/// <summary>
/// Defines the "directive" classification type.
/// </summary>
[Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32Directive)]
internal static ClassificationTypeDefinition directive = null;
internal static ClassificationTypeDefinition Directive = null;

/// <summary>
/// Defines the "datadefine" classification type.
/// </summary>
[Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32DataDefine)]
internal static ClassificationTypeDefinition datadefine = null;
internal static ClassificationTypeDefinition Datadefine = null;

/// <summary>
/// Defines the "text" classification type.
/// </summary>
[Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32Text)]
internal static ClassificationTypeDefinition text = null;
internal static ClassificationTypeDefinition Text = null;

/// <summary>
/// Defines the "comment" classification type.
/// </summary>
[Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32Comment)]
internal static ClassificationTypeDefinition comment = null;
internal static ClassificationTypeDefinition Comment = null;

#endregion
}
}
32 changes: 14 additions & 18 deletions Coloring/Classification/Merlin32sClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace VSMerlin32.Coloring.Classification
[TagType(typeof(ClassificationTag))]
internal sealed class Merlin32ClassifierProvider : ITaggerProvider
{

[Export]
[Name("Merlin32")]
[BaseDefinition("code")]
Expand All @@ -28,34 +27,33 @@ internal sealed class Merlin32ClassifierProvider : ITaggerProvider
internal IClassificationTypeRegistryService ClassificationTypeRegistry = null;

[Import]
internal IBufferTagAggregatorFactoryService aggregatorFactory = null;
internal IBufferTagAggregatorFactoryService AggregatorFactory = null;

public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
{
ITagAggregator<Merlin32TokenTag> merlin32TagAggregator =
AggregatorFactory.CreateTagAggregator<Merlin32TokenTag>(buffer);

ITagAggregator<Merlin32TokenTag> Merlin32TagAggregator =
aggregatorFactory.CreateTagAggregator<Merlin32TokenTag>(buffer);

return new Merlin32Classifier(buffer, Merlin32TagAggregator, ClassificationTypeRegistry) as ITagger<T>;
return new Merlin32Classifier(buffer, merlin32TagAggregator, ClassificationTypeRegistry) as ITagger<T>;
}
}

internal sealed class Merlin32Classifier : ITagger<ClassificationTag>
{
ITextBuffer _buffer;
ITagAggregator<Merlin32TokenTag> _aggregator;
IDictionary<Merlin32TokenTypes, IClassificationType> _Merlin32Types;
private ITextBuffer _buffer;
private readonly ITagAggregator<Merlin32TokenTag> _aggregator;
private readonly IDictionary<Merlin32TokenTypes, IClassificationType> _merlin32Types;

internal Merlin32Classifier(ITextBuffer buffer,
ITagAggregator<Merlin32TokenTag> Merlin32TagAggregator,
ITagAggregator<Merlin32TokenTag> merlin32TagAggregator,
IClassificationTypeRegistryService typeService)
{
_buffer = buffer;
_aggregator = Merlin32TagAggregator;
_Merlin32Types = new Dictionary<Merlin32TokenTypes, IClassificationType>();
_aggregator = merlin32TagAggregator;
_merlin32Types = new Dictionary<Merlin32TokenTypes, IClassificationType>();

foreach (Merlin32TokenTypes token in Enum.GetValues(typeof(Merlin32TokenTypes)))
_Merlin32Types[token] = typeService.GetClassificationType(token.ToString());
_merlin32Types[token] = typeService.GetClassificationType(token.ToString());
}

public event EventHandler<SnapshotSpanEventArgs> TagsChanged
Expand All @@ -66,13 +64,11 @@ public event EventHandler<SnapshotSpanEventArgs> TagsChanged

public IEnumerable<ITagSpan<ClassificationTag>> GetTags(NormalizedSnapshotSpanCollection spans)
{

foreach (var tagSpan in this._aggregator.GetTags(spans))
foreach (var tagSpan in _aggregator.GetTags(spans))
{
var tagSpans = tagSpan.Span.GetSpans(spans[0].Snapshot);
yield return
new TagSpan<ClassificationTag>(tagSpans[0],
new ClassificationTag(_Merlin32Types[tagSpan.Tag.Tokentype]));
yield return
new TagSpan<ClassificationTag>(tagSpans[0], new ClassificationTag(_merlin32Types[tagSpan.Tag.Tokentype]));
}
}
}
Expand Down
64 changes: 32 additions & 32 deletions Coloring/Merlin32CodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ namespace VSMerlin32.Coloring
{
internal class Merlin32CodeHelper
{
const string CommentRegex = @"((\u003B)|(\u002A))(.*)"; // ;
const string TextRegex = @"(""|')[^']*(""|')";
private static readonly string CommentRegex = @"((\u003B)|(\u002A))(.*)"; // ;
private static readonly string TextRegex = @"(""|')[^']*(""|')";
// OPCODE_REG and below are initialized dynamically below.
const string RegexBoilerplate = @"(\b|\s)(?<{0}>{1})(\b|\s)";
const string Opcode = "OPCODE";
const string Data = "DATA";
const string Directive = "DIRECTIVE";
const string Elup = "ELUP";
static string OpcodeRegex = "";
static string DirectiveRegex = "";
static string DataRegex = "";
private static readonly string RegexBoilerplate = @"(\b|\s)(?<{0}>{1})(\b|\s)";
private static readonly string Opcode = "OPCODE";
private static readonly string Data = "DATA";
private static readonly string Directive = "DIRECTIVE";
private static readonly string Elup = "ELUP";
private static string _opcodeRegex = "";
private static string _directiveRegex = "";
private static string _dataRegex = "";

public static IEnumerable<SnapshotHelper> GetTokens(SnapshotSpan span)
{
string TempRegex; // temp var string
Expand Down Expand Up @@ -47,13 +47,13 @@ public static IEnumerable<SnapshotHelper> GetTokens(SnapshotSpan span)
TempRegex = "";
foreach (Merlin32Opcodes token in Enum.GetValues(typeof(Merlin32Opcodes)))
{
TempRegex += (token.ToString() + ("|"));
TempRegex += token.ToString() + ("|");
}
// we remove the last "|" added
TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|"));
OpcodeRegex = string.Format(RegexBoilerplate, Opcode, TempRegex);
TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|", StringComparison.Ordinal));
_opcodeRegex = string.Format(RegexBoilerplate, Opcode, TempRegex);

reg = new Regex(OpcodeRegex,RegexOptions.IgnoreCase);
reg = new Regex(_opcodeRegex,RegexOptions.IgnoreCase);
Match opcodeMatch = reg.Match(formattedLine);
if (opcodeMatch.Success)
{
Expand All @@ -68,21 +68,21 @@ public static IEnumerable<SnapshotHelper> GetTokens(SnapshotSpan span)
// OG NEW
// DIRECTIVES
TempRegex = "";
string ElupDirective = Resources.directives.ELUP;
string elupDirective = Resources.directives.ELUP;
foreach (Merlin32Directives token in Enum.GetValues(typeof(Merlin32Directives)))
{
if (token.ToString() != ElupDirective)
TempRegex += (token.ToString() + ("|"));
if (token.ToString() != elupDirective)
TempRegex += token.ToString() + ("|");
}
// we remove the last "|" added
TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|"));
DirectiveRegex = string.Format(RegexBoilerplate, Directive, TempRegex);
reg = new Regex(DirectiveRegex, RegexOptions.IgnoreCase);
Match DirectiveMatch = reg.Match(formattedLine);
if (DirectiveMatch.Success)
TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|", StringComparison.Ordinal));
_directiveRegex = string.Format(RegexBoilerplate, Directive, TempRegex);

reg = new Regex(_directiveRegex, RegexOptions.IgnoreCase);
Match directiveMatch = reg.Match(formattedLine);
if (directiveMatch.Success)
{
foreach (Capture directive in DirectiveMatch.Groups[Directive].Captures)
foreach (Capture directive in directiveMatch.Groups[Directive].Captures)
{
if (directive.Index < commentMatch)
yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, directive.Index + curLoc), directive.Length), Merlin32TokenTypes.Merlin32Directive);
Expand All @@ -91,10 +91,10 @@ public static IEnumerable<SnapshotHelper> GetTokens(SnapshotSpan span)

// We also need to check for special ELUP directive...
reg = new Regex(Resources.directives.ELUPRegex);
Match ElupMatch = reg.Match(formattedLine);
if (ElupMatch.Success)
Match elupMatch = reg.Match(formattedLine);
if (elupMatch.Success)
{
foreach (Capture elup in ElupMatch.Groups[Elup].Captures)
foreach (Capture elup in elupMatch.Groups[Elup].Captures)
{
if (elup.Index < commentMatch)
yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, elup.Index + curLoc), elup.Length), Merlin32TokenTypes.Merlin32Directive);
Expand All @@ -106,13 +106,13 @@ public static IEnumerable<SnapshotHelper> GetTokens(SnapshotSpan span)
TempRegex = "";
foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines)))
{
TempRegex += (token.ToString() + ("|"));
TempRegex += token.ToString() + ("|");
}
// we remove the last "|" added
TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|"));
DataRegex = string.Format(RegexBoilerplate, Data, TempRegex);
TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|", StringComparison.Ordinal));
_dataRegex = string.Format(RegexBoilerplate, Data, TempRegex);

reg = new Regex(DataRegex, RegexOptions.IgnoreCase);
reg = new Regex(_dataRegex, RegexOptions.IgnoreCase);
Match dataMatch = reg.Match(formattedLine);
if (dataMatch.Success)
{
Expand Down
20 changes: 9 additions & 11 deletions Coloring/Merlin32TokenTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@

namespace VSMerlin32.Coloring
{

[Export(typeof(ITaggerProvider))]
[ContentType("Merlin32")]
[TagType(typeof(Merlin32TokenTag))]
internal sealed class Merlin32TokenTagProvider : ITaggerProvider
{

public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
{
return new Merlin32TokenTagger(buffer) as ITagger<T>;
}
}

public class Merlin32TokenTag : ITag
public class Merlin32TokenTag : ITag
{
public Merlin32TokenTypes Tokentype { get; private set; }

Expand All @@ -35,17 +33,16 @@ public Merlin32TokenTag(Merlin32TokenTypes type)

internal sealed class Merlin32TokenTagger : ITagger<Merlin32TokenTag>
{

ITextBuffer _buffer;
IDictionary<string, Merlin32TokenTypes> _Merlin32Types;
private ITextBuffer _buffer;
private readonly IDictionary<string, Merlin32TokenTypes> _merlin32Types;

internal Merlin32TokenTagger(ITextBuffer buffer)
{
_buffer = buffer;
_Merlin32Types = new Dictionary<string, Merlin32TokenTypes>();
_merlin32Types = new Dictionary<string, Merlin32TokenTypes>();

foreach (Merlin32TokenTypes token in Enum.GetValues(typeof(Merlin32TokenTypes)))
_Merlin32Types.Add(token.ToString(), token);
_merlin32Types.Add(token.ToString(), token);
}

public event EventHandler<SnapshotSpanEventArgs> TagsChanged
Expand All @@ -61,14 +58,15 @@ public IEnumerable<ITagSpan<Merlin32TokenTag>> GetTags(NormalizedSnapshotSpanCol
{
ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();
int curLoc = containingLine.Start.Position;

string formattedLine = containingLine.GetText();

foreach (SnapshotHelper item in Merlin32CodeHelper.GetTokens(curSpan))
{
if (item.Snapshot.IntersectsWith(curSpan))
yield return new TagSpan<Merlin32TokenTag>(item.Snapshot,
new Merlin32TokenTag(item.TokenType));
{
yield return new TagSpan<Merlin32TokenTag>(item.Snapshot, new Merlin32TokenTag(item.TokenType));
}
}

//add an extra char location because of the space
Expand Down
9 changes: 2 additions & 7 deletions Coloring/Merlin32TokenTypes.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Resources;
using System.Reflection;
using System.Collections;

namespace VSMerlin32
{
Expand Down Expand Up @@ -51,7 +46,7 @@ public enum Merlin32DataDefines
DA, DW, DDB, DFB, DB, ADR, ADRL, HEX, DS,
DC, DE, /* ? */
ASC, DCI, INV, FLS, REV, STR, STRL,
CHK
CHK
}

class Merlin32KeywordsHelper
Expand Down Expand Up @@ -85,7 +80,7 @@ public Merlin32KeywordsHelper()
foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines)))
{
_Merlin32KeywordsQuickInfo[token.ToString()] = rsData.GetString(token.ToString());
}
}
/*
_Merlin32OpcodesQuickInfo[Merlin32Opcodes.ORG.ToString()] = VSMerlin32.strings.ORG;
*/
Expand Down
Loading

0 comments on commit 6933f48

Please sign in to comment.