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)));
        }
 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);
 }
 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;
 }
        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);
            }
        }
        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;
                    }
                    sourceCode++;
                }
            }

            return new TypeFunctionToken(name, arguments, templates);
        }
        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);
        }