Parse indexing expressions
This commit is contained in:
parent
5f9b4a2fb6
commit
aca4f669ad
@ -125,4 +125,9 @@ class ASTPrinter : IVisitor<string>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public string visitIndexerExpr(Indexer expr)
|
||||
{
|
||||
return parenthesize("index", expr.Left, expr.Index);
|
||||
}
|
||||
}
|
||||
|
10
Expr.g.cs
10
Expr.g.cs
@ -22,6 +22,7 @@ public interface IVisitor<T> {
|
||||
T visitVariantExpr(Variant expr);
|
||||
T visitRecordExpr(Record expr);
|
||||
T visitSelectorExpr(Selector expr);
|
||||
T visitIndexerExpr(Indexer expr);
|
||||
}
|
||||
public class Sequence : Expr
|
||||
{
|
||||
@ -120,3 +121,12 @@ public class Selector : Expr
|
||||
return visitor.visitSelectorExpr(this);
|
||||
}
|
||||
}
|
||||
public class Indexer : Expr
|
||||
{
|
||||
public required Expr Left { get; init; }
|
||||
public required Expr Index { get; init; }
|
||||
public override T accept<T>(IVisitor<T> visitor)
|
||||
{
|
||||
return visitor.visitIndexerExpr(this);
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +220,9 @@ class Parser
|
||||
|
||||
if (match(TokenType.LBracket))
|
||||
{
|
||||
throw new NotImplementedException("TODO index");
|
||||
var index = expression();
|
||||
consume(TokenType.RBracket, "Expect '[' after expression.");
|
||||
return new Indexer { Left = expr, Index = index };
|
||||
}
|
||||
|
||||
if (match(TokenType.LParen))
|
||||
|
@ -30,10 +30,13 @@ let types =
|
||||
Fields = [ { Type = "Name"; Name = "Tag" }; { Type = "Expr?"; Name = "Argument" } ] }
|
||||
{ Name = "Record"
|
||||
Fields =
|
||||
[ { Type = "Field[]"; Name = "Extensions" }
|
||||
[ { Type = "Field[]"
|
||||
Name = "Extensions" }
|
||||
{ Type = "BaseRecord?"; Name = "Base" } ] }
|
||||
{ Name = "Selector"
|
||||
Fields = [ { Type = "Expr"; Name = "Left" }; { Type = "Name"; Name = "FieldName" } ] } ]
|
||||
Fields = [ { Type = "Expr"; Name = "Left" }; { Type = "Name"; Name = "FieldName" } ] }
|
||||
{ Name = "Indexer"
|
||||
Fields = [ { Type = "Expr"; Name = "Left" }; { Type = "Expr"; Name = "Index" } ] } ]
|
||||
|
||||
let visitorMethod baseName t = $"visit{t.Name}{baseName}"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user