regex interpreter now can build partial correct AST (i forget groups), but in bad shape. building an optimizer.
This commit is contained in:
@@ -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
|
||||
) { }
|
||||
|
||||
Reference in New Issue
Block a user