Skip to content

Commit

Permalink
refactor: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
furesoft committed Dec 30, 2024
1 parent 5b79388 commit 797ce2d
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 104 deletions.
130 changes: 76 additions & 54 deletions NewSource/.idea/.idea.Socordia/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private IEnumerable<string> GetNames(AstNode node)
result.Add(id.Name);
break;
}
if (node is BinaryOperatorExpression { Operator: "'." } bin)
if (node is BinaryOperatorExpression { Operator: "." } bin)
{
result.Add(((Identifier)bin.Left).Name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void AddChildrenRecursively(BinaryOperatorExpression op)
{
Children.Add(new SimpleTypeName(id.Name));
}
else if (child is BinaryOperatorExpression binaryChild && binaryChild.Operator == "'.")
else if (child is BinaryOperatorExpression binaryChild && binaryChild.Operator == ".")
{
AddChildrenRecursively(binaryChild);
}
Expand Down
8 changes: 4 additions & 4 deletions NewSource/Socordia.CodeAnalysis/Parsing/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static AstNode Parse(Parser parser, ParsePointCollection parsePoints = nu

var operand = Parse(parser, parsePoints, preUnaryOperatorPrecedence + 1);

left = SyntaxTree.Unary(operatorToken.Text, operand, UnaryOperatorKind.Prefix);
left = new UnaryOperatorExpression(operatorToken.Text, operand, UnaryOperatorKind.Prefix);
}
}
else
Expand All @@ -77,7 +77,7 @@ public static AstNode Parse(Parser parser, ParsePointCollection parsePoints = nu
{
var unaryOperatorToken = parser.Iterator.NextToken();

left = SyntaxTree.Unary(unaryOperatorToken.Text, left, UnaryOperatorKind.Suffix);
left = new UnaryOperatorExpression(unaryOperatorToken.Text, left, UnaryOperatorKind.Suffix);
}
}
}
Expand All @@ -93,7 +93,7 @@ public static AstNode Parse(Parser parser, ParsePointCollection parsePoints = nu
var operatorToken = parser.Iterator.NextToken();
var right = Parse(parser, parsePoints, precedence);

left = new BinaryOperatorExpression($"'{operatorToken.Text}", left, right);
left = new BinaryOperatorExpression(operatorToken.Text, left, right);

// parsing postunary for: Hello::new()? = false;
var postUnaryOperatorPrecedence = GetPostUnaryOperatorPrecedence(parser.Iterator.Current.Type);
Expand All @@ -104,7 +104,7 @@ public static AstNode Parse(Parser parser, ParsePointCollection parsePoints = nu
{
var unaryOperatorToken = parser.Iterator.NextToken();

left = SyntaxTree.Unary(unaryOperatorToken.Text, left, UnaryOperatorKind.Suffix);
left = new UnaryOperatorExpression(unaryOperatorToken.Text, left, UnaryOperatorKind.Suffix);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ public sealed class ReturnStatementParser : IParsePoint
{
public static AstNode Parse(TokenIterator iterator, Parser parser)
{
if (iterator.IsMatch(TokenType.Semicolon))
if (iterator.ConsumeIfMatch(TokenType.Semicolon))
{
iterator.Match(TokenType.Semicolon);
return new ReturnStatement(Expression.Parse(parser));
return new ReturnStatement(new EmptyNode());
}

return null;
AstNode node = new ReturnStatement(Expression.Parse(parser));
iterator.Match(TokenType.Semicolon);

return node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public void InitParsePoints()

AddExpressionParsePoint<IdentifierParser>(TokenType.Identifier);
AddExpressionParsePoint<GroupOrTupleExpressionParser>(TokenType.OpenParen);
// AddExpressionParsePoint<MatchExpression>(TokenType.Match);
AddExpressionParsePoint<DefaultExpressionParser>(TokenType.Default);
AddExpressionParsePoint<SizeOfExpressionParser>(TokenType.SizeOf);
AddExpressionParsePoint<TypeOfExpressionParser>(TokenType.TypeOf);
AddExpressionParsePoint<NoneExpressionParser>(TokenType.None);
AddExpressionParsePoint<InitializerListExpression>(TokenType.OpenSquare);
// AddExpressionParsePoint<MatchExpression>(TokenType.Match);

AddStatementParsePoint<ThrowStatementParser>(TokenType.Throw);
AddStatementParsePoint<BreakStatementParser>(TokenType.Break);
Expand Down
5 changes: 0 additions & 5 deletions NewSource/Socordia.CodeAnalysis/Parsing/SyntaxTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ public static AstNode Try(Block body, List<CatchStatement> catches, Block? final
return new TryStatement(body, catches, finallly);
}

public static AstNode Unary(string op, AstNode operand, UnaryOperatorKind kind)
{
return new UnaryOperatorExpression(op, operand, kind);
}

public static LNode Using(LNode expr)
{
if (!expr.Calls(CodeSymbols.As)) // TODO: throw error in intermediate stage when has only one arg
Expand Down
Loading

0 comments on commit 797ce2d

Please sign in to comment.