-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScrParser.cs
51 lines (43 loc) · 1.4 KB
/
ScrParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace MarkerCheck
{
/// <summary>
/// Main parser for Scripture texts. Uses UsfmToken as the
/// tokenizer, and then implements a variety of routines for getting
/// the verse text, text tokens (for checking), etc.
///
/// It can maintain a cache of UsfmTokens to speed parsing. The cache
/// is automatically cleared with scripture changes.
/// </summary>
public class ScrParser
{
#region Member variables
static readonly Regex nonTextMarksRegex = new Regex(@"(\s*//\s*|~)", RegexOptions.Compiled);
private string bookText;
private ScrStylesheet stylesheet;
#endregion
#region Constructor
/// <summary>
/// Creates a parser
/// </summary>
internal ScrParser(ScrStylesheet stylesheet, string text)
{
this.stylesheet = stylesheet;
bookText = text;
}
#endregion
#region Methods for getting (possibly cached) UsfmTokens
/// <summary>
/// Get specified text as a list of tokens.
/// </summary>
public List<UsfmToken> GetUsfmTokens(int bookNum)
{
List<UsfmToken> tokens;
tokens = UsfmToken.Tokenize(stylesheet, bookText, false);
return tokens;
}
#endregion
}
}