regex interpreter now can build partial correct AST (i forget groups), but in bad shape. building an optimizer.

This commit is contained in:
Youmu Liu
2026-02-06 17:07:03 +08:00
parent 1bfb8b67c4
commit 3a441b270c
13 changed files with 236 additions and 31 deletions
@@ -28,13 +28,15 @@
using StgSharp.RegularAnalysis.Abstraction;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.TextRegex
{
internal class RegexAstNode : ISyntaxNode<RegexAstNode, RegexElementLabel>
public class RegexAstNode : ISyntaxNode<RegexAstNode, RegexElementLabel>
{
private RegexAstNode _left, _right;
@@ -57,9 +59,27 @@ namespace StgSharp.RegularAnalysis.TextRegex
public RegexAstNode Next { get; set; }
public RegexAstNode Left { get; set; }
public RegexAstNode Parent { get; set; }
public RegexAstNode Right { get; set; }
public RegexAstNode Left
{
get;
set
{
field = value;
value.Parent = this;
}
}
public RegexAstNode Right
{
get;
set
{
field = value;
value.Parent = this;
}
}
public RegexElementLabel EqualityTypeConvert
{
@@ -74,6 +94,21 @@ namespace StgSharp.RegularAnalysis.TextRegex
RegexAstNode nextToken
) { }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (bool Valid,int Value) ComparePrecedence(
RegexElementLabel left,
RegexElementLabel right
)
{
left |= RegexElementLabel.OPERATOR;
right |= RegexElementLabel.OPERATOR;
int v_left = (int)left, v_right = (int)right;
if (v_left == 0 || v_right == 0) {
return (false,0);
}
return (true,v_left - v_right);
}
public void PrependNode(
RegexAstNode previousNode
) { }