Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 38 additions & 48 deletions std/regex.d
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,8 @@ enum RegexOption: uint {
multiline = 0x10,
singleline = 0x20
}
alias TypeTuple!('g', 'i', 'x', 'U', 'm', 's') RegexOptionNames;//do not reorder this list
//do not reorder this list
alias RegexOptionNames = TypeTuple!('g', 'i', 'x', 'U', 'm', 's');
static assert( RegexOption.max < 0x80);
enum RegexInfo : uint { oneShot = 0x80 }
alias Escapables = TypeTuple!('[', ']', '\\', '^', '$', '.', '|', '?', ',', '-',
Expand Down Expand Up @@ -751,7 +752,7 @@ enum maxCharsetUsed = 6;

enum maxCachedTries = 8;

alias CodepointTrie!8 Trie;
alias Trie = CodepointTrie!8;

Trie[const(CodepointSet)] trieCache;

Expand Down Expand Up @@ -790,7 +791,7 @@ auto memoizeExpr(string expr)()
{
if(__ctfe)
return mixin(expr);
alias typeof(mixin(expr)) T;
alias T = typeof(mixin(expr));
static T slot;
static bool initialized;
if(!initialized)
Expand All @@ -806,7 +807,7 @@ auto memoizeExpr(string expr)()
+/
@trusted const(CodepointSet) getUnicodeSet(in char[] name, bool negated, bool casefold)
{
alias comparePropertyName ucmp;
alias ucmp = comparePropertyName;
CodepointSet s;

//unicode property
Expand Down Expand Up @@ -898,10 +899,7 @@ enum maxCompiledLength = 2^^18;
//amounts to up to 4 Mb of auxilary table for matching
enum maxCumulativeRepetitionLength = 2^^20;

template BasicElementOf(Range)
{
alias Unqual!(ElementEncodingType!Range) BasicElementOf;
}
alias BasicElementOf(Range) = Unqual!(ElementEncodingType!Range);

struct Parser(R)
if (isForwardRange!R && is(ElementType!R : dchar))
Expand Down Expand Up @@ -1713,8 +1711,8 @@ struct Parser(R)
return tuple(set, op);
}

alias Stack!(CodepointSet) ValStack;
alias Stack!(Operator) OpStack;
alias ValStack = Stack!(CodepointSet);
alias OpStack = Stack!(Operator);

//parse and store IR for CodepointSet
void parseCharset()
Expand Down Expand Up @@ -1955,7 +1953,7 @@ struct Parser(R)
//\ - assumed to be processed, p - is current
const(CodepointSet) parseUnicodePropertySpec(bool negated)
{
alias comparePropertyName ucmp;
alias ucmp = comparePropertyName;
enum MAX_PROPERTY = 128;
char[MAX_PROPERTY] result;
uint k = 0;
Expand Down Expand Up @@ -1990,7 +1988,7 @@ struct Parser(R)
throw new RegexException(app.data);
}

alias BasicElementOf!R Char;
alias Char = BasicElementOf!R;
//packages parsing results into a RegEx object
@property Regex!Char program()
{
Expand Down Expand Up @@ -2062,7 +2060,7 @@ public struct Regex(Char)
@property string back() { return groups[end-1].name; }
@property bool empty() { return start >= end; }
@property size_t length() { return end - start; }
alias length opDollar;
alias opDollar = length;
@property NamedGroupRange save()
{
return NamedGroupRange(groups, start, end);
Expand Down Expand Up @@ -2523,8 +2521,8 @@ int quickTestFwd(RegEx)(uint pc, dchar front, const ref RegEx re)
public struct StaticRegex(Char)
{
private:
alias BacktrackingMatcher!(true) Matcher;
alias bool function(ref Matcher!Char) @trusted MatchFn;
alias Matcher = BacktrackingMatcher!(true);
alias MatchFn = bool function(ref Matcher!Char) @trusted;
MatchFn nativeFn;
public:
Regex!Char _regex;
Expand Down Expand Up @@ -3005,8 +3003,8 @@ unittest
{
foreach(i, v; TypeTuple!(char, wchar, dchar))
{
alias v Char;
alias immutable(v)[] String;
alias Char = v;
alias String = immutable(v)[];
auto r = regex(to!String(`abc$`));
auto kick = Kick!Char(r, new uint[256]);
assert(kick.length == 3, text(Kick.stringof," ",v.stringof, " == ", kick.length));
Expand All @@ -3031,8 +3029,8 @@ unittest
{
foreach(i, v;TypeTuple!(char, wchar, dchar))
{
alias v Char;
alias immutable(v)[] String;
alias Char = v;
alias String = immutable(v)[];
auto r = regex(to!String(`abc[a-z]`));
auto kick = Kick!Char(r, new uint[256]);
auto x = kick.search(to!String("abbabca"), 0);
Expand Down Expand Up @@ -3062,15 +3060,15 @@ unittest
test_flex!(ShiftOr)();
}

alias ShiftOr Kickstart;
alias Kickstart = ShiftOr;

//Simple UTF-string abstraction compatible with stream interface
struct Input(Char)
if(is(Char :dchar))
{
alias size_t DataIndex;
alias DataIndex = size_t;
enum { isLoopback = false };
alias const(Char)[] String;
alias String = const(Char)[];
String _origin;
size_t _index;

Expand Down Expand Up @@ -3110,7 +3108,7 @@ struct Input(Char)

struct BackLooper
{
alias size_t DataIndex;
alias DataIndex = size_t;
enum { isLoopback = true };
String _origin;
size_t _index;
Expand Down Expand Up @@ -3169,7 +3167,7 @@ template BacktrackingMatcher(bool CTregex)
@trusted struct BacktrackingMatcher(Char, Stream = Input!Char)
if(is(Char : dchar))
{
alias Stream.DataIndex DataIndex;
alias DataIndex = Stream.DataIndex;
struct State
{//top bit in pc is set if saved along with matches
DataIndex index;
Expand All @@ -3179,7 +3177,7 @@ template BacktrackingMatcher(bool CTregex)
enum stateSize = State.sizeof / size_t.sizeof;
enum initialStack = 1<<16;
alias const(Char)[] String;
alias Regex!Char RegEx;
alias RegEx = Regex!Char;
alias MatchFn = bool function (ref BacktrackingMatcher!(Char, Stream));
RegEx re; //regex program
static if(CTregex)
Expand Down Expand Up @@ -4611,7 +4609,7 @@ enum OneShot { Fwd, Bwd };
@trusted struct ThompsonMatcher(Char, Stream = Input!Char)
if(is(Char : dchar))
{
alias Stream.DataIndex DataIndex;
alias DataIndex = Stream.DataIndex;
Thread!DataIndex* freelist;
ThreadList!DataIndex clist, nlist;
DataIndex[] merge;
Expand Down Expand Up @@ -5485,8 +5483,8 @@ enum OneShot { Fwd, Bwd };
@trusted public struct Captures(R, DIndex = size_t)
if(isSomeString!R)
{//@trusted because of union inside
alias DIndex DataIndex;
alias R String;
alias DataIndex = DIndex;
alias String = R;
private:
R _input;
bool _empty;
Expand Down Expand Up @@ -5653,8 +5651,8 @@ unittest//verify example
if(isSomeString!R)
{
private:
alias BasicElementOf!R Char;
alias Engine!Char EngineType;
alias Char = BasicElementOf!R;
alias EngineType = Engine!Char;
EngineType _engine;
R _input;
Captures!(R,EngineType.DataIndex) _captures;
Expand Down Expand Up @@ -5765,8 +5763,8 @@ public:

private @trusted auto matchOnce(alias Engine, RegEx, R)(R input, RegEx re)
{
alias BasicElementOf!R Char;
alias Engine!Char EngineType;
alias Char = BasicElementOf!R;
alias EngineType = Engine!Char;

size_t size = EngineType.initialMemory(re);
void[] memory = enforce(malloc(size))[0..size];
Expand Down Expand Up @@ -5824,9 +5822,9 @@ public auto regexImpl(S)(S pattern, const(char)[] flags="")
template ctRegexImpl(alias pattern, string flags=[])
{
enum r = regex(pattern, flags);
alias BasicElementOf!(typeof(pattern)) Char;
alias Char = BasicElementOf!(typeof(pattern));
enum source = ctGenRegExCode(r);
alias BacktrackingMatcher!(true) Matcher;
alias Matcher = BacktrackingMatcher!(true);
@trusted bool func(ref Matcher!Char matcher)
{
debug(std_regex_ctr) pragma(msg, source);
Expand All @@ -5836,8 +5834,6 @@ template ctRegexImpl(alias pattern, string flags=[])
}

/++
Experimental feature.

Compile regular expression using CTFE
and generate optimized native machine code for matching it.

Expand All @@ -5847,16 +5843,10 @@ template ctRegexImpl(alias pattern, string flags=[])
pattern = Regular expression
flags = The _attributes (g, i, m and x accepted)
+/
public template ctRegex(alias pattern, alias flags=[])
{
enum ctRegex = ctRegexImpl!(pattern, flags).nr;
}
enum ctRegex(alias pattern, alias flags=[]) = ctRegexImpl!(pattern, flags).nr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have removed the "public"...

#1745
https://d.puremagic.com/issues/show_bug.cgi?id=11671


template isRegexFor(RegEx, R)
{
enum isRegexFor = is(RegEx == Regex!(BasicElementOf!R))
|| is(RegEx == StaticRegex!(BasicElementOf!R));
}
enum isRegexFor(RegEx, R) = is(RegEx == Regex!(BasicElementOf!R))
|| is(RegEx == StaticRegex!(BasicElementOf!R));

/++
Start matching $(D input) to regex pattern $(D re),
Expand Down Expand Up @@ -6487,7 +6477,7 @@ public struct Splitter(Range, alias RegEx = Regex)
private:
Range _input;
size_t _offset;
alias typeof(match(Range.init,RegEx.init)) Rx;
alias Rx = typeof(match(Range.init,RegEx.init));
Rx _match;

@trusted this(Range input, RegEx separator)
Expand Down Expand Up @@ -6917,7 +6907,7 @@ unittest
int i;
foreach(Char; TypeTuple!( char, wchar, dchar))
{
alias immutable(Char)[] String;
alias String = immutable(Char)[];
String produceExpected(M,Range)(auto ref M m, Range fmt)
{
auto app = appender!(String)();
Expand Down Expand Up @@ -7225,7 +7215,7 @@ unittest
{
return std.string.toUpper(m.hit);
}
alias v String;
alias String = v;
assert(std.regex.replace!(matchFn)(to!String("ark rapacity"), regex(to!String("r")), to!String("c"))
== to!String("ack rapacity"));
assert(std.regex.replace!(matchFn)(to!String("ark rapacity"), regex(to!String("r"), "g"), to!String("c"))
Expand Down