From 108870c7318dc706025ebb3f1821ab715965c4d5 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Fri, 7 Jul 2023 21:29:17 -0600 Subject: [PATCH] Rename Identifier to Variable --- AST.cs | 2 +- Expr.g.cs | 6 +++--- Interpreter.cs | 2 +- Parser.cs | 2 +- Type.cs | 14 ++++++++++++++ ast_classes.fsx | 2 +- 6 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 Type.cs diff --git a/AST.cs b/AST.cs index c41960f..28a5ac9 100644 --- a/AST.cs +++ b/AST.cs @@ -16,7 +16,7 @@ public record Field(Name Name, Expr? Value); public record BaseRecord(Expr Value, Field[] Updates); -public partial record Identifier +public partial record Variable { public override string ToString() { diff --git a/Expr.g.cs b/Expr.g.cs index c7acb80..3a2f5d0 100644 --- a/Expr.g.cs +++ b/Expr.g.cs @@ -17,7 +17,7 @@ public interface IExprVisitor { T visitLiteralExpr(Literal expr); T visitUnaryExpr(Unary expr); T visitIfExpr(If expr); - T visitIdentifierExpr(Identifier expr); + T visitVariableExpr(Variable expr); T visitListExpr(List expr); T visitVariantExpr(Variant expr); T visitRecordExpr(Record expr); @@ -69,11 +69,11 @@ public partial record If(Expr Condition, Expr Then, Expr Else) : Expr() return visitor.visitIfExpr(this); } } -public partial record Identifier(Name Value) : Expr() +public partial record Variable(Name Value) : Expr() { public override T accept(IExprVisitor visitor) { - return visitor.visitIdentifierExpr(this); + return visitor.visitVariableExpr(this); } } public partial record List(Expr[] Elements) : Expr() diff --git a/Interpreter.cs b/Interpreter.cs index a9e049f..f5441be 100644 --- a/Interpreter.cs +++ b/Interpreter.cs @@ -275,7 +275,7 @@ public class Interpreter : AST.IExprVisitor return evaluate(expr.Expression); } - public object visitIdentifierExpr(AST.Identifier expr) + public object visitVariableExpr(AST.Variable expr) { throw new System.NotImplementedException(); } diff --git a/Parser.cs b/Parser.cs index b3ae6af..6ab195a 100644 --- a/Parser.cs +++ b/Parser.cs @@ -396,7 +396,7 @@ class Parser var ident = name(); if (ident != null) { - return new Identifier(ident); + return new Variable(ident); } if (match(TokenType.LParen)) diff --git a/Type.cs b/Type.cs new file mode 100644 index 0000000..b702848 --- /dev/null +++ b/Type.cs @@ -0,0 +1,14 @@ +namespace Finn.Types; + +public record Field(string Name, Type Type); +public record Row(Field[] Fields); +public abstract record Type() +{ + public record Number() : Type(); + public record String() : Type(); + public record Param(int Name) : Type(); + public record List(Type T) : Type(); + public record Record(Row Row) : Type(); + public record Variant(Row Row) : Type(); + public record Function(Type[] Params) : Type(); +} diff --git a/ast_classes.fsx b/ast_classes.fsx index 474211d..988dcae 100644 --- a/ast_classes.fsx +++ b/ast_classes.fsx @@ -22,7 +22,7 @@ let exprTypes = [ { Type = "Expr"; Name = "Condition" } { Type = "Expr"; Name = "Then" } { Type = "Expr"; Name = "Else" } ] } - { Name = "Identifier" + { Name = "Variable" Fields = [ { Type = "Name"; Name = "Value" } ] } { Name = "List" Fields = [ { Type = "Expr[]"; Name = "Elements" } ] }