mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Add expectations to lexer
This commit is contained in:
@@ -33,7 +33,7 @@ public static class Lexer
|
||||
|
||||
var identifierResult = Parse.Letter.AtLeastOnce().Text().Invoke(input);
|
||||
if (!identifierResult.WasSuccessful)
|
||||
return Result.Failure<Instruction>(input, "Invalid code", System.Array.Empty<string>());
|
||||
return Result.Failure<Instruction>(input, "Invalid code", []);
|
||||
|
||||
input = identifierResult.Remainder;
|
||||
var identifier = identifierResult.Value;
|
||||
@@ -73,12 +73,12 @@ public static class Lexer
|
||||
var importDirectiveResult = Parse.String(".import-")(input);
|
||||
input = importDirectiveResult.Remainder;
|
||||
if (!importDirectiveResult.WasSuccessful)
|
||||
return Result.Failure<IImport>(input, "Invalid import directive", null);
|
||||
return Result.Failure<IImport>(input, "Invalid import directive", ["Expected '.import'"]);
|
||||
|
||||
var importTypeResult = Parse.Letter.AtLeastOnce().Text()(input);
|
||||
input = importTypeResult.Remainder;
|
||||
if (!importTypeResult.WasSuccessful)
|
||||
return Result.Failure<IImport>(input, "Invalid import type", null);
|
||||
return Result.Failure<IImport>(input, "Invalid import type", ["Expected 'ns'"]);
|
||||
|
||||
IImport import;
|
||||
switch (importTypeResult.Value.ToUpperInvariant())
|
||||
@@ -87,20 +87,20 @@ public static class Lexer
|
||||
var uriResult = Uri.Token()(input);
|
||||
input = uriResult.Remainder;
|
||||
if (!uriResult.WasSuccessful)
|
||||
return Result.Failure<IImport>(input, "Invalid URI", null);
|
||||
return Result.Failure<IImport>(input, "Invalid URI", ["Expected a valid URI"]);
|
||||
|
||||
input = Parse.String("as").Token()(input).Remainder;
|
||||
|
||||
var nameResult = AlphanumericText(input);
|
||||
input = nameResult.Remainder;
|
||||
if (!nameResult.WasSuccessful)
|
||||
return Result.Failure<IImport>(input, "Invalid namespace alias", null);
|
||||
return Result.Failure<IImport>(input, "Invalid namespace alias", ["Expected a valid namespace alias"]);
|
||||
|
||||
import = new NamespaceImport(uriResult.Value, nameResult.Value);
|
||||
break;
|
||||
|
||||
default:
|
||||
return Result.Failure<IImport>(input, $"Unknown import type '{importTypeResult.Value}'", null);
|
||||
return Result.Failure<IImport>(input, $"Unknown import type '{importTypeResult.Value}'", ["Expected 'ns'"]);
|
||||
}
|
||||
|
||||
return Result.Success(import, input);
|
||||
|
||||
Reference in New Issue
Block a user