diff --git a/Parser.Tests/MLexerGreenTests.cs b/Parser.Tests/MLexerGreenTests.cs index cca2663..5d42561 100644 --- a/Parser.Tests/MLexerGreenTests.cs +++ b/Parser.Tests/MLexerGreenTests.cs @@ -89,8 +89,6 @@ namespace Parser.Tests let text = SyntaxFacts.GetText(kind) where !(text is null) where !(SyntaxFacts.IsUnaryTokenKind(kind) - || SyntaxFacts.IsOpeningToken(kind) - || SyntaxFacts.IsClosingToken(kind) || kind == TokenKind.ApostropheToken) select (kind, text); @@ -254,6 +252,22 @@ namespace Parser.Tests { return true; } + + if (kind1 == TokenKind.CloseBraceToken && kind2 == TokenKind.StringLiteralToken) + { + return true; + } + + if (kind1 == TokenKind.CloseParenthesisToken && kind2 == TokenKind.StringLiteralToken) + { + return true; + } + + if (kind1 == TokenKind.CloseSquareBracketToken && kind2 == TokenKind.StringLiteralToken) + { + return true; + } + return false; } diff --git a/Parser/Internal/DiagnosticsBag.cs b/Parser/Internal/DiagnosticsBag.cs index ca0ab3f..1dadf31 100644 --- a/Parser/Internal/DiagnosticsBag.cs +++ b/Parser/Internal/DiagnosticsBag.cs @@ -57,6 +57,16 @@ namespace Parser.Internal Report($"Unexpected token '{actual}', expected '{expected}'."); } + internal void ReportUnmatchedCloseParenthesis(TextSpan span, TokenKind kind) + { + Report(span, $"Unmatched close parenthesis '{kind}'."); + } + + internal void ReportUnmatchedOpenParenthesisByEndOfFile(TextSpan span) + { + Report(span, "Unmatched open parenthesis by the end of file."); + } + public IEnumerator GetEnumerator() { return _diagnostics.GetEnumerator(); @@ -66,5 +76,6 @@ namespace Parser.Internal { return GetEnumerator(); } + } } \ No newline at end of file diff --git a/Parser/Internal/MLexerGreen.cs b/Parser/Internal/MLexerGreen.cs index 8ff6352..1537d84 100644 --- a/Parser/Internal/MLexerGreen.cs +++ b/Parser/Internal/MLexerGreen.cs @@ -798,19 +798,22 @@ namespace Parser.Internal } else { - throw new ParsingException($"Unmatched \"{tokenInfo.Text}\" at {Window.Position}."); + Diagnostics.ReportUnmatchedCloseParenthesis( + new TextSpan(Window.Position.Offset, 1), tokenInfo.Kind); } } else { - throw new ParsingException($"Unmatched \"{tokenInfo.Text}\" at {Window.Position}."); + Diagnostics.ReportUnmatchedCloseParenthesis( + new TextSpan(Window.Position.Offset, 1), tokenInfo.Kind); } } if (tokenInfo.Kind == TokenKind.EndOfFileToken && TokenStack.Any()) { - throw new ParsingException($"Unmatched \"{TokenStack.Pop()}\" by the end of file."); + Diagnostics.ReportUnmatchedOpenParenthesisByEndOfFile( + new TextSpan(Window.Position.Offset, 1)); } var result = Create(