Skip to content

Commit

Permalink
Fix decorators making semicolons optional sometimes
Browse files Browse the repository at this point in the history
Fixes weird break positions when debugging code that uses decorators
  • Loading branch information
Rohansi committed Jan 24, 2022
1 parent 7234f3d commit 7a1df3c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
13 changes: 13 additions & 0 deletions Mond.Tests/Expressions/DecoratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ namespace Mond.Tests.Expressions
[TestFixture]
public class DecoratorTests
{
[Test]
public void Decorator_ParsesTrailingSemicolon()
{
Assert.Throws<MondCompilerException>(() => Script.Run(@"
fun identity(x) -> x;
@identity
fun add(x, y) -> x + y
return add(2, 2);
"));
}

[Test]
public void FunctionDecorator()
{
Expand Down
5 changes: 2 additions & 3 deletions Mond/Compiler/Instruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ public int Length

public void Print()
{
if (Type >= InstructionType.DebugInfo)
return;

if (Type == InstructionType.Label)
Console.ForegroundColor = ConsoleColor.DarkGreen;
else if (Type >= InstructionType.DebugInfo)
Console.ForegroundColor = ConsoleColor.DarkYellow;

Console.Write("{0:X4} {1,-15} ", Offset, Type.ToString().ToLower());

Expand Down
6 changes: 5 additions & 1 deletion Mond/Compiler/InstructionOperands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ public DebugIdentifierOperand(ConstantOperand<string> name, bool isReadOnly, int
Id = id;
}

public virtual void Print() => throw new NotSupportedException();
public virtual void Print()
{
var desc = $"{FrameIndex}:{Id}={Name.Value}[{(IsReadOnly ? "r" : "rw")}]";
Console.Write("{0,-30} (dbgident)", desc);
}

public int Length => 0;

Expand Down
2 changes: 1 addition & 1 deletion Mond/Compiler/Parselets/Statements/DecoratorParselet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
while (parser.MatchAndTake(TokenType.Decorator))
exprs.Add(parser.ParseExpression());

var stmt = parser.ParseStatement(trailingSemicolon);
var stmt = parser.ParseStatement();

if (stmt is VarExpression varExpr)
{
Expand Down

0 comments on commit 7a1df3c

Please sign in to comment.