Skip to content

Commit

Permalink
Updates from review
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Jul 26, 2024
1 parent 9bbd12a commit d9d77db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 34 deletions.
28 changes: 15 additions & 13 deletions src/SIL.Machine/Corpora/UsfmParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using SIL.Scripture;

Expand Down Expand Up @@ -42,7 +43,19 @@ public static void Parse(
versification,
preserveWhitespace
);
parser.ProcessTokens();
try
{
parser.ProcessTokens();
}
catch (Exception ex)
{
var sb = new StringBuilder();
sb.Append(
$"An error occurred while parsing the USFM text in Verse: {parser.State.VerseRef}, line: {parser.State.LineNumber}, "
);
sb.Append($"column: {parser.State.ColumnNumber}, error: '{ex.Message}'");
throw new InvalidOperationException(sb.ToString(), ex);
}
}

private static readonly Regex OptBreakSplitter = new Regex("(//)", RegexOptions.Compiled);
Expand Down Expand Up @@ -130,18 +143,7 @@ bool preserveWhitespace
/// </summary>
public void ProcessTokens()
{
bool continueProcessing = true;
while (continueProcessing)
{
try
{
continueProcessing = ProcessToken();
}
catch (Exception e)
{
throw new UsfmParsingException(State, e);
}
}
while (ProcessToken()) { }
}

/// <summary>
Expand Down
14 changes: 0 additions & 14 deletions src/SIL.Machine/Corpora/UsfmParsingException.cs

This file was deleted.

17 changes: 10 additions & 7 deletions tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,22 @@ public void GetRows_TriplicateVerse()
TextRow[] rows = GetRows(
@"\id MAT - Test
\c 1
\v 1 First verse
\rem non verse
\v 1 First verse
\rem non verse
\v 1 First verse
\v 1 First verse 1
\rem non verse 1
\v 1 First verse 2
\rem non verse 2
\v 1 First verse 3
\rem non verse 3
\v 2 Second verse
",
includeAllText: true
);
Assert.Multiple(() =>
{
Assert.That(rows[0].Text, Is.EqualTo("First verse"), string.Join(",", rows.ToList().Select(tr => tr.Text)));
Assert.That(rows, Has.Length.EqualTo(4), string.Join(",", rows.ToList().Select(tr => tr.Text)));
Assert.That(rows, Has.Length.EqualTo(5), string.Join(",", rows.ToList().Select(tr => tr.Text)));
Assert.That(rows[0].Text, Is.EqualTo("First verse 1"));
Assert.That(rows[3].Text, Is.EqualTo("non verse 3"));
Assert.That(rows[4].Text, Is.EqualTo("Second verse"));
});
}

Expand Down

0 comments on commit d9d77db

Please sign in to comment.