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


C# ScriptEngine.BuildLongTokens方法代码示例

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


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

示例1: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            // if (condition) { ... } [else [if (condition) { ... }] { ... }]

            var ifStatement = new Statement();

            sourceCode.SeekToNext('(');
            ifStatement.Condition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {')'});
            sourceCode++;

            sourceCode.SeekToNext('{');
            ifStatement.Code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});
            sourceCode++;

            var elseIfStatements = new List<Statement>();
            Statement elseStatement = null;

            while ((++sourceCode).Peek() == 'e')
            {
                bool isElseIf = false;
                sourceCode.SeekToNext('e');
                sourceCode += 4;
                var s = new Statement();

                if (sourceCode.Peek() == 'i')
                {
                    isElseIf = true;
                    // Get the condition;
                    sourceCode.SeekToNext('i');
                    sourceCode++;
                    sourceCode.SeekToNext('(');
                    s.Condition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {')'});
                    sourceCode++;
                }

                sourceCode.SeekToNext('{');
                s.Code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});
                sourceCode++;

                if (isElseIf)
                {
                    elseIfStatements.Add(s);
                }
                else
                {
                    elseStatement = s;
                }
            }
            return new IfToken(ifStatement, elseIfStatements, elseStatement);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:50,代码来源:IfBlockBuilder.cs

示例2: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            while ((++sourceCode).SpecialChar)
            {
            }
            if (sourceCode.Peek() != '{')
            {
                sourceCode.Throw(String.Format("Error parsing a 'do' statement, expected a '{' but got '{0}' instead.",
                                               sourceCode.Peek()));
            }
            List<List<List<Token>>> code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});

            if (!sourceCode.SeekToNext("while"))
            {
                sourceCode.Throw("Error parsing a 'do' statement, was expecting a 'while' after the { } block.");
            }

            if (!sourceCode.SeekToNext('('))
            {
                sourceCode.Throw("Error parsing a 'do' statement, was expecting a '(' after 'while'.");
            }

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

            return new DoWhileToken(code, exitCondition);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:26,代码来源:DoWhileBlockBuilder.cs

示例3: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            // while (condition) { /* Code */ }
            sourceCode += 4; // The +1 comes from below.

            while ((++sourceCode).SpecialChar)
            {
            }

            if (sourceCode.CurrentCode != '(')
            {
                sourceCode.Throw("Error parsing a 'while' statement, was epexting a '(' after 'while'.");
            }

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

            if (!sourceCode.SeekToNext('{'))
            {
                sourceCode.Throw(String.Format("Unexpected char: '{0}'", sourceCode.CurrentCode));
            }

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

            return new WhileLoopToken(exitCondition, code);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:25,代码来源:WhileBlockBuilder.cs

示例4: 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

示例5: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            // for (init; condition; increment) { /* Code */ }
            sourceCode += 3; // Skip past the "for".

            while (char.IsWhiteSpace(sourceCode.CurrentCode))
            {
                sourceCode++; // Offset until we reach a non-whitespace character.
            }

            if (sourceCode.CurrentCode != '(')
            {
                throw new Exception("Error parsing a 'for' statement, was expecting a '(' after 'for'");
            }

            // Otherwise, moving along!

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

            // We can then build the exitCondition
            List<List<Token>> endCondition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {';'});
            sourceCode++;

            // And then the increment condition.
            List<List<Token>> incrementStatement = engine.BuildTokensAdvanced(ref sourceCode, ref script,
                                                                              new[] {';', ')'});

            if (!sourceCode.SeekToNext('{'))
            {
                throw new Exception("Unexpected char: " + sourceCode.CurrentCode);
            }

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

            sourceCode++;

            return new ForLoopToken(forInit, endCondition, incrementStatement, code);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:39,代码来源:ForBlockBuilder.cs

示例6: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            List<List<List<Token>>> code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});

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

示例7: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            sourceCode += 8; // Skip past function

            // Pattern
            // function functionName(args) { code }

            string functionName = "";
            var argumentNames = new List<string>();

            // Build the name first.
            while (sourceCode.SpecialChar)
            {
                sourceCode++;
            }

            bool space = false;
            while (sourceCode.CurrentCode != '(')
            {
                if (sourceCode.CurrentCode == ' ')
                {
                    space = true;
                }
                else
                {
                    if (space)
                    {
                        sourceCode.Throw("Unexpected Whitespace");
                    }
                    functionName += sourceCode.CurrentCode;
                }
                sourceCode++;
            }

            // Build up arguments now.
            sourceCode++;
            space = false;
            string arg = "";
            while (sourceCode.CurrentCode != ')')
            {
                char c = sourceCode.CurrentCode;
                if (c == ',')
                {
                    if (string.IsNullOrEmpty(arg))
                    {
                        sourceCode.Throw("Expected an argument.");
                    }
                    else
                    {
                        argumentNames.Add(arg);
                        space = false;
                        arg = "";
                    }
                }
                else
                {
                    if (char.IsWhiteSpace(c) && !string.IsNullOrEmpty(arg))
                    {
                        space = true;
                    }
                    else
                    {
                        if (space)
                        {
                            sourceCode.Throw("Unexpected whitespace");
                        }
                        else if (char.IsWhiteSpace(c))
                        {
                            // Do nothing...
                        }
                        else
                        {
                            arg += sourceCode.CurrentCode;
                        }
                    }
                }
                sourceCode++;
            }

            if (string.IsNullOrEmpty(arg))
            {
                sourceCode.Throw("Expected an argument.");
            }
            argumentNames.Add(arg);

            bool result = sourceCode.SeekToNext('{');

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

            return new FunctionToken(functionName, argumentNames, code);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:91,代码来源:FunctionBuilder.cs

示例8: Build

 public override void Build(ref SourceCode code, ref Script script, ScriptEngine engine, ConfigBuilder config)
 {
     string id = "";
     code += _identifier.Length;
     if (code.Peek() == '{' && _requiresID)
     {
         throw new Exception("Script block requires an ID.");
     }
     if (code.Peek() != '{')
     {
         code.SeekToNext('"');
         while (!(++code).EOF && code.CurrentCode != '"')
         {
             id += code.CurrentCode;
         }
         if (code.EOF)
         {
             code.Throw("Unexpected EOF");
         }
     }
     code.SeekToNext('{');
     var c = new Code(engine.BuildLongTokens(ref code, ref script, new[] {'}'}),
                      new Script(engine) {UseEngineGlobals = false});
     config.AddReturnElement(_identifier, new ScriptBlock {Code = c, Identifier = id});
 }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:25,代码来源:ConfigBuilder.cs


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