Skip to content

Commit b0a2aa8

Browse files
committed
添加 备注
1 parent 3e41c19 commit b0a2aa8

File tree

8 files changed

+78
-19
lines changed

8 files changed

+78
-19
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ public class ConditionTreeTest
99
[Test]
1010
public void Test1()
1111
{
12-
string txt = "AA.IsText()=bb";
12+
string txt = "AA.IsText() = bb";
1313
var t1 = ConditionTree.Parse(txt);
1414
Assert.AreEqual(t1.Type, ConditionTreeType.String);
15-
Assert.AreEqual("AA.IsText()=bb", txt.Substring(t1.Start, t1.End - t1.Start + 1));
15+
Assert.AreEqual("AA.IsText() = bb", txt.Substring(t1.Start, t1.End - t1.Start + 1));
16+
Assert.AreEqual("AA.IsText()=bb", t1.ConditionString);
1617

1718
txt = "[bbb]=bb";
1819
t1 = ConditionTree.Parse(txt);

csharp/ToolGood.Algorithm2/Internals/ConditionTree.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,33 @@ namespace ToolGood.Algorithm.Internals
66
{
77
public class ConditionTree
88
{
9-
public List<ConditionTree> Nodes { get; internal set; }
10-
9+
/// <summary>
10+
/// 子节点
11+
/// </summary>
12+
public IList<ConditionTree> Nodes { get; internal set; }
13+
/// <summary>
14+
/// 开始位置
15+
/// </summary>
1116
public int Start { get; internal set; }
17+
/// <summary>
18+
/// 结束位置
19+
/// </summary>
1220
public int End { get; internal set; }
13-
21+
/// <summary>
22+
/// 类型
23+
/// </summary>
1424
public ConditionTreeType Type { get; internal set; }
15-
25+
/// <summary>
26+
/// 条件
27+
/// </summary>
28+
public string ConditionString { get; internal set; }
29+
/// <summary>
30+
/// 出错信息
31+
/// </summary>
1632
public String ErrorMessage { get; internal set; }
1733

1834
internal ConditionTree()
1935
{
20-
Nodes = new List<ConditionTree>();
2136
}
2237

2338

csharp/ToolGood.Algorithm2/Internals/ConditionTreeType.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22
{
33
public enum ConditionTreeType
44
{
5+
/// <summary>
6+
/// 文本
7+
/// </summary>
58
String,
9+
/// <summary>
10+
/// 并
11+
/// </summary>
612
And,
13+
/// <summary>
14+
/// 或
15+
/// </summary>
716
Or,
17+
/// <summary>
18+
/// 错误
19+
/// </summary>
820
Error
921

1022
}

csharp/ToolGood.Algorithm2/Internals/MathSplitVisitor.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using Antlr4.Runtime;
22
using Antlr4.Runtime.Tree;
3-
using System;
43
using System.Collections.Generic;
5-
using System.Linq;
64
using System.Text;
75

86
namespace ToolGood.Algorithm.Internals
@@ -16,6 +14,7 @@ public ConditionTree VisitProg(mathParser.ProgContext context)
1614
public ConditionTree VisitAndOr_fun(mathParser.AndOr_funContext context)
1715
{
1816
ConditionTree tree = new ConditionTree();
17+
tree.Nodes = new List<ConditionTree>();
1918
var t = context.op.Text;
2019
if (CharUtil.Equals(t, "&&", "and")) {
2120
tree.Type = ConditionTreeType.And;
@@ -35,15 +34,17 @@ public ConditionTree Visit_fun(ParserRuleContext context)
3534
ConditionTree tree = new ConditionTree();
3635
tree.Start = context.Start.StartIndex;
3736
tree.End = context.Stop.StopIndex;
37+
tree.ConditionString = context.GetText();
3838
return tree;
3939
}
4040

41+
4142
public ConditionTree VisitIF_fun(mathParser.IF_funContext context)
4243
{
4344
return Visit_fun(context);
4445
}
4546

46-
47+
4748
public ConditionTree VisitAND_fun(mathParser.AND_funContext context)
4849
{
4950
return Visit_fun(context);
@@ -75,9 +76,6 @@ public ConditionTree VisitAddSub_fun(mathParser.AddSub_funContext context)
7576
{
7677
return Visit_fun(context);
7778
}
78-
79-
80-
8179
public ConditionTree VisitArray_fun(mathParser.Array_funContext context)
8280
{
8381
return Visit_fun(context);

java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/ConditionTree.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,33 @@
1010
import java.util.List;
1111

1212
public class ConditionTree {
13+
/**
14+
* 子节点
15+
*/
1316
public List<ConditionTree> Nodes;
14-
17+
/**
18+
* 开始位置
19+
*/
1520
public int Start;
21+
/**
22+
* 结束位置
23+
*/
1624
public int End;
17-
25+
/**
26+
* 类型
27+
*/
1828
public ConditionTreeType Type;
19-
29+
/**
30+
* 条件
31+
*/
32+
public String ConditionString;
33+
/**
34+
* 出错信息
35+
*/
2036
public String ErrorMessage;
2137

2238
public ConditionTree() {
23-
Nodes = new ArrayList<>();
39+
2440
}
2541

2642

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
package toolgood.algorithm.internals;
22

33
public enum ConditionTreeType {
4+
/**
5+
* 文本
6+
*/
47
String,
8+
/**
9+
* 并
10+
*/
511
And,
12+
/**
13+
* 或
14+
*/
615
Or,
16+
/**
17+
* 错误
18+
*/
719
Error
820
}

java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/MathSplitVisitor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import toolgood.algorithm.math.mathParser2;
66
import toolgood.algorithm.math.mathVisitor;
77

8+
import java.util.ArrayList;
9+
810
public class MathSplitVisitor extends AbstractParseTreeVisitor<ConditionTree> implements mathVisitor<ConditionTree> {
911
@Override
1012
public ConditionTree visitProg(mathParser2.ProgContext context) {
@@ -14,6 +16,7 @@ public ConditionTree visitProg(mathParser2.ProgContext context) {
1416
@Override
1517
public ConditionTree visitAndOr_fun(mathParser2.AndOr_funContext context) {
1618
ConditionTree tree = new ConditionTree();
19+
tree.Nodes = new ArrayList<>();
1720
String t = context.op.getText();
1821
if (CharUtil.Equals(t, "&&", "and")) {
1922
tree.Type = ConditionTreeType.And;
@@ -35,6 +38,7 @@ public ConditionTree visit_fun(ParserRuleContext context) {
3538
tree.Type = ConditionTreeType.String;
3639
tree.Start = context.start.getStartIndex();
3740
tree.End = context.stop.getStopIndex();
41+
tree.ConditionString = context.getText();
3842
return tree;
3943
}
4044

java/toolgood.algorithm/src/test/java/toolgood/algorithm/Tests4/ConditionTreeTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ public class ConditionTreeTest {
1010

1111
@Test
1212
public void Test1() {
13-
String txt = "AA.IsText()=bb";
13+
String txt = "AA.IsText() = bb";
1414
ConditionTree t1 = ConditionTree.Parse(txt);
1515

1616
assertEquals(t1.Type, ConditionTreeType.String);
17-
assertEquals("AA.IsText()=bb", txt.substring(t1.Start, t1.End + 1));
17+
assertEquals("AA.IsText() = bb", txt.substring(t1.Start, t1.End + 1));
18+
assertEquals("AA.IsText()=bb",t1.ConditionString);
1819

1920
txt = "[bbb]=bb";
2021
t1 = ConditionTree.Parse(txt);

0 commit comments

Comments
 (0)