public static bool TryScan(CodeReader reader, out Interactive scanned) { scanned = null; string line = reader.NextLine(); if (!Regex.IsMatch(line, RegEx)) { return(false); } string name = Regex.Match(line, @"(transistion:|" + RegExHelper.Variable + @"\()").Value; name = name.Remove(name.Length - 1); string parameters = Regex.Match(line, "\\(" + RegExHelper.FunctionParameters + "\\)").Value.Trim('(', ')'); scanned = new Interactive(name, String.IsNullOrWhiteSpace(parameters) ? new string[0] : parameters.Split(',')); line = reader.NextLine(); while (!reader.Done && !reader.EndingKeyword) { if (Command.TryScan(reader.Copy(), out Command command)) { scanned.AddCommand(command); reader.Skip(command.Lines - 1); line = reader.NextLine(); } else { throw new Exception("Unknown Command in Line " + reader.TextLine + "."); } } return(true); }
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); }
internal CodeReader CreateReader(CodeReader reader) { string text = ""; CodeReader r = reader.Copy(); while (!r.Done) { string line = r.NextLine(); if (line.StartsWith("def ")) { continue; } var matches = definitions.Where(d => d.IsMatch(line)); foreach (var match in matches) { line = match.Apply(line); } text += line + "\n"; } return(CodeReader.FromText(text)); }