...
This commit is contained in:
@@ -375,7 +375,7 @@ public class Parser
|
||||
initializers.Add(new NodeExpressionStructLiteral.Initializer(TokensFrom(initializerStartIndex), fieldName, fieldValue));
|
||||
}
|
||||
|
||||
expr = new NodeExpressionStructLiteral(TokensFrom(startIndex), initializers);
|
||||
expr = new NodeExpressionStructLiteral(TokensFrom(startIndex), null, initializers);
|
||||
}
|
||||
else if (TryExpectSymbol(Symbol.Bang))
|
||||
{
|
||||
@@ -408,8 +408,32 @@ public class Parser
|
||||
else if (TryExpectKeyword(Keyword.New))
|
||||
{
|
||||
var type = ParseType();
|
||||
var value = ParseExpression();
|
||||
return new NodeExpressionNewNamedType(TokensFrom(startIndex), type, value);
|
||||
|
||||
if (TryExpectSymbol(Symbol.OpenParen))
|
||||
{
|
||||
var value = ParseExpression();
|
||||
ExpectSymbol(Symbol.CloseParen);
|
||||
|
||||
expr = new NodeExpressionEnumLiteral(TokensFrom(startIndex), type, value);
|
||||
}
|
||||
else if (TryExpectSymbol(Symbol.OpenCurly))
|
||||
{
|
||||
var initializers = new List<NodeExpressionStructLiteral.Initializer>();
|
||||
while (!TryExpectSymbol(Symbol.CloseCurly))
|
||||
{
|
||||
var initializerStartIndex = startIndex;
|
||||
var fieldName = ExpectIdent();
|
||||
ExpectSymbol(Symbol.Equal);
|
||||
var fieldValue = ParseExpression();
|
||||
initializers.Add(new NodeExpressionStructLiteral.Initializer(TokensFrom(initializerStartIndex), fieldName, fieldValue));
|
||||
}
|
||||
|
||||
expr = new NodeExpressionStructLiteral(TokensFrom(startIndex), null, initializers);
|
||||
}
|
||||
else
|
||||
{
|
||||
expr = new NodeExpressionEnumLiteral(TokensFrom(startIndex), type, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -869,14 +893,9 @@ public class NodeExpressionBoolLiteral(List<Token> tokens, TokenBoolLiteral valu
|
||||
public TokenBoolLiteral Value { get; } = value;
|
||||
}
|
||||
|
||||
public class NodeExpressionNewNamedType(List<Token> tokens, NodeType type, NodeExpression value) : NodeExpression(tokens)
|
||||
{
|
||||
public NodeType Type { get; } = type;
|
||||
public NodeExpression Value { get; } = value;
|
||||
}
|
||||
|
||||
public class NodeExpressionStructLiteral(List<Token> tokens, List<NodeExpressionStructLiteral.Initializer> initializers) : NodeExpression(tokens)
|
||||
public class NodeExpressionStructLiteral(List<Token> tokens, NodeType? type, List<NodeExpressionStructLiteral.Initializer> initializers) : NodeExpression(tokens)
|
||||
{
|
||||
public NodeType? Type { get; } = type;
|
||||
public List<Initializer> Initializers { get; } = initializers;
|
||||
|
||||
public class Initializer(List<Token> tokens, TokenIdent name, NodeExpression value) : Node(tokens)
|
||||
@@ -886,6 +905,12 @@ public class NodeExpressionStructLiteral(List<Token> tokens, List<NodeExpression
|
||||
}
|
||||
}
|
||||
|
||||
public class NodeExpressionEnumLiteral(List<Token> tokens, NodeType type, NodeExpression? value) : NodeExpression(tokens)
|
||||
{
|
||||
public NodeType Type { get; } = type;
|
||||
public NodeExpression? Value { get; } = value;
|
||||
}
|
||||
|
||||
public class NodeExpressionMemberAccess(List<Token> tokens, NodeExpression target, TokenIdent name) : NodeExpression(tokens)
|
||||
{
|
||||
public NodeExpression Target { get; } = target;
|
||||
|
||||
Reference in New Issue
Block a user