70 lines
1.4 KiB
C#
70 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Finn.AST;
|
|
|
|
public record Field(Token Name, Expr? Value);
|
|
|
|
public record BaseRecord(Expr Value, Field[] Updates);
|
|
|
|
public partial record Variable
|
|
{
|
|
public override string ToString()
|
|
{
|
|
return this.Value.Lexeme;
|
|
}
|
|
}
|
|
|
|
public partial record Binary
|
|
{
|
|
public override string ToString()
|
|
{
|
|
return $"Binary {{ Left = {this.Left}, Op = {this.Op.Lexeme}, Right = {this.Right} }}";
|
|
}
|
|
}
|
|
|
|
public partial record Literal
|
|
{
|
|
public override string ToString()
|
|
{
|
|
return this.Value.ToString()!;
|
|
}
|
|
}
|
|
|
|
public partial record SimplePattern
|
|
{
|
|
public override string ToString()
|
|
{
|
|
if (this.Identifier == null)
|
|
{
|
|
return "_";
|
|
}
|
|
return this.Identifier.Lexeme;
|
|
}
|
|
}
|
|
|
|
public abstract record Binding(Expr Value);
|
|
public record VarBinding(Pattern Pattern, Expr Value) : Binding(Value);
|
|
public record FuncBinding(Token Name, Pattern[] Params, Expr Value) : Binding(Value)
|
|
{
|
|
public override string ToString()
|
|
{
|
|
return $"FuncBinding {{ Name = {Name}, Params = {string.Join(", ", (IEnumerable<object?>)(this.Params))}, Value = {this.Value} }}";
|
|
}
|
|
}
|
|
|
|
public partial record Let
|
|
{
|
|
public override string ToString()
|
|
{
|
|
return $"Let {{ Bindings = {string.Join(", ", (IEnumerable<object?>)(this.Bindings))}, Body = {this.Body} }}";
|
|
}
|
|
}
|
|
|
|
public partial record RecordPattern
|
|
{
|
|
public override string ToString()
|
|
{
|
|
return $"RecordPattern {{ Bindings = {string.Join(", ", (IEnumerable<object?>)(this.Fields))}, Rest = {this.Rest} }}";
|
|
}
|
|
}
|