add generator if ''UNIT''s in regex
This commit is contained in:
@@ -24,7 +24,6 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
internal TextRegexSource(
|
||||
string pattern,
|
||||
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> ast,
|
||||
RegexInfo info,
|
||||
Exception? analyseException = null
|
||||
|
||||
)
|
||||
@@ -32,7 +31,6 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
Pattern = pattern;
|
||||
Ast = ast;
|
||||
AnalyseException = analyseException;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public Exception? AnalyseException { get; set; }
|
||||
@@ -41,8 +39,6 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal AbstractSyntaxTree<RegexAstNode, RegexElementLabel> Ast { get; }
|
||||
|
||||
internal RegexInfo Info { get; }
|
||||
|
||||
}
|
||||
|
||||
public static partial class RegexAnalyzer
|
||||
@@ -56,16 +52,15 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
// RegexAnalyzer interpreter = new();
|
||||
// interpreter._source = regex;
|
||||
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree;
|
||||
RegexInfo info = new();
|
||||
try
|
||||
{
|
||||
tree = GenerateAST(regex);
|
||||
OptimizeTree(tree);
|
||||
return new TextRegexSource(regex, tree, info, null);
|
||||
return new TextRegexSource(regex, tree, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new TextRegexSource(regex, null, info, ex);
|
||||
return new TextRegexSource(regex, null, ex);
|
||||
}
|
||||
/*
|
||||
// List<RegexIR> base_ir;
|
||||
@@ -94,15 +89,4 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal struct RegexInfo
|
||||
{
|
||||
|
||||
public int RegionCount { get; set; }
|
||||
|
||||
public int MinPredictLength { get; set; }
|
||||
|
||||
public int SingleLineResultCount { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
if (last < first) {
|
||||
throw new InvalidCastException($"Invalid character range: {first}-{last}");
|
||||
}
|
||||
rules.Add(new(content[first..last].ToString(), RegexCharSetType.Range, true));
|
||||
rules.Add(new($"{first}{last}", RegexCharSetType.Range, true));
|
||||
} else
|
||||
{
|
||||
_ = singles.Add(first);
|
||||
|
||||
@@ -29,17 +29,36 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
)
|
||||
{
|
||||
RegexAstNode root = ast;
|
||||
switch (root.Label & (RegexElementLabel.VAST_OPERATOR))
|
||||
RegexElementLabel op = root.Label & (RegexElementLabel.VAST_OPERATOR);
|
||||
if (op != 0)
|
||||
{
|
||||
case RegexElementLabel.CONCAT:
|
||||
GenerateConcat(root, sc, func_list);
|
||||
break;
|
||||
case RegexElementLabel.COUNT:
|
||||
break;
|
||||
case RegexElementLabel.GROUP_BEGIN:
|
||||
break;
|
||||
case RegexElementLabel.ALT:
|
||||
break;
|
||||
switch (op)
|
||||
{
|
||||
case RegexElementLabel.CONCAT:
|
||||
GenerateConcat(root, sc, func_list);
|
||||
break;
|
||||
case RegexElementLabel.COUNT:
|
||||
GenerateCount(root, sc, func_list);
|
||||
break;
|
||||
case RegexElementLabel.GROUP_BEGIN:
|
||||
GenerateGroup(root, sc, func_list);
|
||||
break;
|
||||
case RegexElementLabel.ALT:
|
||||
GenerateAlt(root, sc, func_list);
|
||||
break;
|
||||
}
|
||||
} else
|
||||
{
|
||||
op = root.Label & (RegexElementLabel.SEQUENCE);
|
||||
switch (op)
|
||||
{
|
||||
case RegexElementLabel.UNIT:
|
||||
break;
|
||||
case RegexElementLabel.UNIT_SET:
|
||||
break;
|
||||
case RegexElementLabel.UNIT_SPAN:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +99,46 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
in List<SequenceEmitter<string>> func_list
|
||||
)
|
||||
{
|
||||
RegexAstNode left = node.Left;
|
||||
RegexAstNode right = node.Right;
|
||||
|
||||
RegexAstNode current = left;
|
||||
|
||||
while (RegexAstNode.IsNullOrEmpty(current))
|
||||
{
|
||||
GenerateMethodSource(current, sc, func_list);
|
||||
current = current.Next;
|
||||
}
|
||||
current = right;
|
||||
|
||||
while (RegexAstNode.IsNullOrEmpty(current))
|
||||
{
|
||||
GenerateMethodSource(current, sc, func_list);
|
||||
current = current.Next;
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateGroup(
|
||||
RegexAstNode node,
|
||||
[NotNull] in SequenceEmitter<string> sc,
|
||||
in List<SequenceEmitter<string>> func_list
|
||||
)
|
||||
{
|
||||
RegexAstNode left = node.Left;
|
||||
RegexAstNode right = node.Right;
|
||||
|
||||
RegexGroupPayload config = node.PayloadAs<RegexGroupPayload>();
|
||||
|
||||
if (left is not null)
|
||||
{
|
||||
GenerateMethodSource(left, sc, func_list);
|
||||
} else
|
||||
if (right is not null) {
|
||||
GenerateMethodSource(right, sc, func_list);
|
||||
}
|
||||
|
||||
string group_name = config.Name;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static void GenerateConcat(
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
result.AddDiagnostic(CompileFailDiag, null, analyze_result.AnalyseException.Message);
|
||||
} else
|
||||
{
|
||||
SequenceEmitter<string> method_source = GenerateSource(analyze_result);
|
||||
SequenceEmitter<string> method_source = /**/ new()/*GenerateSource(analyze_result)/**/;
|
||||
result.GeneratedSource = method_source;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user