Merge pull request #3 from mahalex/fix-unpaired-brackets-handling
Fix unpaired brackets handling
This commit is contained in:
commit
fe2f09ce6d
@ -15,9 +15,7 @@ namespace Parser.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
#pragma warning disable xUnit1019 // MemberData must reference a member providing a valid data type
|
||||
[MemberData(nameof(SingleTokensData))]
|
||||
#pragma warning restore xUnit1019 // MemberData must reference a member providing a valid data type
|
||||
public void MLexerGreen_Parses_Token(TokenKind kind, string text)
|
||||
{
|
||||
var tokens = ParseText(text);
|
||||
@ -26,9 +24,7 @@ namespace Parser.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
#pragma warning disable xUnit1019 // MemberData must reference a member providing a valid data type
|
||||
[MemberData(nameof(PairTokensData))]
|
||||
#pragma warning restore xUnit1019 // MemberData must reference a member providing a valid data type
|
||||
public void MLexerGreen_Parses_PairOfTokens(TokenKind kind1, string text1, TokenKind kind2, string text2)
|
||||
{
|
||||
var text = text1 + text2;
|
||||
@ -39,9 +35,7 @@ namespace Parser.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
#pragma warning disable xUnit1019 // MemberData must reference a member providing a valid data type
|
||||
[MemberData(nameof(PairTokensWithSeparatorData))]
|
||||
#pragma warning restore xUnit1019 // MemberData must reference a member providing a valid data type
|
||||
public void MLexerGreen_Parses_PairOfTokensWithSeparator(TokenKind kind1, string text1, string separatorText, TokenKind kind2, string text2)
|
||||
{
|
||||
var text = text1 + separatorText + text2;
|
||||
@ -89,8 +83,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 +246,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;
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,7 @@ namespace Parser.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
#pragma warning disable xUnit1019 // MemberData must reference a member providing a valid data type
|
||||
[MemberData(nameof(FilesData))]
|
||||
#pragma warning restore xUnit1019 // MemberData must reference a member providing a valid data type
|
||||
public void TestFile(string fileName)
|
||||
{
|
||||
var text = File.ReadAllText(fileName);
|
||||
|
@ -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<Diagnostic> GetEnumerator()
|
||||
{
|
||||
return _diagnostics.GetEnumerator();
|
||||
@ -66,5 +76,6 @@ namespace Parser.Internal
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user