finn-lang/AST.cs

71 lines
1.5 KiB
C#
Raw Normal View History

2023-07-02 20:27:12 +00:00
using System.CodeDom.Compiler;
using System.Collections.Generic;
2023-07-02 20:27:12 +00:00
namespace Finn.AST;
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()!;
}
}
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-05 16:18:27 +00:00
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)
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} }}";
}
}
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
}