Tests for Parser

This commit is contained in:
Michael Schimmel
2025-11-25 14:40:04 +01:00
parent 29c36c7ae0
commit d84509c034
6 changed files with 172 additions and 73 deletions
+5 -2
View File
@@ -16,6 +16,9 @@ uses
Myc.Ast;
type
// Exception specific to the binding phase (e.g. undefined symbols, invalid identifiers)
EBinderException = class(EAstException);
IAstBinder = interface(IAstVisitor)
function Execute(const RootNode: IAstNode; out Layout: IScopeLayout): IAstNode;
end;
@@ -236,7 +239,7 @@ begin
if Node.Address.Kind = akUnresolved then
begin
if not ResolveSymbol(Node.Name, physAddr) then
raise Exception.CreateFmt('Undefined identifier: "%s"', [Node.Name]);
raise EBinderException.CreateFmt('Undefined identifier: "%s"', [Node.Name]);
if physAddr.ScopeDepth > 0 then
begin
@@ -262,7 +265,7 @@ var
begin
var identifier := Node.Target.AsIdentifier;
if not IsValidIdentifier(identifier.Name) then
raise Exception.CreateFmt('Invalid identifier name: "%s".', [identifier.Name]);
raise EBinderException.CreateFmt('Invalid identifier name: "%s".', [identifier.Name]);
slot := FCurrentBuilder.Define(identifier.Name);
addr := TResolvedAddress.Create(akLocalOrParent, 0, slot);