single ir is briefly ok
This commit is contained in:
@@ -277,6 +277,11 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
ir = ir_span[i];
|
||||
if ((ir.Prefix.Mask & simple_alt) == simple_alt)
|
||||
{
|
||||
if (TryGenerateSingleIR(outer_level, [ir], sc, code, local_func) > 0)
|
||||
{
|
||||
// TODO add additional code for the alt chain
|
||||
}
|
||||
|
||||
// simple match
|
||||
} else if (ir is RegexTryIR _try && (ir.Prefix.Mask & simple_alt) == simple_alt)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using StgSharp.RegularAnalysis.Abstraction;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@@ -76,6 +78,25 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
#region code
|
||||
|
||||
private static int TryGenerateSingleIR(
|
||||
int outer_level,
|
||||
ReadOnlySpan<RegexIR> ir_span,
|
||||
SourceGenContext sc,
|
||||
in SequenceEmitter<string> code,
|
||||
in List<SequenceEmitter<string>> local_func
|
||||
)
|
||||
{
|
||||
return TryGenerateCountSeq(outer_level, ir_span, sc, code,
|
||||
local_func) > 0 ||
|
||||
TryGenerateCountSet(outer_level, ir_span, sc, code,
|
||||
local_func) > 0 ||
|
||||
TryGenerateMatchSet(outer_level, ir_span, sc, code,
|
||||
local_func) > 0 ||
|
||||
TryGenerateMatchSeq(outer_level, ir_span, sc, code, local_func) > 0 ?
|
||||
1 :
|
||||
-1;
|
||||
}
|
||||
|
||||
private static int TryGeneratePack(
|
||||
int outer_level,
|
||||
ReadOnlySpan<RegexIR> ir_span,
|
||||
@@ -203,6 +224,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
.AppendLine("}")
|
||||
.AppendLine("else")
|
||||
.AppendLine("{")//TODO fail here
|
||||
.AppendLine("break;")
|
||||
.AppendLine("}");
|
||||
return 1;
|
||||
}
|
||||
@@ -233,6 +255,10 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
* {
|
||||
* success here
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* fail case
|
||||
* }
|
||||
*/
|
||||
for (int i = 1; i < set_arr.Length - 1; i++)
|
||||
{
|
||||
@@ -244,7 +270,11 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
_case_code = GenLine(set, sc, ")");
|
||||
_ = code.AppendLine(_case_code)
|
||||
.AppendLine("{")
|
||||
.AppendLine(sc.MakeRemainOffset(1))// TODO case success
|
||||
.AppendLine(sc.MakeRemainOffset(1)) // TODO case success
|
||||
.AppendLine("}")
|
||||
.AppendLine("else")
|
||||
.AppendLine("{")
|
||||
.AppendLine("break;") // TODO case fail
|
||||
.AppendLine("}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,21 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
public string StepResult { get; } = _stepResult;
|
||||
|
||||
public string[] BeginRegion()
|
||||
{
|
||||
return [
|
||||
"do",
|
||||
"{"
|
||||
];
|
||||
}
|
||||
|
||||
public string[] CloseRegion()
|
||||
{
|
||||
return [
|
||||
"} while(true);"
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Emits declarations for every slot requested during body generation.
|
||||
/// </summary>
|
||||
|
||||
@@ -91,7 +91,8 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
brace_count = 0;
|
||||
foreach (string line in ce)
|
||||
{
|
||||
bool is_right_brace = line == "}";
|
||||
bool is_right_brace = (line == "}") ||
|
||||
line.StartsWith("} while", StringComparison.InvariantCulture);
|
||||
brace_count -= is_right_brace ? 1 : 0;
|
||||
for (int i = 0; i < brace_count; i++) {
|
||||
_ = code_source.Append(" ");
|
||||
|
||||
Reference in New Issue
Block a user