add a scanner, but this seems to be a wrong solution. Change open-source head
This commit is contained in:
+6
-26
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAnalyzer.ASTGenerate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -35,7 +15,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexAnalyzerFrontEnd
|
||||
public partial class RegexAnalyzer
|
||||
{
|
||||
|
||||
private static AbstractSyntaxTree<RegexAstNode, RegexElementLabel> GenerateAST(
|
||||
+7
-28
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAnalyzer.ASTOptimize"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -39,7 +19,7 @@ using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexAnalyzerFrontEnd
|
||||
public partial class RegexAnalyzer
|
||||
{
|
||||
|
||||
private static RegexAstNode FlattenAlt(
|
||||
@@ -157,7 +137,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
}
|
||||
|
||||
private static void OptimizeTree(
|
||||
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree
|
||||
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree
|
||||
)
|
||||
{
|
||||
// phase0: scan container and remove no parent nodes
|
||||
@@ -214,7 +194,6 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void RotateConcat(
|
||||
+7
-27
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RegexInterpreter.IRGenerate"
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAnalyzer.IRGenerate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -40,7 +20,7 @@ using System.Xml;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexAnalyzerFrontEnd
|
||||
public partial class RegexAnalyzer
|
||||
{
|
||||
|
||||
internal static List<RegexIR> GenerateIR(
|
||||
+15
-35
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RegexAnalyzerFrontEnd.IROptimize"
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAnalyzer.IROptimize"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StgSharp.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -37,7 +17,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexAnalyzerFrontEnd
|
||||
public partial class RegexAnalyzer
|
||||
{
|
||||
|
||||
internal static void ScanAndOptimizeIR(
|
||||
@@ -243,7 +223,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
if (min == 0) {
|
||||
return -1;
|
||||
}
|
||||
string pattern = seq.Sequence;
|
||||
string pattern = seq.Pattern;
|
||||
int pattern_size = pattern.Length;
|
||||
if (pattern_size > flatten_size) {
|
||||
opt.Add(ir);
|
||||
@@ -400,14 +380,14 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
if (ir is IRegexCount { Min: 1, Max: 1 })
|
||||
{
|
||||
string pattern;
|
||||
switch (ir.Command & RegexIRCommand.Count)
|
||||
switch (ir.CommandMask & RegexIRCommand.Count)
|
||||
{
|
||||
case RegexIRCommand.Count_Complex:
|
||||
RegexCountComplexIR complex = Unsafe.As<RegexCountComplexIR>(ir);
|
||||
return complex.CommandCount;
|
||||
case RegexIRCommand.Count_Seq:
|
||||
RegexCountSeqIR seq = Unsafe.As<RegexCountSeqIR>(ir);
|
||||
pattern = seq.Sequence;
|
||||
pattern = seq.Pattern;
|
||||
opt.Add(new RegexMatchSeqIR(pattern));
|
||||
return 0;
|
||||
case RegexIRCommand.Count_Set:
|
||||
@@ -421,14 +401,14 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
} else if (ir is IRegexCount { Min: 0, Max: 1 })
|
||||
{
|
||||
string pattern;
|
||||
switch (ir.Command & RegexIRCommand.Count)
|
||||
switch (ir.CommandMask & RegexIRCommand.Count)
|
||||
{
|
||||
case RegexIRCommand.Count_Complex:
|
||||
RegexCountComplexIR complex = Unsafe.As<RegexCountComplexIR>(ir);
|
||||
return complex.CommandCount;
|
||||
case RegexIRCommand.Count_Seq:
|
||||
RegexCountSeqIR seq = Unsafe.As<RegexCountSeqIR>(ir);
|
||||
pattern = seq.Sequence;
|
||||
pattern = seq.Pattern;
|
||||
opt.Add(new RegexTryIR(1));
|
||||
opt.Add(new RegexMatchSeqIR(pattern));
|
||||
return 0;
|
||||
@@ -497,20 +477,20 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
}
|
||||
bool is_greedy = count.IsGreedy;
|
||||
string pattern;
|
||||
switch (ir.Command & RegexIRCommand.Count)
|
||||
switch (ir.CommandMask & RegexIRCommand.Count)
|
||||
{
|
||||
case RegexIRCommand.Count_Complex:
|
||||
RegexCountComplexIR complex = Unsafe.As<RegexCountComplexIR>(ir);
|
||||
return complex.CommandCount;
|
||||
case RegexIRCommand.Count_Seq:
|
||||
RegexCountSeqIR seq = Unsafe.As<RegexCountSeqIR>(ir);
|
||||
pattern = seq.Sequence;
|
||||
pattern = seq.Pattern;
|
||||
opt.Add(new RegexMatchSeqIR(pattern));
|
||||
opt.Add(new RegexCountSeqIR(0, -1, is_greedy, pattern));
|
||||
return 0;
|
||||
case RegexIRCommand.Count_Set:
|
||||
RegexCountSeqIR set = Unsafe.As<RegexCountSeqIR>(ir);
|
||||
pattern = set.Sequence;
|
||||
pattern = set.Pattern;
|
||||
opt.Add(new RegexMatchSeqIR(pattern));
|
||||
opt.Add(new RegexCountSeqIR(0, -1, is_greedy, pattern));
|
||||
return 0;
|
||||
@@ -0,0 +1,112 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAnalyzer.InfoScan"
|
||||
// Project: StgSharp
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexAnalyzer
|
||||
{
|
||||
|
||||
internal static RegexInterpreterInfo ScanInfo(
|
||||
List<RegexIR> ir
|
||||
)
|
||||
{
|
||||
RegexInterpreterInfo info = new();
|
||||
int process_count = 0;
|
||||
|
||||
ReadOnlySpan<RegexIR> irSpan = CollectionsMarshal.AsSpan(ir);
|
||||
|
||||
int max_region = 0;
|
||||
int min_length = 0;
|
||||
int single_line_count = 0;
|
||||
|
||||
ScanSpan(irSpan);
|
||||
return info;
|
||||
|
||||
void ScanSpan(
|
||||
ReadOnlySpan<RegexIR> ir_span
|
||||
)
|
||||
{
|
||||
do
|
||||
{
|
||||
int count = int.Min(8, ir_span.Length - process_count);
|
||||
ReadOnlySpan<RegexIR> window = ir_span.Slice(process_count, count);
|
||||
RegexIRPrefix prefix;
|
||||
if (window[0].CommandMask == RegexIRCommand.Match_Seq)
|
||||
{
|
||||
RegexMatchSeqIR match_seq = Unsafe.As<RegexMatchSeqIR>(window[0]);
|
||||
min_length += match_seq.Pattern.Length;
|
||||
prefix = match_seq.Prefix;
|
||||
max_region = int.Max(max_region, prefix.WorkingRegion);
|
||||
if ((prefix.Mask & RegexIRPrefixMask.ObserveMethod) == RegexIRPrefixMask.Observe_Line)
|
||||
{
|
||||
int line_idx = prefix.ObserveSource;
|
||||
RegexIR source = ir[line_idx];
|
||||
if (!source.SingleLineResultRequired)
|
||||
{
|
||||
source.SingleLineResultIndex = line_idx;
|
||||
single_line_count++;
|
||||
}
|
||||
}
|
||||
process_count++;
|
||||
} else if (window[0] is RegexFindSeqIR find_seq)
|
||||
{
|
||||
min_length += find_seq.Pattern.Length;
|
||||
prefix = find_seq.Prefix;
|
||||
max_region = int.Max(max_region, prefix.WorkingRegion);
|
||||
if ((prefix.Mask & RegexIRPrefixMask.ObserveMethod) == RegexIRPrefixMask.Observe_Line)
|
||||
{
|
||||
int line_idx = prefix.ObserveSource;
|
||||
RegexIR source = ir[line_idx];
|
||||
if (!source.SingleLineResultRequired)
|
||||
{
|
||||
source.SingleLineResultIndex = line_idx;
|
||||
single_line_count++;
|
||||
}
|
||||
}
|
||||
process_count++;
|
||||
} else if (window[0] is RegexCountSeqIR count_seq)
|
||||
{
|
||||
min_length += count_seq.Pattern.Length * count_seq.Min;
|
||||
prefix = count_seq.Prefix;
|
||||
max_region = int.Max(max_region, prefix.WorkingRegion);
|
||||
if ((prefix.Mask & RegexIRPrefixMask.ObserveMethod) == RegexIRPrefixMask.Observe_Line)
|
||||
{
|
||||
int line_idx = prefix.ObserveSource;
|
||||
RegexIR source = ir[line_idx];
|
||||
if (!source.SingleLineResultRequired)
|
||||
{
|
||||
source.SingleLineResultIndex = line_idx;
|
||||
single_line_count++;
|
||||
}
|
||||
}
|
||||
process_count++;
|
||||
} else if (window[0] is RegexMatchSetIR) { }
|
||||
} while (process_count < ir.Count);
|
||||
}
|
||||
}
|
||||
|
||||
internal struct RegexInterpreterInfo
|
||||
{
|
||||
|
||||
public int RegionCount { get; set; }
|
||||
|
||||
public int MinPredictLength { get; set; }
|
||||
|
||||
public int SingleLineResultCount { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+136
-76
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RegexAnalyzerFrontEnd.PrefixEmit"
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAnalyzer.PrefixEmit"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -34,7 +14,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public static partial class RegexAnalyzerFrontEnd
|
||||
public static partial class RegexAnalyzer
|
||||
{
|
||||
|
||||
internal static List<RegexIR> EmitPrefix(
|
||||
@@ -65,22 +45,35 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
emit_window = region[index..];
|
||||
|
||||
int emitResult;
|
||||
if ((emitResult = TryEmitGroupFindPack(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
if ((emitResult =
|
||||
TryEmitGroupFindPack(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
{
|
||||
index += emitResult;
|
||||
} else if ((emitResult = TryEmitTryGroupTail(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
} else if ((emitResult =
|
||||
TryEmitTryGroupTail(emit_window, result, currentRegion,
|
||||
lineBase)) > 0)
|
||||
{
|
||||
index += emitResult;
|
||||
} else if ((emitResult = TryEmitAltChain(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
} else if ((emitResult =
|
||||
TryEmitAltChain(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
{
|
||||
index += emitResult;
|
||||
} else if ((emitResult = TryEmitAltSuccessTail(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
} else if ((emitResult =
|
||||
TryEmitAltSuccessTail(emit_window, result, currentRegion,
|
||||
lineBase)) > 0)
|
||||
{
|
||||
index += emitResult;
|
||||
} else if ((emitResult = TryEmitAltFailTail(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
} else if ((emitResult =
|
||||
TryEmitAltFailTail(emit_window, result, currentRegion,
|
||||
lineBase)) > 0)
|
||||
{
|
||||
index += emitResult;
|
||||
} else if ((emitResult = TryEmitTryIR(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
} else if ((emitResult =
|
||||
TryEmitComplexIR(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
{
|
||||
index += emitResult;
|
||||
} else if ((emitResult =
|
||||
TryEmitTryIR(emit_window, result, currentRegion, lineBase)) > 0)
|
||||
{
|
||||
index += emitResult;
|
||||
} else
|
||||
@@ -111,12 +104,8 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
}
|
||||
|
||||
int tryOutputIndex = result.Count;
|
||||
int emitCount = TryEmitTryIR(
|
||||
origin,
|
||||
result,
|
||||
currentRegion,
|
||||
lineBase,
|
||||
foldSingleInstructionTry: false);
|
||||
int emitCount = TryEmitTryIR(origin, result, currentRegion, lineBase,
|
||||
foldSingleInstructionTry:false);
|
||||
if (emitCount <= 0 || result[tryOutputIndex] is not RegexTryIR emittedTry) {
|
||||
return -1;
|
||||
}
|
||||
@@ -125,18 +114,14 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
int regionId = emittedTry.Prefix.WorkingRegion;
|
||||
|
||||
RegexIR prefixedPop = CloneIR(pop, regionId);
|
||||
ApplyPrefix(
|
||||
prefixedPop,
|
||||
regionId,
|
||||
RegexIRPrefixMask.Prev_Fail | RegexIRPrefixMask.Observe_Region,
|
||||
regionId);
|
||||
ApplyPrefix(prefixedPop, regionId,
|
||||
RegexIRPrefixMask.Prev_Fail | RegexIRPrefixMask.Observe_Region,
|
||||
regionId);
|
||||
|
||||
RegexIR prefixedPack = CloneIR(pack, regionId);
|
||||
ApplyPrefix(
|
||||
prefixedPack,
|
||||
regionId,
|
||||
RegexIRPrefixMask.Prev_Success | RegexIRPrefixMask.Observe_Region,
|
||||
regionId);
|
||||
ApplyPrefix(prefixedPack, regionId,
|
||||
RegexIRPrefixMask.Prev_Success | RegexIRPrefixMask.Observe_Region,
|
||||
regionId);
|
||||
|
||||
result.Add(prefixedPop);
|
||||
result.Add(prefixedPack);
|
||||
@@ -164,12 +149,15 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
RegexIR previous = result[^1];
|
||||
observeRegion = GetObservedRegion(previous, currentRegion);
|
||||
GetObservation(previous, result, lineBase, currentRegion, out observeMask, out observeSource);
|
||||
ApplyPrefix(previous, observeRegion, RegexIRPrefixMask.Pop_Success, observeRegion);
|
||||
GetObservation(previous, result, lineBase, currentRegion, out observeMask,
|
||||
out observeSource);
|
||||
ApplyPrefix(previous, observeRegion, RegexIRPrefixMask.Pop_Success,
|
||||
observeRegion);
|
||||
}
|
||||
|
||||
RegexIRPrefixMask mask = RegexIRPrefixMask.Prev_Fail | observeMask;
|
||||
int emit_count = TryEmitTryIR(origin[2..], result, currentRegion, lineBase, mask, observeSource, observeRegion);
|
||||
int emit_count = TryEmitTryIR(origin[2..], result, currentRegion, lineBase, mask,
|
||||
observeSource, observeRegion);
|
||||
return emit_count < 0 ? -1 : emit_count + 2;
|
||||
}
|
||||
|
||||
@@ -211,23 +199,86 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
return -1;
|
||||
}
|
||||
|
||||
GetObservation(
|
||||
previous,
|
||||
result,
|
||||
lineBase,
|
||||
currentRegion,
|
||||
out RegexIRPrefixMask observeMask,
|
||||
out int observeSource);
|
||||
GetObservation(previous, result, lineBase, currentRegion,
|
||||
out RegexIRPrefixMask observeMask, out int observeSource);
|
||||
RegexIR prefixedPop = CloneIR(pop, currentRegion);
|
||||
ApplyPrefix(
|
||||
prefixedPop,
|
||||
currentRegion,
|
||||
RegexIRPrefixMask.Prev_Fail | observeMask,
|
||||
observeSource);
|
||||
ApplyPrefix(prefixedPop, currentRegion, RegexIRPrefixMask.Prev_Fail | observeMask,
|
||||
observeSource);
|
||||
result.Add(prefixedPop);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TryEmitComplexIR(
|
||||
ReadOnlySpan<RegexIR> origin,
|
||||
List<RegexIR> result,
|
||||
int currentRegion,
|
||||
int lineBase
|
||||
)
|
||||
{
|
||||
if (origin.Length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (origin[0] is RegexCountComplexIR count)
|
||||
{
|
||||
int commandCount = count.CommandCount;
|
||||
if (origin.Length < commandCount + 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
List<RegexIR> sub_ir = new(commandCount);
|
||||
EmitPrefix(origin.Slice(1, commandCount), sub_ir, currentRegion,
|
||||
lineBase + result.Count + 1);
|
||||
|
||||
RegexCountComplexIR newCount = new(count.Min, count.Max, count.IsGreedy,
|
||||
sub_ir.Count)
|
||||
{
|
||||
IsFullyOptimized = count.IsFullyOptimized,
|
||||
Prefix =
|
||||
new RegexIRPrefix(
|
||||
count.Prefix.WorkingRegion == 0 ?
|
||||
currentRegion :
|
||||
count.Prefix.WorkingRegion,
|
||||
count.Prefix.Mask,
|
||||
count.Prefix.ObserveSource)
|
||||
};
|
||||
|
||||
result.Add(newCount);
|
||||
result.AddRange(sub_ir);
|
||||
return commandCount + 1;
|
||||
}
|
||||
|
||||
if (origin[0] is RegexFindComplexIR { CommandCount: > 0 } find)
|
||||
{
|
||||
int commandCount = find.CommandCount;
|
||||
if (origin.Length < commandCount + 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
List<RegexIR> sub_ir = new(commandCount);
|
||||
EmitPrefix(origin.Slice(1, commandCount), sub_ir, currentRegion,
|
||||
lineBase + result.Count + 1);
|
||||
|
||||
RegexFindComplexIR newFind = new(find.IsNearest, sub_ir.Count)
|
||||
{
|
||||
IsFullyOptimized = find.IsFullyOptimized,
|
||||
Prefix =
|
||||
new RegexIRPrefix(
|
||||
find.Prefix.WorkingRegion == 0 ?
|
||||
currentRegion :
|
||||
find.Prefix.WorkingRegion,
|
||||
find.Prefix.Mask,
|
||||
find.Prefix.ObserveSource)
|
||||
};
|
||||
|
||||
result.Add(newFind);
|
||||
result.AddRange(sub_ir);
|
||||
return commandCount + 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// convert TRY into region
|
||||
int TryEmitTryIR(
|
||||
ReadOnlySpan<RegexIR> origin,
|
||||
@@ -256,7 +307,8 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
if (foldSingleInstructionTry &&
|
||||
commandCount == 1 &&
|
||||
IsFoldableSingleTryInstruction(origin[1])) {
|
||||
IsFoldableSingleTryInstruction(origin[1]))
|
||||
{
|
||||
RegexIR folded = CloneIR(origin[1], regionId);
|
||||
int foldedObserveSource =
|
||||
(mask & RegexIRPrefixMask.ObserveMethod) != 0 ?
|
||||
@@ -316,7 +368,8 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
};
|
||||
RegexPackIR newPack = new(pack.Condition, pack.GroupName)
|
||||
{
|
||||
Prefix = new RegexIRPrefix(
|
||||
Prefix =
|
||||
new RegexIRPrefix(
|
||||
regionId,
|
||||
pack.Prefix.Mask | RegexIRPrefixMask.Prev_Success | RegexIRPrefixMask.Observe_Line,
|
||||
-1)
|
||||
@@ -362,7 +415,8 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
for (int i = 0; i < result.Count; i++)
|
||||
{
|
||||
RegexIRPrefix prefix = result[i].Prefix;
|
||||
if ((prefix.Mask & RegexIRPrefixMask.Observe_Line) == 0) {
|
||||
if ((prefix.Mask & RegexIRPrefixMask.Observe_Line) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -386,12 +440,14 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
RegexIR ir
|
||||
)
|
||||
{
|
||||
return ir is RegexMatchSeqIR or
|
||||
RegexMatchSetIR or
|
||||
RegexCountSeqIR or
|
||||
RegexCountSetIR or
|
||||
RegexFindSeqIR or
|
||||
RegexFindComplexIR;
|
||||
return ir is
|
||||
RegexMatchSeqIR or
|
||||
RegexMatchSetIR or
|
||||
RegexCountSeqIR or
|
||||
RegexCountSetIR or
|
||||
RegexFindSeqIR or
|
||||
//RegexFindSetIR or
|
||||
RegexFindComplexIR;
|
||||
}
|
||||
|
||||
static void ApplyPrefix(
|
||||
@@ -423,12 +479,16 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
RegexMatchSetIR match => new RegexMatchSetIR(match.Charset),
|
||||
RegexConditionIR condition => new RegexConditionIR(condition.SuccessCase, condition.FailCase),
|
||||
RegexPackIR pack => new RegexPackIR(pack.Condition, pack.GroupName),
|
||||
RegexCountComplexIR count => new RegexCountComplexIR(count.Min, count.Max, count.IsGreedy, count.CommandCount)
|
||||
RegexCountComplexIR count => new RegexCountComplexIR(count.Min, count.Max,
|
||||
count.IsGreedy,
|
||||
count.CommandCount)
|
||||
{
|
||||
IsFullyOptimized = count.IsFullyOptimized
|
||||
},
|
||||
RegexCountSeqIR count => new RegexCountSeqIR(count.Min, count.Max, count.IsGreedy, count.Sequence),
|
||||
RegexCountSetIR count => new RegexCountSetIR(count.Min, count.Max, count.IsGreedy, count.CharSet),
|
||||
RegexCountSeqIR count => new RegexCountSeqIR(count.Min, count.Max,
|
||||
count.IsGreedy, count.Pattern),
|
||||
RegexCountSetIR count => new RegexCountSetIR(count.Min, count.Max,
|
||||
count.IsGreedy, count.CharSet),
|
||||
RegexTryIR tryIR => new RegexTryIR(tryIR.CommandCount)
|
||||
{
|
||||
IsFullyOptimized = tryIR.IsFullyOptimized
|
||||
+6
-26
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RegexAnalyzerBackEnd.CharSetEmitter"
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAnalyzer.SourceGen.CharSetEmitter"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -0,0 +1,64 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAnalyzer.SourceGen"
|
||||
// Project: StgSharp
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using Microsoft.CodeAnalysis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexAnalyzer
|
||||
{
|
||||
|
||||
internal static StringBuilder GenerateSource(
|
||||
List<RegexIR> ir
|
||||
)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
List<StringBuilder> sub_match_list = [];
|
||||
|
||||
ReadOnlySpan<RegexIR> source = CollectionsMarshal.AsSpan(ir);
|
||||
RegexIR[] window = new RegexIR[8];
|
||||
Span<RegexIR> scan_win = window;
|
||||
|
||||
_ = sb.AppendLine(@"public abstract MatchResult Match(ReadOnlySpan<char> text)")//
|
||||
.AppendLine(@"{");
|
||||
|
||||
int index = 0;
|
||||
do
|
||||
{
|
||||
int count = int.Min(8, source.Length - index);
|
||||
source.Slice(index, count).CopyTo(scan_win);
|
||||
} while (index < ir.Count);
|
||||
|
||||
foreach (StringBuilder _sub in sub_match_list)
|
||||
{
|
||||
_ = sb.AppendLine() //
|
||||
.Append(_sub);
|
||||
}
|
||||
|
||||
return sb;
|
||||
/*
|
||||
int TryGenerateMatch(
|
||||
Span<RegexIR> scan_win,
|
||||
StringBuilder sb
|
||||
)
|
||||
{
|
||||
if (scan_win[0] is RegexMatchSeqIR seq) {
|
||||
_ = sb.AppendLine(string.Empty);
|
||||
}
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+9
-27
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RegexAnalyzerFrontEnd"
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAnalyzer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -68,13 +48,14 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
}
|
||||
|
||||
public static partial class RegexAnalyzerFrontEnd
|
||||
public static partial class RegexAnalyzer
|
||||
{
|
||||
|
||||
public static TextRegexSource Analyze(
|
||||
string regex
|
||||
)
|
||||
{
|
||||
#pragma warning disable CA1031
|
||||
// RegexAnalyzer interpreter = new();
|
||||
// interpreter._source = regex;
|
||||
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree;
|
||||
@@ -106,6 +87,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
return new TextRegexSource(regex, tree, base_ir, null, ex);
|
||||
}
|
||||
#pragma warning restore CA1031
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RegexAnalyzerBackEnd"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using Microsoft.CodeAnalysis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
internal static partial class RegexAnalyzerBackEnd
|
||||
{
|
||||
|
||||
internal static string GenerateSource(
|
||||
List<RegexIR> ir
|
||||
)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexAstNode"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@@ -35,7 +15,9 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
// private RegexAstNode _left, _right;
|
||||
|
||||
public RegexAstNode(Token<RegexElementLabel> source)
|
||||
public RegexAstNode(
|
||||
Token<RegexElementLabel> source
|
||||
)
|
||||
{
|
||||
Source = source;
|
||||
}
|
||||
@@ -87,14 +69,19 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
public Token<RegexElementLabel> Source { get; private protected set; }
|
||||
|
||||
public void AppendNode(RegexAstNode nextToken)
|
||||
public void AppendNode(
|
||||
RegexAstNode nextToken
|
||||
)
|
||||
{
|
||||
Next = nextToken;
|
||||
nextToken.Previous = this;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static (bool Valid, int Value) ComparePrecedence(RegexElementLabel left, RegexElementLabel right)
|
||||
public static (bool Valid, int Value) ComparePrecedence(
|
||||
RegexElementLabel left,
|
||||
RegexElementLabel right
|
||||
)
|
||||
{
|
||||
left &= RegexElementLabel.OPERATOR;
|
||||
right &= RegexElementLabel.OPERATOR;
|
||||
@@ -106,19 +93,25 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsNullOrEmpty(RegexAstNode node)
|
||||
public static bool IsNullOrEmpty(
|
||||
RegexAstNode node
|
||||
)
|
||||
{
|
||||
return node is null || ReferenceEquals(node, Empty);
|
||||
}
|
||||
/**/
|
||||
|
||||
public void PrependNode(RegexAstNode previousNode)
|
||||
public void PrependNode(
|
||||
RegexAstNode previousNode
|
||||
)
|
||||
{
|
||||
Previous = previousNode;
|
||||
previousNode.Next = this;
|
||||
}
|
||||
|
||||
public void RemoveChild(RegexAstNode node)
|
||||
public void RemoveChild(
|
||||
RegexAstNode node
|
||||
)
|
||||
{
|
||||
if (Left == node)
|
||||
{
|
||||
@@ -136,7 +129,9 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
return new EmptyRegexAstNode();
|
||||
}
|
||||
|
||||
internal void RemoveAndAsChild(bool useLeft)
|
||||
internal void RemoveAndAsChild(
|
||||
bool useLeft
|
||||
)
|
||||
{
|
||||
if (useLeft)
|
||||
{
|
||||
@@ -161,7 +156,9 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
/// <param name="node">
|
||||
/// The node to replace the current node with.
|
||||
/// </param>
|
||||
internal void ReplaceBy(RegexAstNode node)
|
||||
internal void ReplaceBy(
|
||||
RegexAstNode node
|
||||
)
|
||||
{
|
||||
Source = node.Source;
|
||||
Left = node.Left;
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexElementLabel"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexIR.Abstraction"
|
||||
// Project: StgSharp
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
internal interface IRegexComplex
|
||||
{
|
||||
|
||||
bool IsFullyOptimized { get; set; }
|
||||
|
||||
int CommandCount { get; set; }
|
||||
|
||||
}
|
||||
|
||||
internal interface IRegexSequence
|
||||
{
|
||||
|
||||
string Pattern { get; }
|
||||
|
||||
}
|
||||
|
||||
internal interface IRegexCount
|
||||
{
|
||||
|
||||
bool IsGreedy { get; }
|
||||
|
||||
bool IsStar { get; }
|
||||
|
||||
bool IsPlus { get; }
|
||||
|
||||
int Min { get; }
|
||||
|
||||
int Max { get; }
|
||||
|
||||
}
|
||||
|
||||
internal abstract class RegexIR
|
||||
{
|
||||
|
||||
protected RegexIR(
|
||||
RegexIRCommand command
|
||||
)
|
||||
{
|
||||
CommandMask = command;
|
||||
}
|
||||
|
||||
public bool SingleLineResultRequired { get; set; }
|
||||
|
||||
public int SingleLineResultIndex { get; set; }
|
||||
|
||||
public RegexIRPrefix Prefix { get; set; }
|
||||
|
||||
internal RegexIRCommand CommandMask { get; init; }
|
||||
|
||||
internal string AsCommand(
|
||||
int lineNum
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t{Prefix}\t{AsCommand()}";
|
||||
}
|
||||
|
||||
protected abstract string AsCommand();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexIR.Prefix"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -61,9 +41,9 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
return $"{WorkingRegion:D4}, {DisplayMask(Mask , RegexIRPrefixMask.ExeCondition):D1}, {DisplayMask(Mask , RegexIRPrefixMask.PopCondition):D1}, {DisplayMask(Mask ,RegexIRPrefixMask.ObserveMethod):D1}, {ObserveSource:D4}";
|
||||
}
|
||||
|
||||
private int DisplayMask(
|
||||
RegexIRPrefixMask mask,
|
||||
RegexIRPrefixMask range
|
||||
private readonly int DisplayMask(
|
||||
RegexIRPrefixMask mask,
|
||||
RegexIRPrefixMask range
|
||||
)
|
||||
{
|
||||
return range switch
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexIR"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -53,37 +33,14 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
Match = Match_Seq | Match_Set,
|
||||
Count = Count_Seq | Count_Set | Count_Complex,
|
||||
|
||||
}
|
||||
|
||||
internal interface IRegexComplex
|
||||
{
|
||||
|
||||
bool IsFullyOptimized { get; set; }
|
||||
|
||||
int CommandCount { get; set; }
|
||||
|
||||
}
|
||||
|
||||
internal interface IRegexCount
|
||||
{
|
||||
|
||||
bool IsGreedy { get; }
|
||||
|
||||
bool IsStar { get; }
|
||||
|
||||
bool IsPlus { get; }
|
||||
|
||||
int Min { get; }
|
||||
|
||||
int Max { get; }
|
||||
Find = Find_Seq | Find_Set | Find_Complex,
|
||||
|
||||
}
|
||||
|
||||
internal sealed class RegexFindComplexIR(
|
||||
bool nearest,
|
||||
int count
|
||||
) : RegexIR, IRegexComplex
|
||||
) : RegexIR(RegexIRCommand.Find_Complex), IRegexComplex
|
||||
{
|
||||
|
||||
public bool IsFullyOptimized { get; set; }
|
||||
@@ -92,8 +49,6 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
public int CommandCount { get; set; } = count;
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Find_Complex;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
@@ -103,36 +58,16 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
}
|
||||
|
||||
internal abstract class RegexIR
|
||||
{
|
||||
|
||||
public RegexIRPrefix Prefix { get; set; }
|
||||
|
||||
internal abstract RegexIRCommand Command { get; }
|
||||
|
||||
internal string AsCommand(
|
||||
int lineNum
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t{Prefix}\t{AsCommand()}";
|
||||
}
|
||||
|
||||
protected abstract string AsCommand();
|
||||
|
||||
}
|
||||
|
||||
internal sealed class RegexFindSeqIR(
|
||||
string pattern,
|
||||
bool isFirst
|
||||
) : RegexIR
|
||||
) : RegexIR(RegexIRCommand.Find_Seq), IRegexSequence
|
||||
{
|
||||
|
||||
public bool IsFirst { get; } = isFirst;
|
||||
|
||||
public string Pattern { get; } = pattern;
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Find_Seq;
|
||||
|
||||
protected override string AsCommand(
|
||||
)
|
||||
{
|
||||
@@ -146,13 +81,11 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
/// </summary>
|
||||
internal sealed class RegexMatchSeqIR(
|
||||
string pattern
|
||||
) : RegexIR
|
||||
) : RegexIR(RegexIRCommand.Match_Seq), IRegexSequence
|
||||
{
|
||||
|
||||
public string Pattern { get; } = pattern;
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Match_Seq;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
@@ -164,13 +97,11 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal sealed class RegexMatchSetIR(
|
||||
string charset
|
||||
) : RegexIR
|
||||
) : RegexIR(RegexIRCommand.Match_Set)
|
||||
{
|
||||
|
||||
public string Charset { get; } = charset;
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Match_Set;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
@@ -183,15 +114,13 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
internal sealed class RegexConditionIR(
|
||||
int success,
|
||||
int fail
|
||||
) : RegexIR
|
||||
) : RegexIR(RegexIRCommand.Condition)
|
||||
{
|
||||
|
||||
public int SuccessCase { get; } = success;
|
||||
|
||||
public int FailCase { get; } = fail;
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Condition;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
@@ -204,15 +133,13 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
internal sealed class RegexPackIR(
|
||||
bool condition,
|
||||
string name = ""
|
||||
) : RegexIR
|
||||
) : RegexIR(RegexIRCommand.Pack)
|
||||
{
|
||||
|
||||
public bool Condition { get; } = condition;
|
||||
|
||||
public string GroupName { get; } = name;
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Pack;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
@@ -227,7 +154,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
int max,
|
||||
bool isGreedy,
|
||||
int operation
|
||||
) : RegexIR, IRegexCount, IRegexComplex
|
||||
) : RegexIR(RegexIRCommand.Count_Complex), IRegexCount, IRegexComplex
|
||||
{
|
||||
|
||||
public bool IsGreedy { get; } = isGreedy;
|
||||
@@ -244,8 +171,6 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
public int CommandCount { get; set; } = operation;
|
||||
|
||||
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Complex;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
@@ -260,7 +185,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
int max,
|
||||
bool isGreedy,
|
||||
string seq
|
||||
) : RegexIR, IRegexCount
|
||||
) : RegexIR(RegexIRCommand.Count_Seq), IRegexCount, IRegexSequence
|
||||
{
|
||||
|
||||
public bool IsGreedy { get; } = isGreedy;
|
||||
@@ -273,15 +198,13 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
public int Max { get; } = max;
|
||||
|
||||
public string Sequence { get; } = seq.Length == 2 && seq[0] == '\\' ? seq[1..2] : seq;
|
||||
|
||||
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Seq;
|
||||
public string Pattern { get; } = seq.Length == 2 && seq[0] == '\\' ? seq[1..2] : seq;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"COUNT_SEQ {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} SEQ: \"{Sequence}\"";
|
||||
return $"COUNT_SEQ {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} SEQ: \"{Pattern}\"";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -291,7 +214,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
int max,
|
||||
bool isGreedy,
|
||||
string set
|
||||
) : RegexIR, IRegexCount
|
||||
) : RegexIR(RegexIRCommand.Count_Set), IRegexCount
|
||||
{
|
||||
|
||||
public bool IsGreedy { get; } = isGreedy;
|
||||
@@ -308,8 +231,6 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
public string CharSet { get; } = set;
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Count_Set;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
@@ -321,15 +242,13 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal sealed class RegexTryIR(
|
||||
int count
|
||||
) : RegexIR, IRegexComplex
|
||||
) : RegexIR(RegexIRCommand.Try), IRegexComplex
|
||||
{
|
||||
|
||||
public bool IsFullyOptimized { get; set; }
|
||||
|
||||
public int CommandCount { get; set; } = count;
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Try;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
@@ -341,13 +260,11 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal sealed class RegexPopIR(
|
||||
bool isSuccess
|
||||
) : RegexIR
|
||||
) : RegexIR(RegexIRCommand.Pop)
|
||||
{
|
||||
|
||||
public bool IsSuccess { get; } = isSuccess;
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Pop;
|
||||
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexIRGenerator"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexTokenParser"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexTokenReader"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="RegexTokenUtil"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="TextHelper"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="TextRegex"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -36,17 +16,10 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
public abstract class TextRegex
|
||||
{
|
||||
|
||||
public abstract bool IsMatch(
|
||||
ReadOnlySpan<char> text
|
||||
public abstract MatchResult Match(
|
||||
ReadOnlySpan<char> text
|
||||
);
|
||||
|
||||
public ref struct Match
|
||||
{
|
||||
|
||||
private ReadOnlySpan<char> _sequence;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ref struct MatchResult { }
|
||||
|
||||
Reference in New Issue
Block a user