Fix infinite loop when parsing parameter list

This fixes a bug reported by David Garrison: on
encountering the new function argument validation
syntax, the parser went into an infinite loop.
This commit is contained in:
Alexander Luzgarev 2022-04-21 18:12:26 +02:00
parent 6c204846ce
commit 98ae1a1499
2 changed files with 34 additions and 0 deletions

View File

@ -1,5 +1,6 @@
using Xunit; using Xunit;
using FluentAssertions; using FluentAssertions;
using System;
namespace Parser.Tests namespace Parser.Tests
{ {
@ -150,5 +151,34 @@ namespace Parser.Tests
rhs.Span.Start.Should().Be(16); rhs.Span.Start.Should().Be(16);
rhs.Span.End.Should().Be(17); rhs.Span.End.Should().Be(17);
} }
[Fact]
public void NotHangOnUnknownSyntax()
{
var text = @"
classdef myClass
properties
Channel;
NodeID;
Node;
end
methods
function this = sendData(this, arg1, arg2)
arguments
this (1,1) myClass
arg1 (1,1) double {mustBeNonnegative}
arg2 (1,1) double {mustBeNonnegative}
end
If (arg1 = 0)
this.NodeID = 3;
end
end
function this = getData(this, arg1, arg2)
end
end";
var sut = GetSut(text);
Func<SyntaxTree> action = sut.Parse;
action.Should().Throw<ParsingException>();
}
} }
} }

View File

@ -170,6 +170,10 @@ namespace Parser.Internal
{ {
var identifierToken = EatToken(TokenKind.IdentifierToken); var identifierToken = EatToken(TokenKind.IdentifierToken);
builder.Add(Factory.IdentifierNameExpressionSyntax(identifierToken)); builder.Add(Factory.IdentifierNameExpressionSyntax(identifierToken));
if (identifierToken.IsMissing)
{
break;
}
} }
} }