Example #1
0
 public CountdownCommand(
     string arguments,
     ConditionalCommand condition     = null,
     ConditionalCommand anticondition = null
     ) : base("countdown", arguments, condition, anticondition)
 {
 }
Example #2
0
 public SetCommand(
     string arguments,
     ConditionalCommand condition     = null,
     ConditionalCommand anticondition = null
     ) : base("set", arguments, condition, anticondition)
 {
 }
Example #3
0
        public Choice(
            string text,
            string target,
            ConditionalCommand condition = null
            )
        {
            this._text   = text;
            this._target = target;

            // If this is non-null, we expect this command to be true before
            // adding this choice.
            this._condition = condition;
        }
Example #4
0
        public Statement(
            string text,
            ConditionalCommand condition = null,
            bool isEither = false
            )
        {
            this._text = text;

            // If this is non-null, we expect this command to be true before
            // adding this statement.
            this._condition = condition;

            this._isEither = isEither;
        }
Example #5
0
        public Command(
            string verb,
            string arguments,
            ConditionalCommand condition     = null,
            ConditionalCommand anticondition = null
            )
        {
            this._verb      = verb;
            this._arguments = arguments;

            // If this is non-null, we expect this command to be true before
            // executing this command.
            this._condition = condition;

            // If this is non-null, we expect this command to be false before
            // executing this command.
            this._anticondition = anticondition;
        }
Example #6
0
        public Page(string rawScript)
        {
            this._commands = new List <Command>();

            this._statements = new List <Statement>();
            this._choices    = new List <Choice>();

            Regex commandRegex = new Regex(
                @"\((?<verb>[\w-]+?):(?<args>[^\)]*?)\)"
                );
            Regex otherChoiceRegex = new Regex(
                @"\[\[(?<text>.+?)->(?<target>.+?)\]\]"
                );
            Regex selfChoiceRegex = new Regex(@"\[\[(?<target>.+)\]\]");

            ConditionalCommand condition = null;

            List <ConditionalCommand> conditions = new List <ConditionalCommand>();

            foreach (string rawLine in rawScript.Split('\n'))
            {
                string line = rawLine.Trim();

                if (line.Length == 0)
                {
                    continue;
                }

                Match match = commandRegex.Match(line);

                if (match.Success)
                {
                    string verb = match.Groups["verb"].Value;
                    string args = match.Groups["args"].Value;

                    switch (verb)
                    {
                    case ("if"):
                    case ("else-if"):
                    case ("else"): {
                        condition = new ConditionalCommand(
                            verb,
                            args,
                            conditions
                            );

                        conditions.Add(condition);

                        break;
                    }

                    default: {
                        if (condition == null)
                        {
                            conditions.Clear();
                        }

                        break;
                    }
                    }

                    switch (verb)
                    {
                    case ("set"): {
                        this._commands.Add(new SetCommand(args, condition));

                        break;
                    }

                    case ("countdown"): {
                        this._commands.Add(
                            new CountdownCommand(
                                args,
                                condition
                                )
                            );

                        break;
                    }

                    case ("either"): {
                        List <string> options = new List <string>();

                        foreach (string option in args.Split(','))
                        {
                            options.Add(option.Trim().Trim('"'));
                        }

                        this._statements.Add(
                            new Statement(
                                String.Join("#", options.ToArray()),
                                condition,
                                true
                                )
                            );

                        break;
                    }

                    default: {
                        break;
                    }
                    } // switch

                    continue;
                }

                if ((condition != null) && (line == "]"))
                {
                    condition = null;

                    continue;
                }

                match = otherChoiceRegex.Match(line);

                if (match.Success)
                {
                    string text   = match.Groups["text"].Value;
                    string target = match.Groups["target"].Value;

                    this._choices.Add(new Choice(text, target, condition));

                    continue;
                }

                match = selfChoiceRegex.Match(line);

                if (match.Success)
                {
                    string target = match.Groups["target"].Value;

                    this._choices.Add(new Choice(target, target, condition));

                    continue;
                }

                this._statements.Add(new Statement(line, condition));
            }
        }