Ejemplo n.º 1
0
        // TODO: dokončiť!
        // zostupne podľa priority vyhľadávania
        // konštanty sa pridružujú k iným operandom a určujú sa podľa kontextu!

        // "string"
        // "string".member
        // "string"[i]

        // &"FILE_LOCALIZED_STRING"

        // 56 | -56 | +56

        // []

        // { 1, 2, 3 }

        // (0,1,2)
        // (0,1,2)[i]

        // (subExpression)
        // (subExpression).member
        // (subExpression)[i]

        // true
        // false
        // undefined

        // thread

        // ::func
        // path::func | path::const

        // var | const
        // var.member
        // var[i]


        // as operators

        // = Expression

        // lastOperand [[delegate]]()
        // lastOperand [[delegate]]().member
        // lastOperand [[delegate]]()[i]

        // lastOperand func()
        // lastOperand func().member
        // lastOperand func()[i]
        // lastOperand path::func()
        // lastOperand path::func().member
        // lastOperand path::func()[i]

        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo, ref bool isSingleOperand, bool isArrayContentDefEnabled, bool isArrayDefEnabled)
        {
            if ((isArrayDefEnabled && (ArrayDef.Check(parentInfo, parsingInfo, scriptInfo))) || // []
                (isArrayContentDefEnabled && ArrayContentDef.Check(parentInfo, parsingInfo, scriptInfo)))    // { 0,1,2 }
            {
                isSingleOperand = IsSingle(parentInfo, parsingInfo);
                return(true);
            }

            if (StringArray.Check(parentInfo, parsingInfo, scriptInfo) || // "str" | "str".member | "str"[]
                LocalizedString.Check(parentInfo, parsingInfo, scriptInfo) || // &"str"
                SignedNumber.Check(parentInfo, parsingInfo, scriptInfo) || // 56 | -56 | +56
                Vector.Check(parentInfo, parsingInfo, scriptInfo) || // (0,1,2) | (0,1,2)[]
                SubExpression.Check(parentInfo, parsingInfo, scriptInfo) || // (exp) | (exp).member* | (exp)[]*
                Literal.Check(parentInfo, parsingInfo, scriptInfo) || // true | false | undefined
                FuncCallModifier.Check(parentInfo, parsingInfo, scriptInfo) || // thread
                DelegateCall.Check(parentInfo, parsingInfo, scriptInfo) || // // [[delegate]](funcArgs) | [[d]]().member* | [[d]]()[]*
                FuncCall.Check(parentInfo, parsingInfo, scriptInfo) || // f() | path::f() | f().member* | f()[i]*
                DelegateDef.Check(parentInfo, parsingInfo, scriptInfo) || // ::func | path::func
                VarName.Check(parentInfo, parsingInfo, scriptInfo)    // var | var.member* | var[i]*
                )
            {
                isSingleOperand = IsSingle(parentInfo, parsingInfo);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public override void Compile(MoveInfo treeInfo, ScriptInfo scriptInfo, CompilingInfo compilingInfo)
        {
            Assign tryAssign = _exp.GetChildren()[0] as Assign;

            if (tryAssign != null)
            {
                ArrayContentDef tryArrayContentDef = tryAssign.Exp.GetChildren()[0] as ArrayContentDef;
                if (tryArrayContentDef != null)
                {
                    IElement compiledStatements = tryArrayContentDef.GetCompiledStatements(tryAssign.VarName);
                    treeInfo.ReplaceCurrent(compiledStatements);
                }
            }
        }
Ejemplo n.º 3
0
        private void GetIndexesAndValues(ArrayContentDef arrayDef, ref Dictionary <Queue <StrIntIndex>, IElement> indexesForValues, Queue <StrIntIndex> lastQueue)
        {
            Queue <StrIntIndex> indexesQueue;

            foreach (StrIntIndex curI in arrayDef._content.Keys)
            {
                if (lastQueue != null)
                {
                    indexesQueue = new Queue <StrIntIndex>(lastQueue);
                }
                else
                {
                    indexesQueue = new Queue <StrIntIndex>();
                }

                indexesQueue.Enqueue(curI);

                IElement curElem = arrayDef._content[curI];

                // empty array {} | []
                if ((curElem is ArrayContentDef && ((ArrayContentDef)curElem)._isEmpty) ||
                    (curElem is Expression && ((Expression)curElem).GetChildren()[0] is ArrayDef))
                {
                    IElement emptyArray = new BallOfMud(new List <IElement> {
                        Token.SQBracketOpen, Token.SQBracketClose
                    });
                    indexesForValues.Add(indexesQueue, emptyArray);
                }
                else if (curElem is ArrayContentDef) // { {...} }
                {
                    GetIndexesAndValues((ArrayContentDef)curElem, ref indexesForValues, indexesQueue);
                }
                else if (curElem is Expression) // {"5"}
                {
                    indexesForValues.Add(indexesQueue, curElem);
                }
                else
                {
                    throw new InvalidOperationException("Ehm...WTF?!...check Parse");
                }
            }
        }
Ejemplo n.º 4
0
        public override IElement CreateCopy()
        {
            ArrayContentDef e = new ArrayContentDef();

            e.AddChildren(this.CopyChildren());

            e._isEmpty = _isEmpty;

            e._contentIntsCount = _contentIntsCount;
            ScopeGroup thisScope = (ScopeGroup)this.children[0];
            ScopeGroup eScope    = (ScopeGroup)e.children[0];

            foreach (StrIntIndex index in _content.Keys)
            {
                IElement value = _content[index];
                e._content.Add(index, eScope.GetChildren()[thisScope.GetChildren().IndexOf(value)]);
            }

            return(e);
        }
Ejemplo n.º 5
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);
        }