Skip to content

Commit

Permalink
Intermediate commit for major atomic stage refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ender committed Dec 14, 2017
1 parent eb0cf72 commit 3922fe7
Show file tree
Hide file tree
Showing 28 changed files with 925 additions and 370 deletions.
61 changes: 0 additions & 61 deletions Retina/Retina/Configuration.cs

This file was deleted.

79 changes: 79 additions & 0 deletions Retina/Retina/Configuration/Config.cs
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Retina.Configuration
{
public class Config
{
public RegexOptions RegexOptions { get; set; }

// General configuration
public List<Limit> Limits { get; set; }

// This is only relevant for stages with multiple patterns.
// If this is true, the patterns will be chosen from greedily.
// If this is false, the patterns will be cycled through instead.
public bool Greedy { get; set; }

// If this is true, the stage's input will be used as the regex, and the first
// line of the stage will be used as the input.
public bool InputAsRegex { get; set; }

// If this is true, the matches and the separators between them
// will swap their roles.
public bool InvertMatches { get; set; }

// Custom regex modifiers

// How to treat overlapping matches.
public Overlaps Overlaps { get; set; }
// How to treat repeated matches.
public UniqueMatches UniqueMatches { get; set; }
// Require the regex to cover the entire input.
public bool Anchored { get; set; }

// General options which are interpreted differently by various stage types.
public bool Reverse { get; set; }
public bool Random { get; set; }
public string ListStart { get; set; }
public string ListSeparator { get; set; }
public string ListEnd { get; set; }

// Configuration for Output stages
public bool TrailingLinefeed { get; set; }
public bool PrintOnlyIfChanged { get; set; }

// Configuration for Split mode
public bool OmitEmpty { get; set; }
public bool OmitGroups { get; set; }

public Config()
{
Limits = new List<Limit>();
ListStart = "";
ListEnd = "";
ListSeparator = "\n";
}

public void Inherit(Config other)
{
RegexOptions ^= other.RegexOptions;
}

public void Merge(Config other)
{
RegexOptions ^= other.RegexOptions;
Limits.AddRange(other.Limits);
}

public Limit GetLimit(int i)
{
return i < Limits.Count ? Limits[i] : new Limit();
}
}
}
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Retina
namespace Retina.Configuration
{
public class Limit
{
Expand Down
41 changes: 21 additions & 20 deletions Retina/Retina/Modes.cs → Retina/Retina/Configuration/Modes.cs
@@ -1,20 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Retina
{
public enum Modes
{
Match,
Grep,
AntiGrep,
Split,
Replace,
Transliterate,
Sort,
Deduplicate
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Retina.Configuration
{
public enum Modes
{
Count,
Match,
Grep,
AntiGrep,
Split,
Replace,
Transliterate,
Sort,
Deduplicate
}
}
17 changes: 17 additions & 0 deletions Retina/Retina/Configuration/Overlaps.cs
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Retina.Configuration
{
public enum Overlaps
{
None = 0,
// Find up to one match per starting-position, even if they overlap.
OverlappingSimple,
// Find all substrings that can be matched, even if they overlap.
OverlappingAll,
}
}
17 changes: 17 additions & 0 deletions Retina/Retina/Configuration/UniqueMatches.cs
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Retina.Configuration
{
public enum UniqueMatches
{
Off = 0,
// If the same substring is matched multiple times, discard the new one.
KeepFirst,
// If the same substring is matched multiple times, discard the old one.
KeepLast,
}
}

0 comments on commit 3922fe7

Please sign in to comment.