finn-lang/AST.cs

80 lines
1.6 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;
2023-07-02 20:27:12 +00:00
public record Name(string Value, bool Quoted)
{
public override string ToString()
{
if (this.Quoted) return $"@\"{this.Value}\"";
return this.Value;
}
};
2023-07-02 17:38:48 +00:00
public record Field(Name Name, Expr? Value);
public record BaseRecord(Expr Value, Field[] Updates);
2023-07-02 20:27:12 +00:00
public partial record Identifier
{
public override string ToString()
{
return this.Value.ToString();
}
}
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.ToString();
}
}
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(Name 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()
{
return $"Let {{ Bindings = {string.Join(", ", (IEnumerable<object?>)(this.Fields))}, Rest = {this.Rest} }}";
}
2023-07-05 16:18:27 +00:00
}