diff --git a/SimaiSharp/src/Internal/LexicalAnalysis/Tokenizer.cs b/SimaiSharp/src/Internal/LexicalAnalysis/Tokenizer.cs index 3a15529..56df517 100644 --- a/SimaiSharp/src/Internal/LexicalAnalysis/Tokenizer.cs +++ b/SimaiSharp/src/Internal/LexicalAnalysis/Tokenizer.cs @@ -136,7 +136,8 @@ public IEnumerable GetTokens() } default: - throw new UnsupportedSyntaxException(_line, _charIndex); + // throw new UnsupportedSyntaxException(_line, _charIndex); + return null; } } diff --git a/SimaiSharp/src/Internal/SyntacticAnalysis/States/SlideReader.cs b/SimaiSharp/src/Internal/SyntacticAnalysis/States/SlideReader.cs index cd9a3c6..315e2a0 100644 --- a/SimaiSharp/src/Internal/SyntacticAnalysis/States/SlideReader.cs +++ b/SimaiSharp/src/Internal/SyntacticAnalysis/States/SlideReader.cs @@ -104,7 +104,8 @@ private static void DecorateSlide(in Token token, ref SlidePath path) path.type = NoteType.Break; return; default: - throw new UnsupportedSyntaxException(token.line, token.character); + // throw new UnsupportedSyntaxException(token.line, token.character); + return; } } @@ -190,7 +191,7 @@ private static void ReadDuration(TimingChange timing, in Token token, ref SlideP } } - var durationDeclaration = token.lexeme.Span[startOfDurationDeclaration..]; + var durationDeclaration = token.lexeme.Span[startOfDurationDeclaration..].ToString().Replace(" ", ""); var indexOfSeparator = durationDeclaration.IndexOf(':'); // Slide duration: diff --git a/SimaiSharp/src/SimaiFile.cs b/SimaiSharp/src/SimaiFile.cs index 6d90bf8..e772625 100644 --- a/SimaiSharp/src/SimaiFile.cs +++ b/SimaiSharp/src/SimaiFile.cs @@ -26,9 +26,9 @@ public SimaiFile(FileSystemInfo file) var fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read); // Determine the encoding of the file - var buffer = new byte[64]; + var buffer = new byte[64]; var numCharsRead = fileStream.Read(buffer, 0, 64); - var encoding = buffer[..numCharsRead].TryGetEncoding(sampleSize); + var encoding = buffer[..numCharsRead].TryGetEncoding(sampleSize); // We've already read 64 chars, so we'll reset here. fileStream.Position = 0; @@ -59,7 +59,7 @@ public SimaiFile(StreamReader reader) public IEnumerable> ToKeyValuePairs() { - var currentKey = string.Empty; + var currentKey = string.Empty; var currentValue = new StringBuilder(); while (!_simaiReader.EndOfStream) @@ -78,6 +78,8 @@ public IEnumerable> ToKeyValuePairs() } var keyValuePair = line.Split('=', 2); + if (keyValuePair.Length != 2) + continue; currentKey = keyValuePair[0][1..]; currentValue.AppendLine(keyValuePair[1]); } @@ -93,10 +95,10 @@ public IEnumerable> ToKeyValuePairs() public string? GetValue(string key) { - var keyPart = $"&{key}="; + var keyPart = $"&{key}="; var keyPartLength = keyPart.Length; - var result = new StringBuilder(); + var result = new StringBuilder(); var readingValue = false; while (!_simaiReader.EndOfStream)