Skip to content

Commit c3ee3e3

Browse files
committed
создание операций и терминалов конструкторами
1 parent b16a0dc commit c3ee3e3

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

src/OneScript.Language/SyntaxAnalysis/AstNodes/BinaryOperationNode.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@ public BinaryOperationNode(Lexem operation) : base(NodeKind.BinaryOperation, ope
1717
{
1818
Operation = operation.Token;
1919
}
20+
21+
public BinaryOperationNode(BslSyntaxNode firstArg, BslSyntaxNode secondArg, Lexem operation)
22+
: base(NodeKind.BinaryOperation, operation)
23+
{
24+
Operation = operation.Token;
25+
AddChild(firstArg);
26+
AddChild(secondArg);
27+
}
2028
}
2129
}

src/OneScript.Language/SyntaxAnalysis/AstNodes/UnaryOperationNode.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public class UnaryOperationNode : NonTerminalNode
1616
public UnaryOperationNode(Lexem operation) : base(NodeKind.UnaryOperation, operation)
1717
{
1818
Operation = operation.Token;
19-
}
19+
}
20+
21+
public UnaryOperationNode(BslSyntaxNode arg, Lexem operation) : base(NodeKind.UnaryOperation, operation)
22+
{
23+
Operation = operation.Token;
24+
AddChild(arg);
25+
}
2026
}
2127
}

src/OneScript.Language/SyntaxAnalysis/DefaultBslParser.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,7 @@ private BslSyntaxNode BuildExpressionAwaitOperator(Lexem lexem)
757757
if (argument != default)
758758
{
759759
CheckAsyncMethod();
760-
var awaitOperator = new UnaryOperationNode(lexem);
761-
awaitOperator.AddChild(argument);
762-
return awaitOperator;
760+
return new UnaryOperationNode(argument, lexem);
763761
}
764762
else if (!_isInAsyncMethod)
765763
{
@@ -1140,7 +1138,7 @@ private BslSyntaxNode BuildGlobalCall(Lexem identifier)
11401138

11411139
private BslSyntaxNode CallOrVariable(Lexem identifier)
11421140
{
1143-
var target = NodeBuilder.CreateNode(NodeKind.Identifier, identifier);
1141+
BslSyntaxNode target = new TerminalNode(NodeKind.Identifier, identifier);
11441142
if (_lastExtractedLexem.Token != Token.OpenPar)
11451143
{
11461144
_lastDereferenceIsWritable = true; // одиночный идентификатор
@@ -1251,7 +1249,7 @@ private BslSyntaxNode BuildExpression(int prio)
12511249
NextLexem();
12521250
var secondArg = BuildExpression(LanguageDef.GetBinaryPriority(operationLexem.Token));
12531251

1254-
firstArg = MakeBinaryOperationNode(firstArg, secondArg, operationLexem);
1252+
firstArg = new BinaryOperationNode(firstArg, secondArg, operationLexem);
12551253
}
12561254

12571255
return firstArg;
@@ -1293,9 +1291,7 @@ private BslSyntaxNode BuildPrimaryExpression()
12931291
}
12941292

12951293
var arg = BuildExpression(prio);
1296-
var op = new UnaryOperationNode(operation);
1297-
op.AddChild(arg);
1298-
return op;
1294+
return new UnaryOperationNode(arg, operation);
12991295
}
13001296

13011297

@@ -1336,14 +1332,6 @@ private void BuildOptionalExpression(NonTerminalNode parent, Token stopToken)
13361332

13371333
#region Operators
13381334

1339-
private static BinaryOperationNode MakeBinaryOperationNode(BslSyntaxNode firstArg, BslSyntaxNode secondArg, in Lexem lexem)
1340-
{
1341-
var node = new BinaryOperationNode(lexem);
1342-
node.AddChild(firstArg);
1343-
node.AddChild(secondArg);
1344-
return node;
1345-
}
1346-
13471335
private BslSyntaxNode BuildParenthesis()
13481336
{
13491337
NextLexem();
@@ -1375,7 +1363,7 @@ private BslSyntaxNode SelectTerminalNode(in Lexem currentLexem, bool supportAwai
13751363
BslSyntaxNode node = default;
13761364
if (LanguageDef.IsLiteral(currentLexem))
13771365
{
1378-
node = NodeBuilder.CreateNode(NodeKind.Constant, currentLexem);
1366+
node = new TerminalNode(NodeKind.Constant, currentLexem);
13791367
NextLexem();
13801368
}
13811369
else if (LanguageDef.IsUserSymbol(currentLexem))
@@ -1449,7 +1437,7 @@ private BslSyntaxNode BuildDereference(BslSyntaxNode target)
14491437
NextLexem();
14501438
if (_lastExtractedLexem.Token == Token.OpenPar)
14511439
{
1452-
var ident = NodeBuilder.CreateNode(NodeKind.Identifier, identifier);
1440+
var ident = new TerminalNode(NodeKind.Identifier, identifier);
14531441
var call = BuildCall(ident, NodeKind.MethodCall);
14541442
dotNode.AddChild(call);
14551443
}

0 commit comments

Comments
 (0)