diff --git a/libs/UIX.Asm/Lexer.Body.cs b/libs/UIX.Asm/Lexer.Body.cs index 985190c..f7fea37 100644 --- a/libs/UIX.Asm/Lexer.Body.cs +++ b/libs/UIX.Asm/Lexer.Body.cs @@ -7,11 +7,11 @@ namespace Microsoft.Iris.Asm; partial class Lexer { - public static readonly Parser BodyItem = ParseBodyItem; - private static IResult ParseBodyItem(IInput input) { input = ConsumeWhitespace(input); + var line = input.Line; + var column = input.Column; var identifierResult = Parse.Letter.AtLeastOnce().Text().Invoke(input); if (!identifierResult.WasSuccessful) @@ -24,7 +24,10 @@ partial class Lexer if (!input.AtEnd && input.Current == ':') { input = input.Advance(); - bodyItem = new Label(identifier); + bodyItem = new Label(identifier) + { + Line = line, Column = column, + }; input = StatementEnd(input).Remainder; } else @@ -38,11 +41,15 @@ partial class Lexer input = ConsumeWhitespace(input); var operandsResult = Parse.Ref(() => AlphanumericText).DelimitedBy(Parse.Char(',').Token())(input); - operands.AddRange(operandsResult.Value.Select(s => new Operand(s))); + operands.AddRange(operandsResult.Value.Select(s => new Operand(s) { Line = line })); input = operandsResult.Remainder; } - bodyItem = new Instruction(identifier, operands); + bodyItem = new Instruction(identifier, operands) + { + Line = line, + Column = column, + }; } return Result.Success(bodyItem, input); diff --git a/libs/UIX.Asm/Lexer.Imports.cs b/libs/UIX.Asm/Lexer.Imports.cs index 8f84aa1..5129351 100644 --- a/libs/UIX.Asm/Lexer.Imports.cs +++ b/libs/UIX.Asm/Lexer.Imports.cs @@ -5,8 +5,6 @@ namespace Microsoft.Iris.Asm; partial class Lexer { - public static readonly Parser Import = ParseImport; - private static IResult ParseImport(IInput input) { input = ConsumeWhitespace(input); diff --git a/libs/UIX.Asm/Lexer.cs b/libs/UIX.Asm/Lexer.cs index f081191..2154449 100644 --- a/libs/UIX.Asm/Lexer.cs +++ b/libs/UIX.Asm/Lexer.cs @@ -17,6 +17,10 @@ public static partial class Lexer from sectionId in Parse.Letter.AtLeastOnce().Text() select sectionId; + public static readonly Parser Import = ParseImport; + + public static readonly Parser BodyItem = ParseBodyItem; + public static readonly Parser Program = from imports in Import.Token().Many() from body in BodyItem.Many() diff --git a/libs/UIX.Asm/Models/Interfaces.cs b/libs/UIX.Asm/Models/Interfaces.cs index 14f6568..ce2b528 100644 --- a/libs/UIX.Asm/Models/Interfaces.cs +++ b/libs/UIX.Asm/Models/Interfaces.cs @@ -10,6 +10,8 @@ public abstract record AsmItem : IAsmItem { public int Line { get; set; } = -1; public int Column { get; set; } = -1; + + internal const string DebuggerDisplay = "({Line}, {Column})"; } public interface IDirective : IAsmItem; diff --git a/libs/UIX.Asm/Models/SyntaxModels.cs b/libs/UIX.Asm/Models/SyntaxModels.cs index 7357e28..9854d81 100644 --- a/libs/UIX.Asm/Models/SyntaxModels.cs +++ b/libs/UIX.Asm/Models/SyntaxModels.cs @@ -1,10 +1,12 @@ using Microsoft.Iris.Markup; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; namespace Microsoft.Iris.Asm.Models; +[DebuggerDisplay("{ToString()} " + DebuggerDisplay)] public record Instruction(string Mnemonic, IEnumerable Operands) : BodyItem { public Instruction(OpCode opCode, OperationType? operationType, IEnumerable Operands) @@ -19,11 +21,18 @@ public record Instruction(string Mnemonic, IEnumerable Operands) : Body public OpCode OpCode => LexerMaps.MnemonicToOpCode(Mnemonic); public OperationType? OperationType => LexerMaps.TryOperationMnemonicToType(Mnemonic); - public override string ToString() => Operands.Any() - ? $"{Mnemonic} {string.Join(", ", Operands)}" - : Mnemonic; + public override string ToString() => ToString(true); + + public string ToString(bool uppercase) + { + var mnemonic = uppercase ? Mnemonic.ToUpperInvariant() : Mnemonic.ToLowerInvariant(); + return Operands.Any() + ? $"{mnemonic} {string.Join(", ", Operands)}" + : mnemonic; + } } +[DebuggerDisplay("{Name} " + DebuggerDisplay)] public record Label(string Name) : BodyItem { public override string ToString() => $"{Name}:";