Allow underscores, dashes, and digits in identifiers

This commit is contained in:
Yoshi Askharoun
2024-02-10 21:37:12 -06:00
parent 3329591b5a
commit 93fa998caa
5 changed files with 28 additions and 12 deletions
+20 -7
View File
@@ -48,19 +48,32 @@ partial class Lexer
break;
case "TYPE":
var typePrefixResult = WordText.Token()(input);
var typePrefixResult = Identifier.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 typeNamespaceDelimitterResult = Parse.Char(':')(input);
input = typeNamespaceDelimitterResult.Remainder;
var typeNameResult = WordText(input);
input = typeNameResult.Remainder;
if (!typeNameResult.WasSuccessful)
return Result.Failure<IImport>(input, "Invalid type import", ["Expected a valid type name"]);
string typeName, typePrefix;
if (typeNamespaceDelimitterResult.WasSuccessful)
{
var typeNameResult = Identifier(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);
typePrefix = typePrefixResult.Value;
typeName = typeNameResult.Value;
}
else
{
typePrefix = null;
typeName = typePrefixResult.Value;
}
import = new TypeImport(typePrefix, typeName);
break;
default: