Add type imports and exports to parser

This commit is contained in:
Yoshi Askharoun
2024-02-08 10:51:08 -06:00
parent 9e8ffe786b
commit 3c2ae6a9cd
6 changed files with 83 additions and 9 deletions
+17 -1
View File
@@ -23,7 +23,7 @@ partial class Lexer
return Result.Failure<IImport>(input, "Invalid import type", ["An import type must be specified"]);
input = input.Advance();
var importTypeResult = Parse.Letter.AtLeastOnce().Text()(input);
var importTypeResult = WordText(input);
input = importTypeResult.Remainder;
if (!importTypeResult.WasSuccessful)
return Result.Failure<IImport>(input, "Invalid import type", ["Expected 'ns'"]);
@@ -47,6 +47,22 @@ partial class Lexer
import = new NamespaceImport(uriResult.Value, nameResult.Value);
break;
case "TYPE":
var typePrefixResult = WordText.Token()(input);
input = typePrefixResult.Remainder;
if (!typePrefixResult.WasSuccessful)
return Result.Failure<IImport>(input, "Invalid type import", ["Expected a valid namespace prefix"]);
input = Parse.Char(':')(input).Remainder;
var typeNameResult = WordText(input);
input = typeNameResult.Remainder;
if (!typeNameResult.WasSuccessful)
return Result.Failure<IImport>(input, "Invalid type import", ["Expected a valid type name"]);
import = new TypeImport(typePrefixResult.Value, typeNameResult.Value);
break;
default:
return Result.Failure<IImport>(input, $"Unknown import type '{importTypeResult.Value}'", ["Expected 'ns'"]);
}