Browse Source

Address PR review comment

tags/v0.5.1
Mihai 2 years ago
parent
commit
24d3e1bfa8
1 changed files with 8 additions and 16 deletions
  1. +8
    -16
      LLama/Grammar/GrammarParser.cs

+ 8
- 16
LLama/Grammar/GrammarParser.cs View File

@@ -372,25 +372,17 @@ namespace LLama.Grammar

public ParseState Parse(string input)
{
try
{
byte[] byteArray = Encoding.UTF8.GetBytes(input);
ReadOnlySpan<byte> src = new ReadOnlySpan<byte>(byteArray);
ParseState state = new ParseState();
ReadOnlySpan<byte> pos = ParseSpace(src, true);

while (!pos.IsEmpty)
{
pos = ParseRule(state, pos);
}
byte[] byteArray = Encoding.UTF8.GetBytes(input);
ReadOnlySpan<byte> src = new ReadOnlySpan<byte>(byteArray);
ParseState state = new ParseState();
ReadOnlySpan<byte> pos = ParseSpace(src, true);

return state;
}
catch(Exception err)
while (!pos.IsEmpty)
{
Console.Error.WriteLine($"{nameof(Parse)}: error parsing grammar: {err.Message}");
throw;
pos = ParseRule(state, pos);
}

return state;
}
}
}

Loading…
Cancel
Save