public static DefinitionCollection Create(CodeReader reader) { CodeReader r = reader.Copy(); DefinitionCollection result = new DefinitionCollection(); result.definitions = new List <Definition>(); List <string> definitions = new List <string>(); while (!r.Done) { string line = r.NextLine(); if (line.StartsWith("def ")) { definitions.Add(line); } } foreach (var def in definitions) { int mid = def.IndexOf(" as "); string patternIn = def.Remove(mid).Substring(4); string patternOut = def.Substring(mid + 4); Definition d = new Definition(patternIn, patternOut.TrimEnd(';')); result.definitions.Add(d); } return(result); }
public static Presentation Parse(CodeReader reader) { CodeReader r = reader.Copy(); Presentation presentation = new Presentation(); DefinitionCollection dc = DefinitionCollection.Create(r); r = dc.CreateReader(r); while (!r.Done) { var line = r.NextLine(); if (Import.TryScan(r.Copy(), out Import import)) { presentation.AddImport(import); r.Skip(import.LineLength - 1); } else if (Style.TryScan(r.Copy(), out Style style)) { presentation.AddStyle(style); r.Skip(style.LineLength - 1); } else if (Interactive.TryScan(r.Copy(), out Interactive interactive)) { presentation.AddInteractive(interactive); r.Skip(interactive.LineLength - 1); } else if (Pattern.TryScan(r.Copy(), out Pattern pattern)) { presentation.AddPattern(pattern); r.Skip(pattern.LineLength - 1); } else if (Slide.TryScan(r.Copy(), presentation, out Slide slide)) { presentation.AddSlide(slide); r.Skip(slide.LineLength - 1); } else { throw new Exception("Unknown Command in Line " + r.CurrentLine + ": " + r.PeekLine()); } Console.WriteLine(line); } return(presentation); }