当前位置: 首页>>代码示例>>C#>>正文


C# ScriptProcessor.ExecuteStatement方法代码示例

本文整理汇总了C#中ScriptProcessor.ExecuteStatement方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptProcessor.ExecuteStatement方法的具体用法?C# ScriptProcessor.ExecuteStatement怎么用?C# ScriptProcessor.ExecuteStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptProcessor的用法示例。


在下文中一共展示了ScriptProcessor.ExecuteStatement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        /// <summary>
        /// Parses a string as an array.
        /// </summary>
        internal new static SObject Parse(ScriptProcessor processor, string exp)
        {
            // Format: [item1, item2, ... itemn]

            if (Regex.IsMatch(exp, REGEX_EMPTY_ARRAY)) return processor.CreateArray(0);

            exp = exp.Remove(exp.Length - 1, 1).Remove(0, 1).Trim(); // Remove [ and ].

            var elements = new List<SObject>();

            var elementStart = 0;
            var index = 0;
            var depth = 0;
            StringEscapeHelper escaper = new LeftToRightStringEscapeHelper(exp, 0);
            string element;

            while (index < exp.Length)
            {
                var t = exp[index];
                escaper.CheckStartAt(index);

                if (!escaper.IsString)
                {
                    if (t == '{' || t == '[' || t == '(')
                    {
                        depth++;
                    }
                    else if (t == '}' || t == ']' || t == ')')
                    {
                        depth--;
                    }
                    else if (t == ',' && depth == 0)
                    {
                        element = exp.Substring(elementStart, index - elementStart);
                        
                        if (string.IsNullOrWhiteSpace(element))
                            elements.Add(processor.Undefined);
                        else
                            elements.Add(processor.ExecuteStatement(new ScriptStatement(element)));

                        elementStart = index + 1;
                    }
                }

                index++;
            }

            element = exp.Substring(elementStart, index - elementStart);

            if (string.IsNullOrWhiteSpace(element))
                elements.Add(processor.Undefined);
            else
                elements.Add(processor.ExecuteStatement(new ScriptStatement(element)));

            return processor.CreateArray(elements.ToArray());
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:59,代码来源:SArray.cs

示例2: Interpolate

        private static string Interpolate(ScriptProcessor processor, string val)
        {
            // string interpolation
            // replaces the following pattern: {variable}.
            // {something} has to written as {{something}}.
            // string interpolation can be turned on by putting a $ in front of the string literal.

            if (val.Contains("{") && val.Contains("}"))
            {
                var searchOffset = 0;

                while (val.IndexOf("{", searchOffset) > -1 && val.IndexOf("}", searchOffset) > -1)
                {
                    var startIndex = val.IndexOf("{", searchOffset);

                    if (startIndex < val.Length - 2)
                    {
                        if (val[startIndex + 1] == '{')
                        {
                            val = val.Remove(startIndex + 1) + val.Remove(0, startIndex + 2);

                            // find closing bracket and remove it:
                            var level = 1;
                            var i = startIndex + 1;
                            var foundClosing = false;
                            while (!foundClosing && i < val.Length)
                            {
                                var token = val[i];

                                switch (token)
                                {
                                    case '{':
                                        level++;
                                        break;
                                    case '}':
                                        level--;
                                        if (level == 0)
                                        {
                                            val = val.Remove(i) + val.Remove(0, i + 1);
                                            foundClosing = true;
                                        }
                                        break;
                                }

                                i++;
                            }

                            searchOffset = startIndex + 1;
                        }
                        else
                        {
                            var endIndex = val.IndexOf("}", startIndex);
                            if (endIndex > -1)
                            {
                                var interpolationSequence = val.Substring(startIndex, endIndex - startIndex + 1);
                                interpolationSequence = processor.ExecuteStatement(new ScriptStatement(interpolationSequence.Remove(interpolationSequence.Length - 1, 1).Remove(0, 1))).ToString(processor).Value;

                                val = val.Remove(startIndex) + interpolationSequence + val.Remove(0, endIndex + 1);
                                searchOffset = startIndex + interpolationSequence.Length;
                            }
                            else
                            {
                                searchOffset = startIndex + 1;
                            }
                        }
                    }
                }
            }

            return val;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:71,代码来源:SString.cs

示例3: Parse

        /// <summary>
        /// Parses an anonymous object.
        /// </summary>
        internal static SProtoObject Parse(ScriptProcessor processor, string source)
        {
            Prototype prototype = new Prototype(LITERAL_OBJECT);

            source = source.Trim();

            // Format: { member1 : content1, member2 : content2 }

            // Remove "{" and "}":
            source = source.Remove(source.Length - 1, 1).Remove(0, 1).Trim();

            if (source.Length == 0)
                return prototype.CreateInstance(processor, null, false);

            int index = 0;
            string identifier = "";
            string content = "";
            SObject contentObj = null;

            while (index < source.Length)
            {
                int nextSeperatorIndex = source.IndexOf(",", index);
                if (nextSeperatorIndex == -1)
                {
                    nextSeperatorIndex = source.Length - 1;
                }
                else
                {
                    //Let's find the correct ",":

                    nextSeperatorIndex = index;
                       
                    int depth = 0;
                    StringEscapeHelper escaper = new LeftToRightStringEscapeHelper(source, nextSeperatorIndex, true);
                    bool foundSeperator = false;

                    while (!foundSeperator && nextSeperatorIndex < source.Length)
                    {
                        char t = source[nextSeperatorIndex];

                        escaper.CheckStartAt(nextSeperatorIndex);

                        if (!escaper.IsString)
                        {
                            if (t == '{' || t == '[' || t == '(')
                            {
                                depth++;
                            }
                            else if (t == '}' || t == ']' || t == ')')
                            {
                                depth--;
                            }
                            else if (t == ',' && depth == 0)
                            {
                                foundSeperator = true;
                                nextSeperatorIndex--; // it adds one to the index at the end of the while loop, but we need the index where we stopped searching, so we subtract 1 here to accommodate for that.
                            }
                        }

                        nextSeperatorIndex++;
                    }
                }

                string member = source.Substring(index, nextSeperatorIndex - index);

                if (member.Contains(":"))
                {
                    identifier = member.Remove(member.IndexOf(":")).Trim();
                    content = member.Remove(0, member.IndexOf(":") + 1);

                    contentObj = processor.ExecuteStatement(new ScriptStatement(content));
                }
                else
                {
                    identifier = member.Trim();
                    contentObj = processor.Undefined;
                }

                if (!ScriptProcessor.IsValidIdentifier(identifier))
                    processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_MISSING_VAR_NAME);

                prototype.AddMember(processor, new PrototypeMember(identifier, contentObj));

                index = nextSeperatorIndex + 1;
            }

            return prototype.CreateInstance(processor, null, false);
        }
开发者ID:Aragas,项目名称:Pokemon3D-1,代码行数:91,代码来源:SProtoObject.cs


注:本文中的ScriptProcessor.ExecuteStatement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。