Пример #1
0
        public static bool TryScan(CodeReader reader, out Style scanned)
        {
            scanned = null;
            string line = reader.NextLine();

            if (!Regex.IsMatch(line, RegEx))
            {
                return(false);
            }
            string name = Regex.Match(line, @"(std:|" + RegExHelper.Variable + @"\()").Value;

            name    = name.Remove(name.Length - 1);
            scanned = new Style(name);
            line    = reader.NextLine();
            while (!reader.Done && !reader.EndingKeyword)
            {
                if (Instruction.TryScan(reader.Copy(), out Instruction instruction))
                {
                    scanned.AddInstruction(instruction);
                    line = reader.NextLine();
                }
                else if (StaticFunctionCallCommand.TryScan(line, out StaticFunctionCallCommand command))
                {
                    scanned.AddCommand(command);
                    line = reader.NextLine();
                }
                else
                {
                    throw new Exception("Unkwon Command in Line " + reader.CurrentLine + ".");
                }
            }
            return(true);
        }
Пример #2
0
        public static bool TryScan(CodeReader reader, Presentation parent, out Slide slide)
        {
            slide = null;
            string line = reader.NextLine();

            if (!Regex.IsMatch(line, RegEx))
            {
                return(false);
            }
            string name = Regex.Match(line, RegExHelper.String).Value.Trim('@', '\'');

            slide = new Slide(name, parent);
            line  = reader.NextLine();
            Step normalStep = null;

            while (!reader.Done && !reader.EndingKeyword)
            {
                if (Step.TryScan(reader.Copy(), slide, out Step step))
                {
                    if (normalStep != null)
                    {
                        slide.AddStep(normalStep);
                    }
                    normalStep = null;
                    reader.Skip(step.LineLength - 1);
                    slide.AddStep(step);
                }
                else
                {
                    if (normalStep == null)
                    {
                        normalStep = new Step("normal", slide);
                    }
                    if (Command.TryScan(reader.Copy(), out Command command))
                    {
                        reader.Skip(command.Lines - 1);
                        normalStep.Add(command);
                    }
                    else if (StaticFunctionCallCommand.TryScan(line, out StaticFunctionCallCommand functionCallCommand))
                    {
                        reader.Skip(functionCallCommand.Lines - 1);
                        normalStep.Add(functionCallCommand);
                    }

                    else
                    {
                        throw new ArgumentException("Unknown Command in Line " + reader.CurrentLine + ".");
                    }
                }
                line = reader.NextLine();
            }
            if (normalStep != null)
            {
                slide.AddStep(normalStep);
            }
            return(true);
        }
Пример #3
0
        public static bool TryScan(CodeReader reader, Slide parent, out Step scanned)
        {
            scanned = null;
            string line = reader.NextLine();

            if (!Regex.IsMatch(line, RegEx))
            {
                return(false);
            }
            string name = Regex.Match(line, RegExHelper.String).Value.Trim('\'');

            scanned = new Step(name, parent);
            line    = reader.NextLine();

            while (!reader.Done && !reader.EndingKeyword && !Regex.IsMatch(line, RegEx))
            {
                if (String.IsNullOrWhiteSpace(line))
                {
                    line = reader.NextLine();
                    continue;
                }
                if (Command.TryScan(reader.Copy(), out Command command))
                {
                    reader.Skip(command.Lines - 1);
                    scanned.Add(command);
                }
                else if (StaticFunctionCallCommand.TryScan(line, out StaticFunctionCallCommand functionCallCommand))
                {
                    reader.Skip(functionCallCommand.Lines - 1);
                    scanned.Add(functionCallCommand);
                }
                else
                {
                    throw new ArgumentException("Unknwon Command in Line " + reader.TextLine + ".");
                }
                line = reader.NextLine();
            }
            return(true);
        }