public async Task CrashTestRunner()
        {
            var tcs = new TaskCompletionSource <object>();

            OtherComponent.Execute(tcs);

            await tcs.Task;
        }
示例#2
0
        private Tag LoadTag(TreeText.Node root, Tag parent)
        {
            if (root.Line[0] == '.')
            {
                root.ErrorChecker().Error("コンポーネントのルートは属性であってはなりません。");
            }

            if (root.Line[0] == '@')
            {
                root.ErrorChecker().Error("コンポーネントのルートはプロパティであってはなりません。");
            }

            if (root.Line[0] == '!')
            {
                root.ErrorChecker().Error("コンポーネントのルートはイベントであってはなりません。");
            }

            if (root.Line.StartsWith("/!"))             // スクリプト
            {
                if (1 <= root.Children.Count)
                {
                    root.ErrorChecker().Error("スクリプトの配下は空でなければなりません。");
                }

                string script = root.Line.Substring(2);

                // script ⇒ 自由な文字列

                return(new ScriptComponent()
                {
                    Script = script,
                });
            }

            string[] tokens;

            if (root.Line.StartsWith("/."))             // メソッド呼び出し
            {
                if (1 <= root.Children.Count)
                {
                    root.ErrorChecker().Error("メソッド呼び出しの配下は空でなければなりません。");
                }

                if (parent is OtherComponent == false)
                {
                    root.ErrorChecker().Error("メソッド呼び出しは別コンポーネント参照に対して使用出来ます。");
                }

                string methodCall = root.Line.Substring(2);
                tokens = methodCall.Split(new char[] { ' ' }, 2);
                string methodName;
                string args2ndAndLater;

                switch (tokens.Length)
                {
                case 1:
                    methodName      = tokens[0];
                    args2ndAndLater = null;
                    break;

                case 2:
                    methodName      = tokens[0];
                    args2ndAndLater = tokens[1];
                    break;

                default:
                    throw null;                             // never
                }

                root.ErrorChecker().CheckFairName(methodName);
                // args2ndAndLater ⇒ 自由な文字列

                return(new OCMethodCall()
                {
                    Name = methodName,
                    Args2ndAndLater = args2ndAndLater,
                    Parent = parent,
                });
            }

            tokens = root.Line.Split(new char[] { ' ' }, 2);

            if (tokens.Length != 2)
            {
                root.ErrorChecker().Error("コンポーネントの行は2つのトークンでなければなりません。");
            }

            string tagName = tokens[0];
            string tagID   = tokens[1];

            Tag tag;

            if (tagName[0] == '/')             // 別コンポーネント参照
            {
                if (parent == null)
                {
                    root.ErrorChecker().Error("ルートタグを別コンポーネント参照には出来ません。");
                }

                string referenceName = tagName.Substring(1);

                root.ErrorChecker().CheckFairName(referenceName, "@^");
                root.ErrorChecker().CheckFairName(tagID);

                tag = new OtherComponent()
                {
                    Name   = referenceName,
                    ID     = tagID,
                    Parent = parent,
                };

                foreach (TreeText.Node node in root.Children)
                {
                    tag.Children.Add(this.LoadTag(node, tag));
                }
                return(tag);
            }

            root.ErrorChecker().CheckFairName(tagName);
            root.ErrorChecker().CheckFairName(tagID);

            tag = new Tag()
            {
                Name   = tagName,
                ID     = tagID,
                Parent = parent,
            };

            foreach (TreeText.Node node in root.Children)
            {
                if (node.Line[0] == '.')                 // 属性
                {
                    if (node.Children.Count != 1)
                    {
                        node.ErrorChecker().Error("属性の配下は1つの属性値でなければなりません。");
                    }

                    if (node.Children[0].Children.Count != 0)
                    {
                        node.ErrorChecker().Error("属性値の配下は空でなければなりません。");
                    }

                    string attrName  = node.Line.Substring(1);
                    string attrValue = node.Children[0].Line;

                    node.ErrorChecker().CheckFairName(attrName);
                    // attrValue ⇒ 自由な文字列

                    tag.Attributes.Add(new Attribute()
                    {
                        Name   = attrName,
                        Value  = attrValue,
                        Parent = tag,
                    });
                }
                else if (node.Line[0] == '@')                 // プロパティ
                {
                    if (node.Children.Count != 1)
                    {
                        node.ErrorChecker().Error("プロパティの配下は1つのプロパティ値でなければなりません。");
                    }

                    if (node.Children[0].Children.Count != 0)
                    {
                        node.ErrorChecker().Error("プロパティ値の配下は空でなければなりません。");
                    }

                    string propName  = node.Line.Substring(1);
                    string propValue = node.Children[0].Line;

                    node.ErrorChecker().CheckFairName(propName);
                    // propValue ⇒ 自由な文字列

                    tag.Properties.Add(new Property()
                    {
                        Name   = propName,
                        Value  = propValue,
                        Parent = tag,
                    });
                }
                else if (node.Line[0] == '!')                 // イベント
                {
                    if (node.Children.Count != 1)
                    {
                        node.ErrorChecker().Error("イベント名の配下は1つのプロパティ値でなければなりません。");
                    }

                    if (node.Children[0].Children.Count != 0)
                    {
                        node.ErrorChecker().Error("スクリプトの配下は空でなければなりません。");
                    }

                    string propName  = node.Line.Substring(1);
                    string propValue = node.Children[0].Line;

                    node.ErrorChecker().CheckFairName(propName);
                    // propValue ⇒ 自由な文字列

                    tag.Properties.Add(new Property()
                    {
                        Kind   = Property.Kind_e.EVENT,
                        Name   = propName,
                        Value  = propValue,
                        Parent = tag,
                    });
                }
                else
                {
                    tag.Children.Add(this.LoadTag(node, tag));
                }
            }
            return(tag);
        }