diff --git a/Parser.Tests/MParserShould.cs b/Parser.Tests/MParserShould.cs index 7aa648d..0a47f54 100644 --- a/Parser.Tests/MParserShould.cs +++ b/Parser.Tests/MParserShould.cs @@ -1,5 +1,6 @@ using Xunit; using FluentAssertions; +using System; namespace Parser.Tests { @@ -150,5 +151,34 @@ namespace Parser.Tests rhs.Span.Start.Should().Be(16); 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 action = sut.Parse; + action.Should().Throw(); + } } } \ No newline at end of file diff --git a/Parser/Internal/MParserGreen.cs b/Parser/Internal/MParserGreen.cs index 32851ba..f9d3480 100644 --- a/Parser/Internal/MParserGreen.cs +++ b/Parser/Internal/MParserGreen.cs @@ -170,6 +170,10 @@ namespace Parser.Internal { var identifierToken = EatToken(TokenKind.IdentifierToken); builder.Add(Factory.IdentifierNameExpressionSyntax(identifierToken)); + if (identifierToken.IsMissing) + { + break; + } } }