From 19196f737e481440bdddacb0ad0578b404e07440 Mon Sep 17 00:00:00 2001 From: IronicJuice <81492870+IronicJuice@users.noreply.github.com> Date: Tue, 8 Oct 2024 23:36:02 +0200 Subject: [PATCH 1/2] Removed _src from TokenStream.cs as it was never assigned or used --- SudoScript.Core/Parser.cs | 24 +++++++++++++----------- SudoScript.Core/Tokenizer.cs | 4 +--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/SudoScript.Core/Parser.cs b/SudoScript.Core/Parser.cs index feeb9fb..e68d5e9 100644 --- a/SudoScript.Core/Parser.cs +++ b/SudoScript.Core/Parser.cs @@ -119,22 +119,24 @@ private static List ParseParameters(TokenStream stream) List paramChildren = new List(); // While leftBrace is not read, it will keep reading parameters. - while (stream.Peek(true ,out Token? endToken) && endToken.Type != TokenType.LeftBrace) + while (stream.Peek(true ,out Token? endToken) && endToken.Type != TokenType.LeftBrace) { - if (!stream.Expect(TokenType.Space, out Token _)) + if (stream.Expect(TokenType.Space, out Token? _)) { - throw new Exception("Parameter are expected to be separated by space"); - } + // Checks whether the parameter is an identifier or a cell and parses them acordingly + if (stream.Peek(true, out Token? leftParenthesis) && leftParenthesis.Type == TokenType.LeftParenthesis) + { + paramChildren.Add(ParseParameterCell(stream)); + } - // Checks whether the parameter is an identifier or a cell and parses them acordingly - if (stream.Peek(true, out Token? leftParenthesis) && leftParenthesis.Type == TokenType.LeftParenthesis) - { - paramChildren.Add(ParseParameterCell(stream)); + if (stream.Peek(true, out Token? identifier) && identifier.Type == TokenType.Identifier) + { + paramChildren.Add(ParseParameterIdentifier(stream)); + } } - - if (stream.Peek(true, out Token? identifier) && identifier.Type == TokenType.Identifier) + else { - paramChildren.Add(ParseParameterIdentifier(stream)); + throw new Exception("Parameter are expected to be separated by space"); } } diff --git a/SudoScript.Core/Tokenizer.cs b/SudoScript.Core/Tokenizer.cs index 010a92a..44649a5 100644 --- a/SudoScript.Core/Tokenizer.cs +++ b/SudoScript.Core/Tokenizer.cs @@ -47,8 +47,6 @@ public sealed class TokenStream : IDisposable private char? _carry; - private readonly string _src; - public TokenStream(TextReader reader) { _reader = reader; @@ -256,7 +254,7 @@ private bool GetToken([NotNullWhen(true)] out Token? nextToken) throw new ArgumentException($"Unrecognized character: {character} is not a recognised token"); } - nextToken = new Token(type, match, row, column, _src); + nextToken = new Token(type, match, row, column, ""); if (nextToken.Type == TokenType.BlockComment || nextToken.Type == TokenType.LineComment) { From ecdcbf3b7daf00f3a07beed5cd547a0a43c54435 Mon Sep 17 00:00:00 2001 From: IronicJuice <81492870+IronicJuice@users.noreply.github.com> Date: Tue, 8 Oct 2024 23:53:14 +0200 Subject: [PATCH 2/2] Inverted the if statement back based on feedback --- SudoScript.Core/Parser.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SudoScript.Core/Parser.cs b/SudoScript.Core/Parser.cs index e68d5e9..fed087b 100644 --- a/SudoScript.Core/Parser.cs +++ b/SudoScript.Core/Parser.cs @@ -121,7 +121,11 @@ private static List ParseParameters(TokenStream stream) // While leftBrace is not read, it will keep reading parameters. while (stream.Peek(true ,out Token? endToken) && endToken.Type != TokenType.LeftBrace) { - if (stream.Expect(TokenType.Space, out Token? _)) + if (!stream.Expect(TokenType.Space, out Token? _)) + { + throw new Exception("Parameter are expected to be separated by space"); + } + else { // Checks whether the parameter is an identifier or a cell and parses them acordingly if (stream.Peek(true, out Token? leftParenthesis) && leftParenthesis.Type == TokenType.LeftParenthesis) @@ -134,10 +138,6 @@ private static List ParseParameters(TokenStream stream) paramChildren.Add(ParseParameterIdentifier(stream)); } } - else - { - throw new Exception("Parameter are expected to be separated by space"); - } } return paramChildren;