public async Task <MemoMap> ReadAllAsync()
        {
            Rewind();

            var map   = new MemoMap();
            var lines = new List <Match>();

            while (!EndOfStream)
            {
                var line = await ReadLineAsync();

                var match = OrdinalRegex.Match(line);
                if (match.Success)
                {
                    if (lines.Count > 0)
                    {
                        var measure = MemoMeasure.Parse(lines);
                        measure.Ordinal = map.Measures.Count + 1;
                        map.Measures.Add(measure);
                        lines.Clear();
                    }
                    var ordinal = int.Parse(match.Groups["ordinal"].Value);
                    Debug.Assert(map.Measures.Count + 1 == ordinal);
                    continue;
                }

                match = MemoLineRegex.Match(line);
                if (match.Success)
                {
                    lines.Add(match);
                    continue;
                }

                Debug.Assert(string.IsNullOrEmpty(line));
            }

            return(map);
        }
Example #2
0
 public static MemoMeasure ParseMeasure(IReadOnlyList <string> lines)
 {
     return(ParseMeasure(lines.Select(l => MemoLineRegex.Match(l)).ToList()));
 }