Skip to content

Commit 20b487b

Browse files
committed
合并 Not 与 NOT
1 parent f157f5f commit 20b487b

File tree

11 files changed

+6267
-3977
lines changed

11 files changed

+6267
-3977
lines changed

csharp/ToolGood.Algorithm2/Internals/MathVisitor.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,6 @@ public Operand VisitIF_fun(mathParser.IF_funContext context)
334334
return Operand.False;
335335
}
336336

337-
public Operand VisitNot_fun(mathParser.Not_funContext context)
338-
{
339-
var firstValue = this.Visit(context.expr()).ToBoolean("Function NOT first parameter is error!");
340-
if (firstValue.IsError) { return firstValue; }
341-
342-
if (firstValue.BooleanValue) {
343-
return Operand.False;
344-
}
345-
return Operand.True;
346-
}
347-
348337
public Operand VisitIFERROR_fun(mathParser.IFERROR_funContext context)
349338
{
350339
var args = new List<Operand>();

csharp/ToolGood.Algorithm2/math/mathParser.2.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,21 +3509,6 @@ public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor)
35093509
return typedVisitor.VisitPercentage_fun(this);
35103510
}
35113511
}
3512-
public partial class Not_funContext : ExprContext
3513-
{
3514-
[System.Diagnostics.DebuggerNonUserCode]
3515-
public ExprContext expr()
3516-
{
3517-
return GetRuleContext<ExprContext>(0);
3518-
}
3519-
public Not_funContext(ExprContext context) { CopyFrom(context); }
3520-
[System.Diagnostics.DebuggerNonUserCode]
3521-
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor)
3522-
{
3523-
ImathVisitor<TResult> typedVisitor = visitor as ImathVisitor<TResult>;
3524-
return typedVisitor.VisitNot_fun(this);
3525-
}
3526-
}
35273512
public partial class STRING_funContext : ExprContext
35283513
{
35293514
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode STRING() { return GetToken(28, 0); }

csharp/ToolGood.Algorithm2/math/mathParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private ExprContext expr(int _p)
8787
ErrorHandler.Sync(this);
8888
switch (TokenStream.LA(1)) {
8989
case 25: {
90-
_localctx = new Not_funContext(_localctx);
90+
_localctx = new NOT_funContext(_localctx);
9191
Context = _localctx;
9292
_prevctx = _localctx;
9393

csharp/ToolGood.Algorithm2/math/mathVisitor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,5 @@ interface ImathVisitor<Result> : IParseTreeVisitor<Result>
252252

253253
Result VisitDiyFunction_fun(mathParser.DiyFunction_funContext context);
254254
Result VisitPercentage_fun(mathParser.Percentage_funContext context);
255-
256-
Result VisitNot_fun(mathParser.Not_funContext context);
255+
257256
}

g4/math.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ expr:
113113
| expr '[' expr ']' # GetJsonValue_fun
114114
| expr '.' parameter2 # GetJsonValue_fun
115115
| expr '%' # Percentage_fun
116-
| '!' expr # Not_fun
116+
| '!' expr # NOT_fun
117117
| expr2 # expr2_fun;
118118

119119
expr2:

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ public int LA(int i) {
2626
if (c <= 0) {
2727
return c;
2828
}
29+
char o = (char)c;
30+
if (o == '‘') {
31+
o = '\'';
32+
} else if (o == '’') {
33+
o = '\'';
34+
} else if (o == '“') {
35+
o = '"';
36+
} else if (o == '”') {
37+
o = '"';
38+
} else if (o == '〔') {
39+
o = '(';
40+
} else if (o == '〕') {
41+
o = ')';
42+
}
2943

30-
char o = (char)c;
31-
if (o == '(') {
32-
o = '(';
33-
} else if (o == ')') {
34-
o = ')';
35-
} else if (o == ',') {
36-
o = ',';
37-
} else if (o == '【') {
38-
o = '[';
39-
} else if (o == '】') {
40-
o = ']';
41-
} else if (o == '‘') {
42-
o = '\'';
43-
} else if (o == '’') {
44-
o = '\'';
45-
} else if (o == '“') {
46-
o = '"';
47-
} else if (o == '”') {
48-
o = '"';
49-
}
44+
if (c == 12288) {
45+
o = (char)32;
46+
} else if (c > 65280 && c < 65375) {
47+
o = (char)(c - 65248);
48+
}
49+
5050
return Character.toUpperCase(o);
5151
}
5252

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

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,13 @@ public Operand visitPERMUT_fun(final PERMUT_funContext context) {
806806
return Operand.Create(sum);
807807
}
808808

809+
public Operand visitPercentage_fun(Percentage_funContext context) {
810+
Operand firstValue = this.visit(context.expr()).ToNumber("Function Percentage parameter is error!");
811+
if (firstValue.IsError()) { return firstValue; }
812+
813+
return Operand.Create(firstValue.NumberValue() / 100.0);
814+
}
815+
809816
private int F_base_gcd(List<Double> list) {
810817
list = ShellSort(list);
811818
// list = list.OrderBy(q => q).ToList();
@@ -5325,12 +5332,27 @@ public Operand visitNULL_fun(final NULL_funContext context) {
53255332
}
53265333

53275334
public Operand visitPARAMETER_fun(final PARAMETER_funContext context) {
5328-
final Operand p = visit(context.parameter()).ToText("Function PARAMETER first parameter is error!");
5329-
if (p.IsError())
5330-
return p;
53315335

5332-
if (GetParameter != null) {
5333-
return GetParameter.apply(p.TextValue());
5336+
TerminalNode node = context.PARAMETER();
5337+
if (node != null) {
5338+
return GetParameter.apply(node.getText());
5339+
}
5340+
node = context.PARAMETER2();
5341+
if (node != null) {
5342+
String str = node.getText();
5343+
if (str.startsWith("@")) {
5344+
return GetParameter.apply(str.substring(1));
5345+
}
5346+
return GetParameter.apply(str.substring(1, str.length()- 1));
5347+
}
5348+
//防止 多重引用
5349+
if (context.expr()!=null) {
5350+
Operand p = this.visit(context.expr()).ToText("Function PARAMETER first parameter is error!");
5351+
if (p.IsError()) return p;
5352+
5353+
if (GetParameter != null) {
5354+
return GetParameter.apply(p.TextValue());
5355+
}
53345356
}
53355357
return Operand.Error("Function PARAMETER first parameter is error!");
53365358
}
@@ -5348,18 +5370,20 @@ public Operand visitParameter2(final Parameter2Context context) {
53485370
}
53495371

53505372
public Operand visitGetJsonValue_fun(final GetJsonValue_funContext context) {
5351-
final Operand firstValue = visit(context.expr());
5373+
final Operand firstValue = visit(context.expr(0));
53525374
if (firstValue.IsError()) {
53535375
return firstValue;
53545376
}
53555377

53565378
final Operand obj = firstValue;
53575379
Operand op;
5358-
final ParameterContext p1 = context.parameter();
5359-
if (p1 != null) {
5360-
op = visit(p1);
5380+
if (context.parameter2()!=null) {
5381+
op = this.visit(context.parameter2());
53615382
} else {
5362-
op = visit(context.parameter2());
5383+
op = this.visit(context.expr(1));
5384+
if (op.IsError()) {
5385+
op = Operand.Create(context.expr(1).getText());
5386+
}
53635387
}
53645388

53655389
if (obj.Type() == OperandType.ARRARY) {
@@ -5763,4 +5787,8 @@ private static int removeWhiteSpace(char[] data) {
57635787
return newSize;
57645788
}
57655789
}
5790+
5791+
5792+
5793+
57665794
}

0 commit comments

Comments
 (0)