before merge
This commit is contained in:
@@ -49,7 +49,7 @@ else()
|
||||
set(STGSHARP_ARCH_TAG ${SN_RESOLVED_ARCH_NAME})
|
||||
endif()
|
||||
|
||||
set(STGSHARP_BUILD_OUTPUT_DIR ${STGSHARP_SOLUTION_ROOT}/build/${STGSHARP_OS_TAG}-${STGSHARP_ARCH_TAG})
|
||||
set(STGSHARP_BUILD_OUTPUT_DIR ${STGSHARP_SOLUTION_ROOT}/cmake_build/${STGSHARP_OS_TAG}_${STGSHARP_ARCH_TAG})
|
||||
set(STGSHARP_OBJECT_ROOT_DIR ${STGSHARP_SOLUTION_ROOT}/obj/${PROJECT_NAME})
|
||||
set(STGSHARP_NATIVE_PROJECT_FILES
|
||||
${STGSHARP_NATIVE_SOURCES}
|
||||
|
||||
@@ -125,11 +125,11 @@ SN_MK_PROC_DECL_STD(float, avx, _fma, fma)
|
||||
register __m256 a1 = _mm256_load_ps((float *)&a_base->y[1]);
|
||||
register __m256 a2 = _mm256_load_ps((float *)&a_base->y[2]);
|
||||
register __m256 a3 = _mm256_load_ps((float *)&a_base->y[3]);
|
||||
|
||||
SN_MK_FMA_F32_AVX2_FMA_CYCLE(0);
|
||||
SN_MK_FMA_F32_AVX2_FMA_CYCLE(1);
|
||||
SN_MK_FMA_F32_AVX2_FMA_CYCLE(2);
|
||||
SN_MK_FMA_F32_AVX2_FMA_CYCLE(3);
|
||||
|
||||
SN_MK_FMA_F32_AVX2_CYCLE(0);
|
||||
SN_MK_FMA_F32_AVX2_CYCLE(1);
|
||||
SN_MK_FMA_F32_AVX2_CYCLE(2);
|
||||
SN_MK_FMA_F32_AVX2_CYCLE(3);
|
||||
}
|
||||
_mm256_store_ps((float *)&(ans_cur->y[0]), c0);
|
||||
_mm256_store_ps((float *)&(ans_cur->y[1]), c1);
|
||||
|
||||
@@ -2,36 +2,55 @@
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#define SN_MK_FMA_F32_512_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm512_fmadd_ps(a0, _mm512_permute_ps(b0, _FMA_SELECT(i)), c0); \
|
||||
c1 = _mm512_fmadd_ps(a1, _mm512_permute_ps(b1, _FMA_SELECT(i)), c1); \
|
||||
c2 = _mm512_fmadd_ps(a2, _mm512_permute_ps(b2, _FMA_SELECT(i)), c2); \
|
||||
c3 = _mm512_fmadd_ps(a3, _mm512_permute_ps(b3, _FMA_SELECT(i)), c3); \
|
||||
#define SN_MK_FMA_F32_512_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm512_fmadd_ps(c0, a0, _mm512_permute_ps(b0, _FMA_SELECT(i))); \
|
||||
c1 = _mm512_fmadd_ps(c1, a1, _mm512_permute_ps(b1, _FMA_SELECT(i))); \
|
||||
c2 = _mm512_fmadd_ps(c2, a2, _mm512_permute_ps(b2, _FMA_SELECT(i))); \
|
||||
c3 = _mm512_fmadd_ps(c3, a3, _mm512_permute_ps(b3, _FMA_SELECT(i))); \
|
||||
} while (0)
|
||||
|
||||
#define SN_MK_FMA_F32_AVX2_FMA_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm256_fmadd_ps(a0, _mm256_permute_ps(b0, _FMA_SELECT(i)), c0); \
|
||||
c1 = _mm256_fmadd_ps(a1, _mm256_permute_ps(b1, _FMA_SELECT(i)), c1); \
|
||||
c2 = _mm256_fmadd_ps(a2, _mm256_permute_ps(b2, _FMA_SELECT(i)), c2); \
|
||||
c3 = _mm256_fmadd_ps(a3, _mm256_permute_ps(b3, _FMA_SELECT(i)), c3); \
|
||||
#define SN_MK_FMA_F32_AVX2_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm256_fmadd_ps(c0, a0, _mm256_permute_ps(b0, _FMA_SELECT(i))); \
|
||||
c1 = _mm256_fmadd_ps(c1, a1, _mm256_permute_ps(b1, _FMA_SELECT(i))); \
|
||||
c2 = _mm256_fmadd_ps(c2, a2, _mm256_permute_ps(b2, _FMA_SELECT(i))); \
|
||||
c3 = _mm256_fmadd_ps(c3, a3, _mm256_permute_ps(b3, _FMA_SELECT(i))); \
|
||||
} while (0)
|
||||
|
||||
#define SN_MK_FMA_F32_AVX2_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm256_add_ps(_mm256_mul_ps(a0, _mm256_permute_ps(b0, _FMA_SELECT(i))), c0); \
|
||||
c1 = _mm256_add_ps(_mm256_mul_ps(a1, _mm256_permute_ps(b1, _FMA_SELECT(i))), c1); \
|
||||
c2 = _mm256_add_ps(_mm256_mul_ps(a2, _mm256_permute_ps(b2, _FMA_SELECT(i))), c2); \
|
||||
c3 = _mm256_add_ps(_mm256_mul_ps(a3, _mm256_permute_ps(b3, _FMA_SELECT(i))), c3); \
|
||||
#define SN_MK_FMA_F64_AVX2_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm512_fmadd_ps(c0, a0, _mm512_permutex_pd(b0, _FMA_SELECT(i))); \
|
||||
c1 = _mm512_fmadd_ps(c1, a1, _mm512_permutex_pd(b1, _FMA_SELECT(i))); \
|
||||
c2 = _mm512_fmadd_ps(c2, a2, _mm512_permutex_pd(b2, _FMA_SELECT(i))); \
|
||||
c3 = _mm512_fmadd_ps(c3, a3, _mm512_permutex_pd(b3, _FMA_SELECT(i))); \
|
||||
} while (0)
|
||||
|
||||
#define SN_MK_FMA_F64_AVX2_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm512_fmadd_ps(a0, _mm512_permutex_pd(b0, _FMA_SELECT(i)), c0); \
|
||||
c1 = _mm512_fmadd_ps(a1, _mm512_permutex_pd(b1, _FMA_SELECT(i)), c1); \
|
||||
c2 = _mm512_fmadd_ps(a2, _mm512_permutex_pd(b2, _FMA_SELECT(i)), c2); \
|
||||
c3 = _mm512_fmadd_ps(a3, _mm512_permutex_pd(b3, _FMA_SELECT(i)), c3); \
|
||||
#define SN_FMA_F32_512_PACK_COLUMN(col, target) \
|
||||
do { \
|
||||
register __m256 low = _mm512_castps512_ps256(col); \
|
||||
register __m256 high = _mm512_extractf32x8_ps(col, 1); \
|
||||
register __m256 half = _mm256_add_ps(high, low); \
|
||||
register __m128 high128 = _mm256_extractf32x4_ps(half, 1); \
|
||||
register __m128 low128 = _mm256_castps256_ps128(half); \
|
||||
register __m128 half128 = _mm_add_ps(high128, low128); \
|
||||
_mm_store_ps(target, half128); \
|
||||
} while (0)
|
||||
|
||||
#define SN_FMA_F32_AVX2_PACK_COLUMN(col, target) \
|
||||
do { \
|
||||
register __m128 high128 = _mm256_extractf32x4_ps(col, 1); \
|
||||
register __m128 low128 = _mm256_castps256_ps128(col); \
|
||||
register __m128 half128 = _mm_add_ps(high128, low128); \
|
||||
_mm_store_ps(target, half128); \
|
||||
} while (0)
|
||||
|
||||
#define SN_FMA_F64_512_PACK_COLUMN(col, target) \
|
||||
do { \
|
||||
register __m128 high128 = _mm256_extractf32x4_ps(col, 1); \
|
||||
register __m128 low128 = _mm256_castps256_ps128(col); \
|
||||
register __m128 half128 = _mm_add_ps(high128, low128); \
|
||||
_mm_store_ps(target, half128); \
|
||||
} while (0)
|
||||
|
||||
// double
|
||||
|
||||
@@ -28,16 +28,14 @@
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
internal class RegexAstNode : ISyntaxNode<RegexAstNode, RegexElementLabel>
|
||||
{
|
||||
|
||||
// private RegexAstNode _left, _right;
|
||||
|
||||
public RegexAstNode(
|
||||
Token<RegexElementLabel> source
|
||||
)
|
||||
public RegexAstNode(Token<RegexElementLabel> source)
|
||||
{
|
||||
Source = source;
|
||||
}
|
||||
@@ -89,19 +87,14 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
|
||||
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;
|
||||
@@ -113,25 +106,19 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
}
|
||||
|
||||
[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)
|
||||
{
|
||||
@@ -149,9 +136,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
return new EmptyRegexAstNode();
|
||||
}
|
||||
|
||||
internal void RemoveAndAsChild(
|
||||
bool useLeft
|
||||
)
|
||||
internal void RemoveAndAsChild(bool useLeft)
|
||||
{
|
||||
if (useLeft)
|
||||
{
|
||||
@@ -176,9 +161,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
/// <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;
|
||||
|
||||
@@ -31,7 +31,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
[Flags]
|
||||
public enum RegexElementLabel
|
||||
|
||||
@@ -32,7 +32,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
internal enum RegexIRCommand
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
internal class RegexIRGenerator
|
||||
{
|
||||
|
||||
+5
-11
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RegexInterpreter.IRGenerate"
|
||||
// file="RegexInterpreter.IREmit"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
@@ -38,14 +38,12 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexInterpreter
|
||||
{
|
||||
|
||||
internal static List<RegexIR> GenerateIR(
|
||||
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree
|
||||
)
|
||||
internal static List<RegexIR> GenerateIR(AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree)
|
||||
{
|
||||
return GenerateIRRecursion(tree.Root, 0).ToList();
|
||||
}
|
||||
@@ -57,8 +55,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
int min,
|
||||
int max,
|
||||
bool isGreedy,
|
||||
RegexAstNode right
|
||||
)
|
||||
RegexAstNode right)
|
||||
{
|
||||
bool isRightOperator = !RegexAstNode.IsNullOrEmpty(right) &&
|
||||
(right.Source.Flag & RegexElementLabel.OPERATOR) != 0;
|
||||
@@ -89,10 +86,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
}
|
||||
}
|
||||
|
||||
private static RegexIRGenerator GenerateIRRecursion(
|
||||
RegexAstNode node,
|
||||
int depth
|
||||
)
|
||||
private static RegexIRGenerator GenerateIRRecursion(RegexAstNode node, int depth)
|
||||
{
|
||||
#pragma warning disable IDE0010
|
||||
if (depth > 1024)
|
||||
@@ -37,7 +37,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexInterpreter
|
||||
{
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RegexInterpreter.SourceEmit"
|
||||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexInterpreter { }
|
||||
}
|
||||
@@ -35,7 +35,7 @@ using System.Text;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public partial class RegexInterpreter
|
||||
{
|
||||
@@ -58,9 +58,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
}
|
||||
}
|
||||
|
||||
public static RegexInterpreter Analyze(
|
||||
string regex
|
||||
)
|
||||
public static RegexInterpreter Analyze(string regex)
|
||||
{
|
||||
RegexInterpreter interpreter = new();
|
||||
interpreter._source = regex;
|
||||
@@ -222,14 +220,11 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
// TODO enum AST again , do ALT tail merge and simple ALT front merge
|
||||
}
|
||||
|
||||
private void ProcessOperator(
|
||||
RegexAstNode op
|
||||
)
|
||||
private void ProcessOperator(RegexAstNode op)
|
||||
{
|
||||
if (op.EqualityTypeConvert == RegexElementLabel.CONCAT)
|
||||
{
|
||||
if (_stack.TryPopOperand(out RegexAstNode? _1) &&
|
||||
_stack.TryPopOperand(out RegexAstNode? _2))
|
||||
if (_stack.TryPopOperand(out RegexAstNode? _1) && _stack.TryPopOperand(out RegexAstNode? _2))
|
||||
{
|
||||
op.Left = _2;
|
||||
op.Right = _1;
|
||||
@@ -255,8 +250,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
}
|
||||
} else if (op.EqualityTypeConvert == RegexElementLabel.ALT)
|
||||
{
|
||||
if (_stack.TryPopOperand(out RegexAstNode? _1) &&
|
||||
_stack.TryPopOperand(out RegexAstNode? _2))
|
||||
if (_stack.TryPopOperand(out RegexAstNode? _1) && _stack.TryPopOperand(out RegexAstNode? _2))
|
||||
{
|
||||
op.Left = _2;
|
||||
op.Right = _1;
|
||||
|
||||
@@ -34,7 +34,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
internal class RegexTokenParser : TokenParser<RegexElementLabel, RegexElementLabel>
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ using System.Security.Permissions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
internal class RegexTokenReader : ITokenReader<RegexElementLabel>
|
||||
{
|
||||
@@ -45,9 +45,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
|
||||
public RegexTokenReader() { }
|
||||
|
||||
public RegexTokenReader(
|
||||
string source
|
||||
)
|
||||
public RegexTokenReader(string source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
@@ -67,11 +65,9 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
{
|
||||
string value = _source[(pos + 1)..(pos + 3)];
|
||||
pos += 4;
|
||||
if (uint.TryParse(value, out uint code) &&
|
||||
Rune.TryCreate(code, out Rune result))
|
||||
if (uint.TryParse(value, out uint code) && Rune.TryCreate(code, out Rune result))
|
||||
{
|
||||
return new Token<RegexElementLabel>(result.ToString(), 0, pos,
|
||||
RegexElementLabel.UNIT);
|
||||
return new Token<RegexElementLabel>(result.ToString(), 0, pos, RegexElementLabel.UNIT);
|
||||
} else
|
||||
{
|
||||
throw new InvalidCastException($"Failed to convert {value} to a valid ascii code point.");
|
||||
@@ -80,11 +76,9 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
{
|
||||
string value = _source[(pos + 1)..(pos + 5)];
|
||||
pos += 6;
|
||||
if (uint.TryParse(value, out uint code) &&
|
||||
Rune.TryCreate(code, out Rune result))
|
||||
if (uint.TryParse(value, out uint code) && Rune.TryCreate(code, out Rune result))
|
||||
{
|
||||
return new Token<RegexElementLabel>(result.ToString(), 0, pos,
|
||||
RegexElementLabel.UNIT);
|
||||
return new Token<RegexElementLabel>(result.ToString(), 0, pos, RegexElementLabel.UNIT);
|
||||
} else
|
||||
{
|
||||
throw new InvalidCastException($"Failed to convert {value} to a valid unicode code point.");
|
||||
@@ -118,24 +112,21 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
{
|
||||
int length = (i - pos - 1);
|
||||
position = i + 1;
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(i + 1)], 0,
|
||||
position,
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(i + 1)], 0, position,
|
||||
RegexElementLabel.UNIT_SET);
|
||||
}
|
||||
}
|
||||
throw new InvalidOperationException("Unclosed character set");
|
||||
case '|':
|
||||
position = pos + 1;
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos,
|
||||
RegexElementLabel.ALT);
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.ALT);
|
||||
case '(':
|
||||
|
||||
// very comlex here
|
||||
return ReadGroupBeginToken();
|
||||
case ')':
|
||||
position = pos + 1;
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos,
|
||||
RegexElementLabel.GROUP_END);
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.GROUP_END);
|
||||
case '{':
|
||||
for (int i = pos + 1; i < _source.Length; i++)
|
||||
{
|
||||
@@ -150,26 +141,20 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
case '*' or '+':
|
||||
int count = pos + 1 >= _source.Length ? 1 : (_source[pos + 1] == '?' ? 2 : 1);
|
||||
position = pos + count;
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + count)], 0, pos,
|
||||
RegexElementLabel.COUNT);
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + count)], 0, pos, RegexElementLabel.COUNT);
|
||||
case '?':
|
||||
position = pos + 1;
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos,
|
||||
RegexElementLabel.COUNT);
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.COUNT);
|
||||
case '.':
|
||||
position = pos + 1;
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos,
|
||||
RegexElementLabel.UNIT);
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.UNIT);
|
||||
default:
|
||||
position = pos + 1;
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos,
|
||||
RegexElementLabel.UNIT);
|
||||
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.UNIT);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryReadToken(
|
||||
out Token<RegexElementLabel> t
|
||||
)
|
||||
public bool TryReadToken(out Token<RegexElementLabel> t)
|
||||
{
|
||||
if (IsEmpty)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.TextRegex
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
internal static class RegexTokenUtil
|
||||
{
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// 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.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis.Text
|
||||
{
|
||||
public abstract class TextRegex
|
||||
{
|
||||
public ref struct Match
|
||||
{
|
||||
private ReadOnlySpan<char> _sequence;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,17 +32,18 @@ using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
using StgSharp.Timing;
|
||||
using StgSharp.Timing;
|
||||
using System;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
private static bool _hasError;
|
||||
|
||||
private static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
|
||||
|
||||
internal static unsafe void Main(
|
||||
string[] args
|
||||
)
|
||||
internal static unsafe void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -63,12 +64,13 @@ namespace StgSharp
|
||||
// TestMatrix();
|
||||
|
||||
|
||||
/*
|
||||
/**/
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
Console.ReadLine();
|
||||
_ = Console.ReadLine();
|
||||
_hasError = true;
|
||||
/*
|
||||
World.WriteLog($"{ex}", LogType.Error);
|
||||
Dialogue.PostError(ex);
|
||||
@@ -79,6 +81,11 @@ namespace StgSharp
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!_hasError)
|
||||
{
|
||||
Console.WriteLine("Program has exited with no error, press any key to exit.");
|
||||
_ = Console.ReadKey();
|
||||
}
|
||||
World.Terminate(0);
|
||||
}
|
||||
/**/
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using StgSharp.RegularAnalysis.TextRegex;
|
||||
using StgSharp.RegularAnalysis.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -44,8 +44,7 @@ namespace StgSharp
|
||||
@"abc[0-9]x|abc[0-9]y|abd[0-9]x|abd[0-9]y|xyz",
|
||||
@"get_name|get_value|get_type|set_name|set_value|set_type",
|
||||
@"helix|hello|help|hero|hers|her",
|
||||
@"a*.[abc]*(abcd|a(bc)c)+(?<name>abc)"
|
||||
];
|
||||
@"a*.[abc]*(abcd|a(bc)c)+(?<name>abc)"];
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user