Esempio n. 1
0
        private static ArrayContentDef Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ArrayContentDef arrayDef = new ArrayContentDef();

            ScopeGroup group = (ScopeGroup)parentInfo.Current;

            MoveInfo moveInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);
            IElement tryNext  = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            // only for strIndex
            MoveInfo strIndexerInfo = new MoveInfo(moveInfo);
            IElement tryAssign      = strIndexerInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryNext == null) // { }
            {
                arrayDef._isEmpty = true;
            }

            while (!arrayDef._isEmpty)
            {
                if (tryNext == null)
                {
                    throw new SyntaxException("Could not find next element in ArrayContentDef", parentInfo.GetErrorInfo());
                }
                else if (tryNext is ScopeGroup) // { {...} }
                {
                    ArrayContentDef contentDef = ArrayContentDef.Parse(moveInfo, parsingInfo, scriptInfo);
                    arrayDef._content.Add(new StrIntIndex(arrayDef._contentIntsCount++), contentDef);

                    tryNext = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
                }
                else if (tryNext.IsTT(TokenType.Word) && tryAssign != null && tryAssign.IsTT(TokenType.Assign)) // { Name = "MyName" }
                {
                    string   strIndex = tryNext.ToString();
                    IElement strValue = null;

                    IElement strValueTry = strIndexerInfo.FindNextBlack(SearchDirection.LeftToRight); // move behind "="
                    if (strValueTry == null)
                    {
                        throw new SyntaxException("Could not find value for strIndex in ArrayContentDef", parentInfo.GetErrorInfo());
                    }

                    if (strValueTry is ScopeGroup) // { Name = {...} }
                    {
                        strValue = ArrayContentDef.Parse(strIndexerInfo, parsingInfo, scriptInfo);
                    }
                    else
                    {
                        strValue = Expression.Parse(strIndexerInfo, parsingInfo, scriptInfo);
                        if (strValue == null)
                        {
                            throw new SyntaxException("Could not parse expression for strIndex in ArrayContentDef", parentInfo.GetErrorInfo());
                        }
                    }

                    StrIntIndex newIndex     = new StrIntIndex(strIndex);
                    StrIntIndex createdIndex = arrayDef._content.Keys.FirstOrDefault(a => a == newIndex); // index may have been already defined in this def..
                    if (createdIndex != null)
                    {
                        scriptInfo.SF.Errors.Add(new SemanticError("ArrayContentDef already contains key '" + strIndex + "'", new ErrorInfo(moveInfo.GetErrorInfo())));
                    }
                    else
                    {
                        arrayDef._content.Add(newIndex, strValue);
                    }

                    tryNext  = strIndexerInfo.FindNextBlack(SearchDirection.LeftToRight);
                    moveInfo = strIndexerInfo;
                }
                else // { 1, "dawd", self GetGuid() }
                {
                    Expression simpleExp = Expression.Parse(moveInfo, parsingInfo, scriptInfo);
                    if (simpleExp == null)
                    {
                        throw new SyntaxException("Could not parse expression in ArrayContentDef", parentInfo.GetErrorInfo());
                    }

                    arrayDef._content.Add(new StrIntIndex(arrayDef._contentIntsCount++), simpleExp);

                    tryNext = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
                }

                if (tryNext == null) // end of def
                {
                    break;
                }
                else if (tryNext.IsTT(TokenType.Comma)) // new elem...
                {
                    tryNext = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

                    // only for strIndex
                    strIndexerInfo = new MoveInfo(moveInfo);
                    tryAssign      = strIndexerInfo.FindNextBlack(SearchDirection.LeftToRight);
                    continue;
                }
                else // WTF?!
                {
                    throw new SyntaxException("Unexpected token '" + tryNext.ToString() + "' in ArrayContentDef", parentInfo.GetErrorInfo());
                }
            }

            arrayDef.AddChildren(group);
            parentInfo.Replace(1, arrayDef);
            return(arrayDef);
        }
Esempio n. 2
0
 public MoveInfo(IBlock curBlock, SearchTree tree, int curIndex, MoveInfo moveInfo)
     : this(curBlock, tree, curIndex, moveInfo.errorInfo.SF)
 {
 }
Esempio n. 3
0
 public MoveInfo(MoveInfo info)
     : this(info.CurrentBlock, info.TreeMode, info.CurrentIndex, info)
 {
 }
Esempio n. 4
0
        private static void ParseLocal(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            FuncCall funcCall = new FuncCall();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            funcCall._nameElem = (Token)moveInfo.Current;
            funcCall._name     = moveInfo.Current.ToString();

            #region ParsingInfo Args
            FuncInfo tryOutFuncInfo = scriptInfo.FindGlobalsFunc(funcCall._name);
            if (tryOutFuncInfo != null && tryOutFuncInfo.HasOutParams)
            {
                parsingInfo.OutParamFuncCall     = funcCall;
                parsingInfo.OutParamFuncInfo     = tryOutFuncInfo;
                parsingInfo.OutParamFuncArgIndex = 0;
            }

            object lastCall         = parsingInfo.CurrentCall;
            int?   lastCallArgIndex = parsingInfo.CurrentCallArgIndex;
            parsingInfo.CurrentCall         = funcCall;
            parsingInfo.CurrentCallArgIndex = 0;
            #endregion

            // args
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            if (!FuncArgs.Check(moveInfo, parsingInfo, scriptInfo))
            {
                throw new SyntaxException("Could not parse funcArgs", parentInfo.GetErrorInfo());
            }

            #region ParsingInfo Args
            if (parsingInfo.OutParamFuncCall != null)
            {
                parsingInfo.OutParamFuncCall = null;
            }

            parsingInfo.CurrentCall         = lastCall;
            parsingInfo.CurrentCallArgIndex = lastCallArgIndex;
            #endregion

            int startIndex = parentInfo.CurrentIndex;
            int length;

            // find self and modifiers
            MoveInfo selfInfo = new MoveInfo(parentInfo);
            IElement self     = selfInfo.FindNextBlack(SearchDirection.RightToLeft);
            if (self != null && self is ExpressionOperand) // self is self or FuncCallModifier
            {
                startIndex = selfInfo.CurrentIndex;
                if (self is FuncCallModifier) // self is FuncCallModifier -> find self
                {
                    self = selfInfo.FindNextBlack(SearchDirection.RightToLeft);
                    if (self != null && self is ExpressionOperand)
                    {
                        startIndex = selfInfo.CurrentIndex;
                    }
                }
            }

            // find members and arrayIndexers
            IElement next = null;
            do
            {
                length = (moveInfo.CurrentIndex + 1) - startIndex;
                next   = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            }while (next != null &&
                    (ArrayIndexer.Check(moveInfo, parsingInfo, scriptInfo) ||
                     DataMember.Check(moveInfo, parsingInfo, scriptInfo)));

            // build
            funcCall.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, funcCall);
        }