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


C# SourceCode.GetOffset方法代码示例

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


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

示例1: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            string text = "";
            bool space = false;
            bool isFloat = false;

            if (sourceCode.CurrentCode == '-')
            {
                text = "-";
                sourceCode++;
                while (sourceCode.SpecialChar)
                {
                    sourceCode++;
                }
            }

            while (!sourceCode.EOF && !engine.IsStatementEnd(sourceCode.CurrentCode, true))
            {
                if (sourceCode.CurrentCode == ' ')
                {
                    space = true;
                }
                else
                {
                    if (space)
                    {
                        throw new Exception("Unexpected Whitespace");
                    }
                    if (sourceCode.CurrentCode == '.')
                    {
                        if (!char.IsNumber(sourceCode.GetOffset(1)))
                        {
                            break;
                        }
                    }
                    if (sourceCode.CurrentCode == 'f' || sourceCode.CurrentCode == 'F')
                    {
                        isFloat = true;
                    }
                    else
                    {
                        if (isFloat)
                        {
                            throw new Exception("Expected ending condition.");
                        }
                        text += sourceCode.CurrentCode;
                    }
                }
                sourceCode++;
            }
            if (sourceCode.EOF)
            {
                throw new Exception("Unexpected EOF");
            }
            return new ObjectToken<Number>(new Number(double.Parse(text)));
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:56,代码来源:NumberBuilder.cs

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

示例3: Build

 public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
 {
     string text = "";
     bool space = false;
     bool isLocal = (sourceCode.CurrentCode == '@');
     if (sourceCode.GetOffset(1) == '$')
     {
         // Special code.
     }
     sourceCode++;
     while (!sourceCode.EOF)
     {
         if (sourceCode.CurrentCode == ' ')
         {
             space = true;
         }
         else
         {
             if (engine.IsStatementEnd(sourceCode.CurrentCode))
             {
                 return new VaraibleToken(text, isLocal);
             }
             else
             {
                 if (space)
                 {
                     //throw new Exception("Unexpected whitespace.");
                     // Treat this as another statement, return what we have.
                     sourceCode--;
                     return new VaraibleToken(text, isLocal);
                 }
                 text += sourceCode.CurrentCode;
             }
         }
         sourceCode++;
     }
     if (sourceCode.EOF)
     {
         throw new Exception("Unexpected EOF");
     }
     return null;
 }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:42,代码来源:VariableBuilder.cs

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

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

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


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