mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Allow underscores, dashes, and digits in identifiers
This commit is contained in:
@@ -26,7 +26,7 @@ partial class Lexer
|
|||||||
return Result.Success(directiveBodyItem, input);
|
return Result.Success(directiveBodyItem, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
var identifierResult = Parse.Letter.AtLeastOnce().Text().Invoke(input);
|
var identifierResult = Identifier.Invoke(input);
|
||||||
if (!identifierResult.WasSuccessful)
|
if (!identifierResult.WasSuccessful)
|
||||||
return Result.Failure<IBodyItem>(input, "Invalid code", []);
|
return Result.Failure<IBodyItem>(input, "Invalid code", []);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ partial class Lexer
|
|||||||
var line = input.Line;
|
var line = input.Line;
|
||||||
var column = input.Column;
|
var column = input.Column;
|
||||||
|
|
||||||
var directiveBeginResult = Parse.String(".")(input);
|
var directiveBeginResult = Parse.Char('.')(input);
|
||||||
input = directiveBeginResult.Remainder;
|
input = directiveBeginResult.Remainder;
|
||||||
if (!directiveBeginResult.WasSuccessful)
|
if (!directiveBeginResult.WasSuccessful)
|
||||||
return Result.Failure<IDirective>(input, "Invalid directive", ["Expected '.', followed by an identifier"]);
|
return Result.Failure<IDirective>(input, "Invalid directive", ["Expected '.', followed by an identifier"]);
|
||||||
@@ -20,7 +20,7 @@ partial class Lexer
|
|||||||
var directiveIdResult = WordText(input);
|
var directiveIdResult = WordText(input);
|
||||||
input = directiveIdResult.Remainder;
|
input = directiveIdResult.Remainder;
|
||||||
if (!directiveIdResult.WasSuccessful)
|
if (!directiveIdResult.WasSuccessful)
|
||||||
return Result.Failure<IDirective>(input, "Invalid directive", ["Expected an identifier"]);
|
return Result.Failure<IDirective>(input, "Invalid directive", ["Expected a valid directive name"]);
|
||||||
|
|
||||||
IDirective directive;
|
IDirective directive;
|
||||||
switch (directiveIdResult.Value.ToUpperInvariant())
|
switch (directiveIdResult.Value.ToUpperInvariant())
|
||||||
@@ -48,7 +48,7 @@ partial class Lexer
|
|||||||
if (StatementEnd(input).WasSuccessful)
|
if (StatementEnd(input).WasSuccessful)
|
||||||
return Result.Failure<IImport>(input, "Invalid export directive", ["Expected export information"]);
|
return Result.Failure<IImport>(input, "Invalid export directive", ["Expected export information"]);
|
||||||
|
|
||||||
var labelPrefixResult = AlphanumericText.Token()(input);
|
var labelPrefixResult = Identifier.Token()(input);
|
||||||
input = labelPrefixResult.Remainder;
|
input = labelPrefixResult.Remainder;
|
||||||
if (!labelPrefixResult.WasSuccessful)
|
if (!labelPrefixResult.WasSuccessful)
|
||||||
return Result.Failure<IImport>(input, "Invalid export directive", ["Expected prefix of labels to export"]);
|
return Result.Failure<IImport>(input, "Invalid export directive", ["Expected prefix of labels to export"]);
|
||||||
|
|||||||
@@ -48,19 +48,32 @@ partial class Lexer
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "TYPE":
|
case "TYPE":
|
||||||
var typePrefixResult = WordText.Token()(input);
|
var typePrefixResult = Identifier.Token()(input);
|
||||||
input = typePrefixResult.Remainder;
|
input = typePrefixResult.Remainder;
|
||||||
if (!typePrefixResult.WasSuccessful)
|
if (!typePrefixResult.WasSuccessful)
|
||||||
return Result.Failure<IImport>(input, "Invalid type import", ["Expected a valid namespace prefix"]);
|
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);
|
string typeName, typePrefix;
|
||||||
|
if (typeNamespaceDelimitterResult.WasSuccessful)
|
||||||
|
{
|
||||||
|
var typeNameResult = Identifier(input);
|
||||||
input = typeNameResult.Remainder;
|
input = typeNameResult.Remainder;
|
||||||
if (!typeNameResult.WasSuccessful)
|
if (!typeNameResult.WasSuccessful)
|
||||||
return Result.Failure<IImport>(input, "Invalid type import", ["Expected a valid type name"]);
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ public static partial class Lexer
|
|||||||
|
|
||||||
public static readonly Parser<string> WholeNumber = Parse.Digit.AtLeastOnce().Text();
|
public static readonly Parser<string> WholeNumber = Parse.Digit.AtLeastOnce().Text();
|
||||||
|
|
||||||
|
public static readonly Parser<string> Identifier = Parse.LetterOrDigit.Or(Parse.Chars('_', '-')).AtLeastOnce().Text();
|
||||||
|
|
||||||
public static readonly Parser<string> Uri = Parse.LetterOrDigit.Or(Parse.Chars(":/!._-")).AtLeastOnce().Text();
|
public static readonly Parser<string> Uri = Parse.LetterOrDigit.Or(Parse.Chars(":/!._-")).AtLeastOnce().Text();
|
||||||
|
|
||||||
public static readonly Parser<string> StatementEnd = Parse.Char(';').Return(";").Or(Parse.LineTerminator);
|
public static readonly Parser<string> StatementEnd = Parse.Char(';').Return(";").Or(Parse.LineTerminator);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public class Assembly(ITestOutputHelper output)
|
|||||||
.import-ns Me as me
|
.import-ns Me as me
|
||||||
.import-ns assembly://UIX/Microsoft.Iris as iris
|
.import-ns assembly://UIX/Microsoft.Iris as iris
|
||||||
.import-type iris:Command
|
.import-type iris:Command
|
||||||
|
.import-type Int32
|
||||||
|
|
||||||
|
|
||||||
.section data
|
.section data
|
||||||
@@ -40,7 +41,7 @@ main:
|
|||||||
output.WriteLine(ast.ToString());
|
output.WriteLine(ast.ToString());
|
||||||
|
|
||||||
Assert.NotNull(ast);
|
Assert.NotNull(ast);
|
||||||
Assert.Equal(3 + 1 + 2, ast.Directives.Count());
|
Assert.Equal(3 + 2 + 2, ast.Directives.Count());
|
||||||
Assert.Equal(9, ast.Body.Count());
|
Assert.Equal(9, ast.Body.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user