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


C# ScriptEngine.BuildTokens方法代码示例

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


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

示例1: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            bool isKeyValueArray = false; // This is false unless we en-counter a : symbol.

            // 1: = [1, 2, 3, 4];
            // 2: = ["foo": 1, "bar": 2, @t1: @t2];
            var items = new List<List<Token>>();
            var namedTokens = new Dictionary<List<Token>, List<Token>>();

            // There are only used if the we building a (key => value) array.
            int index = 0;
            List<Token> identifier = null;

            while (sourceCode.CurrentCode != ']')
            {
                List<Token> chunk = engine.BuildTokens(ref sourceCode, ref script, new[] {':', ',', ']'});
                if (sourceCode.CurrentCode == ':')
                {
                    isKeyValueArray = true;
                    identifier = chunk;
                }
                else if (sourceCode.CurrentCode == ',' || sourceCode.CurrentCode == ']')
                {
                    // End of current item.
                    if (isKeyValueArray)
                    {
                        if (identifier == null)
                        {
                            var id = new List<Token> {new ObjectToken<Number>(new Number(index))};
                            index++;
                            namedTokens[id] = chunk;
                        }
                        else
                        {
                            namedTokens[identifier] = chunk;
                        }
                        identifier = null;
                    }
                    else
                    {
                        items.Add(chunk);
                    }
                }
                if (sourceCode.CurrentCode != ']')
                {
                    sourceCode++;
                }
            }

            return isKeyValueArray ? new ArrayToken(namedTokens) : new ArrayToken(items);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:51,代码来源:ArrayBuilder.cs

示例2: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            if (lastToken is VaraibleToken)
            {
                var arguments = new List<List<Token>>();
                // We are invoking a method.
                while (!sourceCode.EOF && sourceCode.GetOffset(1) != ')')
                {
                    arguments.Add(engine.BuildTokens(ref sourceCode, ref script, new[] {',', ')'}));
                    if (sourceCode.CurrentCode == ')')
                    {
                        break;
                    }
                    sourceCode++;
                }
                return new MethodInvokeToken(arguments);
            }
            else
            {
                List<Token> code = engine.BuildTokens(ref sourceCode, ref script, new[] {')'});

                return new RoundBracketToken(code);
            }
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:24,代码来源:RoundBracketBuilder.cs

示例3: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            sourceCode += 5;

            if (!sourceCode.SeekToNext('('))
            {
                sourceCode.Throw(String.Format("Expected '(', got '{0}' instead", sourceCode.NextCode));
            }

            List<Token> tokens = engine.BuildTokens(ref sourceCode, ref script, new[] {')'});

            sourceCode.SeekToNext(';'); // Go to the ;

            return new FixedToken(tokens);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:15,代码来源:FixedBuilder.cs

示例4: Build

 public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
 {
     //sourceCode++;
     var arguments = new List<List<Token>>();
     while (!sourceCode.EOF && sourceCode.GetOffset(1) != ']')
     {
         arguments.Add(engine.BuildTokens(ref sourceCode, ref script, new[] {',', ']'}));
         if (sourceCode.CurrentCode == ']')
         {
             break;
         }
         sourceCode++;
     }
     return new ArrayAccessToken(arguments);
 }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:15,代码来源:ArrayAccessBuilder.cs

示例5: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            // using (arg1, arg2, arg3) { }

            sourceCode += 5;

            if (!sourceCode.SeekToNext('('))
            {
                sourceCode.Throw("Expected (");
            }

            // Build up the arguments.
            Dictionary<string, List<Token>> items = new Dictionary<string, List<Token>>();

            while (sourceCode.CurrentCode != ')')
            {

                string name = sourceCode.NextWord();

                if (sourceCode.CurrentCode != '=')
                {
                    sourceCode.Throw(String.Format("Unexpected character, {0}.", sourceCode.CurrentCode));
                }

                // Otherwise...
                List<Token> code = engine.BuildTokens(ref sourceCode, ref script, new char[] {',', ')'});

                items.Add(name, code);

            }

            if (!sourceCode.SeekToNext('{'))
            {
                sourceCode.Throw(String.Format("Unexpected character, {0}", sourceCode.NextCode));
            }

            List<List<List<Token>>> codeBlock = engine.BuildLongTokens(ref sourceCode, ref script, new char[] {'}'});

            return new UsingToken(items, codeBlock);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:40,代码来源:UsingBlockBuilder.cs

示例6: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            // Variable
            // Method()
            // Method<T>()
            // Method(args...)
            // Method<T>(args...)
            string name = "";
            var templates = new List<string>();
            var arguments = new List<List<Token>>();

            bool space = false;

            sourceCode++;

            // Firstly, get the name of the method.
            while (!sourceCode.EOF && !IsEndCondition(sourceCode.CurrentCode))
            {
                if (sourceCode.CurrentCode == ' ')
                {
                    space = true;
                }
                else
                {
                    if (space)
                    {
                        throw new Exception("Unexpected Whitespace");
                    }
                    name += sourceCode.CurrentCode;
                }
                sourceCode++;
            }

            if (sourceCode.EOF)
            {
                throw new Exception("Unexpected EOF");
            }

            var opens = new[] {'[', '.', '+', '-', '/', '%', '*', '&', ')', ']'};

            if (opens.Contains(sourceCode.CurrentCode))
            {
                // Opening statement, return what we have.
                return new TypeFunctionToken(name, new List<List<Token>>(), new List<string>(), false);
            }

            space = false;

            // Once we get here...
            if (sourceCode.CurrentCode == '<')
            {
                // Do Generics.
                string currentG = "";
                while (!sourceCode.EOF && sourceCode.CurrentCode != '>')
                {
                    if (sourceCode.CurrentCode == ' ')
                    {
                        space = true;
                    }
                    else
                    {
                        if (sourceCode.CurrentCode == ',')
                        {
                            templates.Add(currentG);
                            space = false;
                            currentG = "";
                        }
                        else
                        {
                            if (space)
                            {
                                throw new Exception("Unexpected Whitespace");
                            }
                            currentG += sourceCode.CurrentCode;
                        }
                    }
                }
                if (sourceCode.EOF)
                {
                    throw new Exception("Unexpected EOF");
                }
            }

            // We then expect a (...
            if (sourceCode.CurrentCode != '(' && sourceCode.CurrentCode != ';')
            {
                throw new Exception("Expected a (");
            }
            else
            {
                if (sourceCode.CurrentCode == ';')
                {
                    return new TypeFunctionToken(name, arguments, templates, false);
                }
                while (!sourceCode.EOF && sourceCode.GetOffset(1) != ')')
                {
                    arguments.Add(engine.BuildTokens(ref sourceCode, ref script, new[] {',', ')'}));
                    if (sourceCode.CurrentCode == ')')
                    {
                        break;
//.........这里部分代码省略.........
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:101,代码来源:TypeFunctionBuilder.cs

示例7: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            // new {objectID}[<{templateArgs}

            sourceCode += 3;
            while (sourceCode.SpecialChar)
            {
                sourceCode++;
            }

            string name = "";
            var templates = new List<string>();
            var arguments = new List<List<Token>>();

            bool space = false;

            // Firstly, get the name of the method.
            while (!sourceCode.EOF && (sourceCode.CurrentCode != '<' && sourceCode.CurrentCode != '('))
            {
                if (sourceCode.CurrentCode == ' ')
                {
                    space = true;
                }
                else
                {
                    if (space)
                    {
                        throw new Exception("Unexpected Whitespace");
                    }
                    name += sourceCode.CurrentCode;
                }
                sourceCode++;
            }

            if (sourceCode.EOF)
            {
                throw new Exception("Unexpected EOF");
            }

            space = false;

            // Once we get here...
            if (sourceCode.CurrentCode == '<')
            {
                // Do Generics.
                string currentG = "";
                while (!sourceCode.EOF && sourceCode.CurrentCode != '>')
                {
                    if (sourceCode.CurrentCode == ' ')
                    {
                        space = true;
                    }
                    else
                    {
                        if (sourceCode.CurrentCode == ',')
                        {
                            templates.Add(currentG);
                            space = false;
                            currentG = "";
                        }
                        else
                        {
                            if (space)
                            {
                                throw new Exception("Unexpected Whitespace");
                            }
                            currentG += sourceCode.CurrentCode;
                        }
                    }
                }
                if (sourceCode.EOF)
                {
                    throw new Exception("Unexpected EOF");
                }
            }

            // We then expect a (...
            if (sourceCode.CurrentCode != '(' && sourceCode.CurrentCode != ';')
            {
                throw new Exception("Expected a (");
            }
            else
            {
                if (sourceCode.CurrentCode == ';')
                {
                    return new TypeFunctionToken(name, arguments, templates, false);
                }
                while (!sourceCode.EOF && sourceCode.GetOffset(1) != ')')
                {
                    arguments.Add(engine.BuildTokens(ref sourceCode, ref script, new[] {',', ')'}));
                    if (sourceCode.CurrentCode == ')')
                    {
                        break;
                    }
                    sourceCode++;
                }
            }

            return new NewTypeToken(name, arguments, templates);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:100,代码来源:NewTypeBuilder.cs

示例8: Build

            public override void Build(ref SourceCode code, ref Script script, ScriptEngine engine, ConfigBuilder config)
            {
                var items = new Dictionary<string, List<Token>>();

                code += _identifier.Length;
                if (code.Peek() != '{')
                {
                    throw new Exception("Syntax Error: Expected a {");
                }

                code.SeekToNext('{');

                while (!(++code).EOF && code.Peek() != '}')
                {
                    // We are expecting: identifier = (code);
                    while (code.SpecialChar)
                    {
                        code++;
                    }
                    string id = "";
                    bool space = false;
                    while (!code.EOF && code.CurrentCode != '=')
                    {
                        if (code.CurrentCode == ' ')
                        {
                            space = true;
                        }
                        else
                        {
                            if (space)
                            {
                                code--; // Rewind, so the error is where the space is.
                                code.Throw("Unexpected whitespace...");
                            }
                            id += code.CurrentCode;
                        }
                        code++;
                    }
                    if (code.EOF)
                    {
                        code.Throw("Unexpected EOF");
                    }
                    // Otherwise
                    code++;

                    List<Token> tokens = engine.BuildTokens(ref code, ref script, new[] {';'});

                    items.Add(id, tokens);
                }

                code.SeekToNext('}');

                config.AddReturnElement(_identifier, items);
            }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:54,代码来源:ConfigBuilder.cs


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