Skip to content

Commit b6dd2d5

Browse files
committed
fix
1 parent d7f724d commit b6dd2d5

7 files changed

Lines changed: 40 additions & 17 deletions

File tree

csharp/ToolGood.Algorithm.Test/ConditionTrees/CalculateTreeTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public void Test1()
1313
var t1 = AlgorithmEngineHelper.ParseCalculate(txt);
1414
Assert.AreEqual(t1.Type, CalculateTreeType.Add);
1515
Assert.AreEqual("A1+1", txt.Substring(t1.Start, t1.End - t1.Start + 1));
16-
Assert.AreEqual("A1+1", t1.ConditionString);
16+
Assert.AreEqual("A1+1", t1.Text);
1717

1818
txt = "A1-(1+1)";
1919
t1 = AlgorithmEngineHelper.ParseCalculate(txt);
2020
Assert.AreEqual(t1.Type, CalculateTreeType.Sub);
21-
Assert.AreEqual("1+1", t1.Nodes[1].ConditionString);
21+
Assert.AreEqual("1+1", t1.Nodes[1].Text);
2222

2323
txt = "A1*(1+1)";
2424
t1 = AlgorithmEngineHelper.ParseCalculate(txt);

csharp/ToolGood.Algorithm.Test/ConditionTrees/ConditionTreeTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Test1()
1414
var t1 = AlgorithmEngineHelper.ParseCondition(txt);
1515
Assert.AreEqual(t1.Type, ConditionTreeType.String);
1616
Assert.AreEqual("AA.IsText() = bb", txt.Substring(t1.Start, t1.End - t1.Start + 1));
17-
Assert.AreEqual("AA.IsText()=bb", t1.ConditionString);
17+
Assert.AreEqual("AA.IsText()=bb", t1.Text);
1818

1919
txt = "[bbb]=bb";
2020
t1 = AlgorithmEngineHelper.ParseCondition(txt);

csharp/ToolGood.Algorithm/Internals/CalculateTree.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ public sealed class CalculateTree
2828
public CalculateTreeType Type { get; internal set; }
2929

3030
/// <summary>
31-
/// 条件
31+
/// 文本
3232
/// </summary>
33-
public string ConditionString { get; internal set; }
33+
public string Text { get; internal set; }
34+
/// <summary>
35+
/// 外面是否有括号
36+
/// </summary>
37+
public bool HasBracket { get; internal set; }
3438

3539
/// <summary>
3640
/// 出错信息

csharp/ToolGood.Algorithm/Internals/ConditionTree.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ public sealed class ConditionTree
2929
public ConditionTreeType Type { get; internal set; }
3030

3131
/// <summary>
32-
/// 条件
32+
/// 文本
3333
/// </summary>
34-
public string ConditionString { get; internal set; }
34+
public string Text { get; internal set; }
35+
36+
/// <summary>
37+
/// 外面是否有括号
38+
/// </summary>
39+
public bool HasBracket { get; internal set; }
3540

3641
/// <summary>
3742
/// 出错信息

csharp/ToolGood.Algorithm/Internals/Visitors/MathSplitVisitor.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ namespace ToolGood.Algorithm.Internals.Visitors
88
{
99
internal sealed class MathSplitVisitor : AbstractParseTreeVisitor<ConditionTree>, ImathVisitor<ConditionTree>
1010
{
11+
private bool hasBracket = false;
12+
1113
public ConditionTree VisitProg(mathParser.ProgContext context)
1214
{
15+
hasBracket = false;
1316
return context.expr().Accept(this);
1417
}
1518

1619
public ConditionTree VisitAndOr_fun(mathParser.AndOr_funContext context)
1720
{
1821
var tree = new ConditionTree {
19-
Nodes = new List<ConditionTree>()
22+
Nodes = new List<ConditionTree>(),
23+
HasBracket=hasBracket,
2024
};
25+
hasBracket = false;
2126
var t = context.op.Text;
2227
if(CharUtil.Equals(t, "&&")) {
2328
tree.Type = ConditionTreeType.And;
@@ -30,12 +35,13 @@ public ConditionTree VisitAndOr_fun(mathParser.AndOr_funContext context)
3035
tree.Nodes.Add(exprs[1].Accept(this));
3136
tree.Start = context.Start.StartIndex;
3237
tree.End = context.Stop.StopIndex;
33-
tree.ConditionString = context.GetText();
38+
tree.Text = context.GetText();
3439
return tree;
3540
}
3641

3742
public ConditionTree VisitBracket_fun(mathParser.Bracket_funContext context)
3843
{
44+
hasBracket = true;
3945
return context.expr().Accept(this);
4046
}
4147

@@ -44,7 +50,7 @@ public ConditionTree Visit_fun(ParserRuleContext context)
4450
var tree = new ConditionTree {
4551
Start = context.Start.StartIndex,
4652
End = context.Stop.StopIndex,
47-
ConditionString = context.GetText()
53+
Text = context.GetText()
4854
};
4955
return tree;
5056
}

csharp/ToolGood.Algorithm/Internals/Visitors/MathSplitVisitor2.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@ namespace ToolGood.Algorithm.Internals.Visitors
88
{
99
internal sealed class MathSplitVisitor2 : AbstractParseTreeVisitor<CalculateTree>, ImathVisitor<CalculateTree>
1010
{
11+
private bool hasBracket = false;
12+
1113
public CalculateTree VisitProg(mathParser.ProgContext context)
1214
{
15+
hasBracket = false;
1316
return context.expr().Accept(this);
1417
}
1518

1619
public CalculateTree VisitBracket_fun(mathParser.Bracket_funContext context)
1720
{
21+
hasBracket = true;
1822
return context.expr().Accept(this);
1923
}
2024
public CalculateTree VisitMulDiv_fun(mathParser.MulDiv_funContext context)
2125
{
2226
var tree = new CalculateTree {
23-
Nodes = new List<CalculateTree>()
27+
Nodes = new List<CalculateTree>(),
28+
HasBracket = hasBracket,
2429
};
30+
hasBracket = false;
2531
var exprs = context.expr();
2632
var t = context.op.Text;
2733
if(CharUtil.Equals(t, '*')) {
@@ -35,14 +41,16 @@ public CalculateTree VisitMulDiv_fun(mathParser.MulDiv_funContext context)
3541
tree.Nodes.Add(exprs[1].Accept(this));
3642
tree.Start = context.Start.StartIndex;
3743
tree.End = context.Stop.StopIndex;
38-
tree.ConditionString = context.GetText();
44+
tree.Text = context.GetText();
3945
return tree;
4046
}
4147
public CalculateTree VisitAddSub_fun(mathParser.AddSub_funContext context)
4248
{
4349
var tree = new CalculateTree {
44-
Nodes = new List<CalculateTree>()
50+
Nodes = new List<CalculateTree>(),
51+
HasBracket = hasBracket,
4552
};
53+
hasBracket = false;
4654
var exprs = context.expr();
4755
var t = context.op.Text;
4856
if(CharUtil.Equals(t, '+')) {
@@ -56,7 +64,7 @@ public CalculateTree VisitAddSub_fun(mathParser.AddSub_funContext context)
5664
tree.Nodes.Add(exprs[1].Accept(this));
5765
tree.Start = context.Start.StartIndex;
5866
tree.End = context.Stop.StopIndex;
59-
tree.ConditionString = context.GetText();
67+
tree.Text = context.GetText();
6068
return tree;
6169
}
6270

@@ -66,7 +74,7 @@ public CalculateTree Visit_fun(ParserRuleContext context)
6674
var tree = new CalculateTree {
6775
Start = context.Start.StartIndex,
6876
End = context.Stop.StopIndex,
69-
ConditionString = context.GetText()
77+
Text = context.GetText()
7078
};
7179
return tree;
7280
}
@@ -885,7 +893,7 @@ public CalculateTree VisitPRODUCT_fun(mathParser.PRODUCT_funContext context)
885893
{
886894
return Visit_fun(context);
887895
}
888-
896+
889897
public CalculateTree VisitPROPER_fun(mathParser.PROPER_funContext context)
890898
{
891899
return Visit_fun(context);

csharp/ToolGood.Algorithm/ToolGood.Algorithm.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<Product>ToolGood.Algorithm</Product>
2020
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
2121
<SignAssembly>true</SignAssembly>
22-
<Version>6.2.2.3</Version>
22+
<Version>6.2.2.5</Version>
2323
<AssemblyOriginatorKeyFile>ToolGood.Algorithm.snk</AssemblyOriginatorKeyFile>
2424
<DelaySign>false</DelaySign>
2525
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\ToolGood.Algorithm.xml</DocumentationFile>

0 commit comments

Comments
 (0)