示例#1
0
        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);
        }
示例#2
0
        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);
        }