2023-07-02 22:37:06 +00:00
|
|
|
using System.Collections.Generic;
|
2023-07-02 20:27:12 +00:00
|
|
|
|
2023-07-01 06:12:02 +00:00
|
|
|
namespace Finn.AST;
|
|
|
|
|
2023-10-04 18:31:10 +00:00
|
|
|
public record Field(Token Name, Expr Value);
|
2023-07-02 17:38:48 +00:00
|
|
|
|
|
|
|
public record BaseRecord(Expr Value, Field[] Updates);
|
2023-07-02 20:27:12 +00:00
|
|
|
|
2023-07-08 03:29:17 +00:00
|
|
|
public partial record Variable
|
2023-07-02 20:27:12 +00:00
|
|
|
{
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2023-07-25 19:19:07 +00:00
|
|
|
return this.Value.Lexeme;
|
2023-07-02 20:27:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public partial record Binary
|
|
|
|
{
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2023-07-25 19:19:07 +00:00
|
|
|
return $"Binary {{ Left = {this.Left}, Op = {this.Op.Lexeme}, Right = {this.Right} }}";
|
2023-07-02 20:27:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public partial record Literal
|
|
|
|
{
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return this.Value.ToString()!;
|
|
|
|
}
|
|
|
|
}
|
2023-07-02 22:37:06 +00:00
|
|
|
|
|
|
|
public partial record SimplePattern
|
|
|
|
{
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
if (this.Identifier == null)
|
|
|
|
{
|
|
|
|
return "_";
|
|
|
|
}
|
2023-07-25 19:19:07 +00:00
|
|
|
return this.Identifier.Lexeme;
|
2023-07-02 22:37:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-06 23:07:00 +00:00
|
|
|
public abstract record Binding(Expr Value, Token Start);
|
|
|
|
public record VarBinding(Pattern Pattern, Expr Value) : Binding(Value, Pattern.Start);
|
|
|
|
public record FuncBinding(Token Name, Pattern[] Params, Expr Value) : Binding(Value, Name)
|
2023-07-05 16:18:27 +00:00
|
|
|
{
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return $"FuncBinding {{ Name = {Name}, Params = {string.Join(", ", (IEnumerable<object?>)(this.Params))}, Value = {this.Value} }}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-02 22:37:06 +00:00
|
|
|
public partial record Let
|
|
|
|
{
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return $"Let {{ Bindings = {string.Join(", ", (IEnumerable<object?>)(this.Bindings))}, Body = {this.Body} }}";
|
|
|
|
}
|
2023-07-02 23:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public partial record RecordPattern
|
|
|
|
{
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2023-07-05 16:24:03 +00:00
|
|
|
return $"RecordPattern {{ Bindings = {string.Join(", ", (IEnumerable<object?>)(this.Fields))}, Rest = {this.Rest} }}";
|
2023-07-02 23:07:46 +00:00
|
|
|
}
|
2023-07-05 16:18:27 +00:00
|
|
|
}
|