예제 #1
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            WaitStatement waitStatement = new WaitStatement();
            MoveInfo      moveInfo      = new MoveInfo(parentInfo);

            IElement tryExp = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryExp == null)
            {
                throw new SyntaxException("Could not find wait expression", parentInfo.GetErrorInfo());
            }

            Expression exp = Expression.Parse(moveInfo, parsingInfo, scriptInfo);

            if (exp == null)
            {
                throw new SyntaxException("Could not parse wait expression", parentInfo.GetErrorInfo());
            }

            IElement terminalTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            // terminal
            if (terminalTry == null || !terminalTry.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

            // build
            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            waitStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, waitStatement);
        }
예제 #2
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            SubExpression subExp = new SubExpression();

            ParenthesesGroup group     = (ParenthesesGroup)parentInfo.Current;
            MoveInfo         groupInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);
            Expression       exp       = Expression.Parse(groupInfo, parsingInfo, scriptInfo);

            if (exp == null ||
                groupInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse subExpression", parentInfo.GetErrorInfo());
            }

            int startIndex = parentInfo.CurrentIndex;
            int length     = 1;

            MoveInfo moveInfo = new MoveInfo(parentInfo);
            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)));

            subExp.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, subExp);
        }
예제 #3
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            PostfixIncDec postfixIncDec = new PostfixIncDec();

            int startIndex = parentInfo.CurrentIndex;
            int length;

            // find operand
            MoveInfo operandInfo = new MoveInfo(parentInfo);
            IElement operand     = operandInfo.FindNextBlack(SearchDirection.RightToLeft);

            if (operand != null && operand is ExpressionOperand)
            {
                startIndex = operandInfo.CurrentIndex;
            }
            else
            {
                throw new SyntaxException("Could not find PostfixIncDec operand", parentInfo.GetErrorInfo());
            }

            // build
            length = (parentInfo.CurrentIndex + 1) - startIndex;
            postfixIncDec.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));

            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, postfixIncDec);
        }
예제 #4
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo        moveInfo = new MoveInfo(parentInfo);
            List <IElement> content  = new List <IElement>();

            IElement cur          = moveInfo.Current;
            int      lastXMLIndex = moveInfo.CurrentIndex;

            do
            {
                if (cur.IsTT(TokenType.XMLComment))
                {
                    lastXMLIndex = moveInfo.CurrentIndex;
                }

                cur = moveInfo.Move(SearchDirection.LeftToRight);
            }while (cur != null && (cur.IsTT(TokenType.XMLComment) || cur.IsTT(TokenType.WhiteSpace)));

            int startIndex = parentInfo.CurrentIndex;
            int length     = (lastXMLIndex + 1) - startIndex;

            // add tokens between first and last xml with its
            content.AddRange(moveInfo.CurrentElements.GetRange(startIndex, length));

            IElement xmlBlock = new XMLBlock(content);

            parentInfo.Replace(length, xmlBlock);
        }
예제 #5
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            DoWhileStatement doWhileStatement = new DoWhileStatement();
            MoveInfo         moveInfo         = new MoveInfo(parentInfo);

            doWhileStatement._doKeyword = (Token)moveInfo.Current;

            // statement
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            if (!Statement.Check(moveInfo, parsingInfo, scriptInfo))
            {
                throw new SyntaxException("Could not parse do-while statement", parentInfo.GetErrorInfo());
            }

            doWhileStatement._statement = (Statement)moveInfo.Current;

            // while
            IElement tryWhile = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryWhile == null || !tryWhile.IsTT(TokenType.Word) || !tryWhile.ToString().EqualCode("while"))
            {
                throw new SyntaxException("Could not find do-while while part", parentInfo.GetErrorInfo());
            }

            doWhileStatement._whileKeyword = (Token)tryWhile;

            // expression
            IElement tryExpGroup = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryExpGroup == null || !(tryExpGroup is ParenthesesGroup))
            {
                throw new SyntaxException("Could not find do-while expression", parentInfo.GetErrorInfo());
            }

            ParenthesesGroup expGroup     = (ParenthesesGroup)tryExpGroup;
            MoveInfo         expGroupInfo = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, parentInfo);
            Expression       exp          = Expression.Parse(expGroupInfo, parsingInfo, scriptInfo);

            if (exp == null || expGroupInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse do-while expression", parentInfo.GetErrorInfo());
            }

            doWhileStatement._expParentGroup = expGroup;

            // terminal
            IElement tryTerminal = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryTerminal == null || !tryTerminal.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

            // build
            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            doWhileStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, doWhileStatement);
        }
예제 #6
0
        private static void ParseExtern(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            DelegateDef delegDef = new DelegateDef();

            MoveInfo moveInfo = new MoveInfo(parentInfo);
            Path     path     = Path.Parse(moveInfo, parsingInfo, scriptInfo);

            if (path == null)
            {
                throw new SyntaxException("Bad path", parentInfo.GetErrorInfo());
            }

            delegDef._pathOrUsing = path.ToString();
            delegDef._pathElem    = path;

            // ::
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            delegDef._nameSpaceElem = (Token)moveInfo.Current;

            // name
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            delegDef._name = moveInfo.Current.ToString();

            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            delegDef.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, delegDef);
        }
예제 #7
0
        /// <summary>
        /// Vráti path a pridá ho do stromu
        /// Mal by fungovať oboma smermi.
        /// </summary>
        /// <param name="moveInfo"></param>
        /// <param name="dir"></param>
        /// <param name="startIndex"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static Path Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) // TODO: otestovať oboma smermi!
        {
            // TODO: funguješ správne? skontrolovať!
            MoveInfo moveInfo = new MoveInfo(parentInfo);
            IElement next     = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (next == null)
            {
                return(null);
            }

            int startIndex = moveInfo.CurrentIndex;

            MoveToEnd(moveInfo, SearchDirection.LeftToRight);

            int length = moveInfo.CurrentIndex - startIndex;

            if (length == 0)
            {
                return(null);
            }

            Path path = new Path(parentInfo.CurrentElements.GetRange(startIndex, length));

            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, path);
            return(path);
        }
예제 #8
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            Assign assign = new Assign();

            int startIndex;
            int length;

            // find var define
            MoveInfo varInfo = new MoveInfo(parentInfo);
            IElement var     = varInfo.FindNextBlack(SearchDirection.RightToLeft);

            if (var == null || !(var is ExpressionOperand) || !(var is VarName))
            {
                throw new SyntaxException("Could not parse Assign VarName", parentInfo.GetErrorInfo());
            }

            assign.VarName = (VarName)var;

            startIndex = varInfo.CurrentIndex;

            // parse expression
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // move behind =
            Expression exp = Expression.Parse(moveInfo, parsingInfo, scriptInfo, false, true, true);

            if (exp == null)
            {
                throw new SyntaxException("Could not parse Assign Expression", parentInfo.GetErrorInfo());
            }

            assign.Exp = exp;

            // build
            length = (moveInfo.CurrentIndex + 1) - startIndex;
            assign.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));

            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, assign);

            // add local var def
            IElement baseVar     = ((VarName)var).GetChildren()[0];
            string   baseVarName = baseVar.ToString();

            foreach (string tStr in ScriptManager.GlobalVariables)
            {
                if (baseVarName.EqualCode(tStr))
                {
                    return;
                }
            }

            LocalVarInfo tryVarInfo = parsingInfo.CurrentFunc.LocalVars.Find(a => a.Name.EqualCode(baseVarName)); // there is maybe var with this name...

            if (tryVarInfo == null)
            {
                parsingInfo.CurrentFunc.LocalVars.Add(new LocalVarInfo(parsingInfo.SF, baseVarName, baseVar.CharIndex, baseVar.CharLength, assign, (VarName)var));
            }
        }
예제 #9
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            IfElseStatement ifElse = new IfElseStatement();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            IElement expTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (expTry == null || !(expTry is ParenthesesGroup))
            {
                throw new SyntaxException("Could not find if expression", parentInfo.GetErrorInfo());
            }

            ParenthesesGroup expGroup = (ParenthesesGroup)expTry;
            MoveInfo         expInfo  = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, moveInfo);

            Expression exp = Expression.Parse(expInfo, parsingInfo, scriptInfo);

            if (exp == null)
            {
                throw new SyntaxException("Could not find if expression", parentInfo.GetErrorInfo());
            }

            if (expInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse if expression", parentInfo.GetErrorInfo());
            }

            moveInfo.Move(SearchDirection.LeftToRight);

            if (!Statement.Check(moveInfo, parsingInfo, scriptInfo))
            {
                throw new SyntaxException("Could not find statement", parentInfo.GetErrorInfo());
            }

            int endIndex = moveInfo.CurrentIndex;

            IElement tryElse = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryElse != null && tryElse.IsTT(TokenType.Word) && moveInfo.Current.ToString() == "else")
            {
                moveInfo.Move(SearchDirection.LeftToRight);
                if (!Statement.Check(moveInfo, parsingInfo, scriptInfo))
                {
                    throw new SyntaxException("Could not find statement", parentInfo.GetErrorInfo());
                }

                endIndex = moveInfo.CurrentIndex;
            }

            int             totalLength = (endIndex + 1) - parentInfo.CurrentIndex;
            List <IElement> children    = parentInfo.CurrentElements.GetRange(parentInfo.CurrentIndex, totalLength);

            ifElse.AddChildren(children);

            parentInfo.Replace(totalLength, ifElse);
        }
예제 #10
0
        private static void ParseUnsigned(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            SignedNumber n = new SignedNumber(new List <IElement>()
            {
                parentInfo.Current
            });

            parentInfo.Replace(1, n);
        }
예제 #11
0
        private static void ParseSigned(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            int          length = ((moveInfo.CurrentIndex + 1) - parentInfo.CurrentIndex);
            SignedNumber n      = new SignedNumber(parentInfo.CurrentElements.GetRange(parentInfo.CurrentIndex, length));

            parentInfo.Replace(length, n);
        }
예제 #12
0
        public static void ParseEndRegion(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo        moveInfo = new MoveInfo(parentInfo);
            List <IElement> content  = new List <IElement>(2);

            content.Add(moveInfo.Current);
            content.Add(moveInfo.Move(SearchDirection.LeftToRight));

            IBlock region = new PreProcessorRegion(content);

            parentInfo.Replace(2, region);
        }
예제 #13
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            BlockStatement bS             = new BlockStatement();
            ScopeGroup     statementGroup = (ScopeGroup)parentInfo.Current;

            MoveInfo groupInfo = new MoveInfo(statementGroup, SearchTree.ContentBlock, 0, parentInfo);

            Statement.ParseStatementList(groupInfo, parsingInfo, scriptInfo);

            bS.AddChildren(statementGroup);
            parentInfo.Replace(1, bS);
        }
예제 #14
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            FuncArgs funcArgs = new FuncArgs();

            ParenthesesGroup group     = (ParenthesesGroup)parentInfo.Current;
            MoveInfo         groupInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);

            IElement next = groupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            while (next != null)
            {
                Expression exp = Expression.Parse(groupInfo, parsingInfo, scriptInfo);
                next = groupInfo.FindNextBlack(SearchDirection.LeftToRight); // jump behind funcArg
                if (exp == null ||
                    (next != null && !next.IsTT(TokenType.Comma)))
                {
                    throw new SyntaxException("Could not parse funcArg", parentInfo.GetErrorInfo());
                }

                if (next != null)
                {
                    next = groupInfo.FindNextBlack(SearchDirection.LeftToRight); // jump behind ,
                    if (next == null)
                    {
                        throw new SyntaxException("Could not parse funcArg", parentInfo.GetErrorInfo());
                    }
                }

                CheckOutParam(parsingInfo, exp, parentInfo);

                if (parsingInfo.CurrentCall != null &&
                    parsingInfo.CurrentCallArgIndex != null)
                {
                    if (parsingInfo.CurrentCall is FuncCall)
                    {
                        ((FuncCall)parsingInfo.CurrentCall).Arguments.Add(exp);
                        parsingInfo.CurrentCallArgIndex++;
                    }
                    else if (parsingInfo.CurrentCall is DelegateCall)
                    {
                        ((DelegateCall)parsingInfo.CurrentCall).Arguments.Add(exp);
                        parsingInfo.CurrentCallArgIndex++;
                    }
                    else
                    {
                        throw new ArgumentException("parsingInfo.CurrentCall");
                    }
                }
            }

            funcArgs.AddChildren(group);
            parentInfo.Replace(1, funcArgs);
        }
예제 #15
0
        /// <summary>
        /// Vytvorí grupu s obsahom [ ] a prepíše ju v strome.
        /// </summary>
        /// <param name="moveInfo"></param>
        /// <param name="dir"></param>
        /// <param name="startIndex"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static void Parse(MoveInfo moveInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            int startIndex;
            int length;

            moveInfo.GetGroupCorners(TokenType.SQBracketOpen, TokenType.SQBracketClose,
                                     SearchVisibility.Visible, out startIndex, out length);

            SQBracketGroup group = new SQBracketGroup(moveInfo.CurrentElements.GetRange(startIndex, length));

            moveInfo.Replace(length, group);
        }
예제 #16
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            int             startIndex = parentInfo.CurrentIndex;
            int             length     = (moveInfo.CurrentIndex + 1) - startIndex;
            List <IElement> children   = parentInfo.CurrentElements.GetRange(startIndex, length);

            LocalizedString s = new LocalizedString(children);

            parentInfo.Replace(length, s);
        }
예제 #17
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            SQBracketGroup group    = (SQBracketGroup)parentInfo.Current;
            MoveInfo       moveInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);

            if (moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible) != null)
            {
                throw new SyntaxException("Unknown tokens in ArrayDef", parentInfo.GetErrorInfo());
            }

            ArrayDef arrayDef = new ArrayDef();

            arrayDef.AddChildren(group);
            parentInfo.Replace(1, arrayDef);
        }
예제 #18
0
        public static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo moveInfo = new MoveInfo(parentInfo);
            IElement next     = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (next == null || !next.IsTT(TokenType.Word))
            {
                throw new SyntaxException("Could not find member", parentInfo.GetErrorInfo());
            }

            int        length = (moveInfo.CurrentIndex + 1) - parentInfo.CurrentIndex;
            DataMember m      = new DataMember(parentInfo.CurrentElements.GetRange(parentInfo.CurrentIndex, length));

            parentInfo.Replace(length, m);
        }
예제 #19
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ArrayIndexer aI = new ArrayIndexer();

            SQBracketGroup SQGroup     = (SQBracketGroup)parentInfo.Current;
            MoveInfo       SQGroupInfo = new MoveInfo(SQGroup, SearchTree.ContentBlock, 0, parentInfo);
            Expression     exp         = Expression.Parse(SQGroupInfo, parsingInfo, scriptInfo);

            if (exp == null || SQGroupInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse array index", parentInfo.GetErrorInfo());
            }

            aI.AddChildren(SQGroup);
            parentInfo.Replace(1, aI);
        }
예제 #20
0
        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo, bool isTerminated)
        {
            ExpressionStatement expStatement = new ExpressionStatement();

            Expression exp = Expression.Parse(parentInfo, parsingInfo, scriptInfo, true, false, false);

            if (exp == null)
            {
                return(false);
            }

            expStatement._exp = exp;

            // exp content
            string   error   = "Only Assign, FuncCall, DelegateCall and PostfixIncDec is allowed as statement";
            MoveInfo expInfo = new MoveInfo(exp, SearchTree.ChildrenBlock, 0, parentInfo);

            if (!((expInfo.Current is Assign ||
                   expInfo.Current is FuncCall ||
                   expInfo.Current is DelegateCall ||
                   expInfo.Current is PostfixIncDec
                   ) && expInfo.FindNextBlack(SearchDirection.LeftToRight) == null))
            {
                throw new SyntaxException(error, parentInfo.GetErrorInfo());
            }

            // next token
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            if (isTerminated)
            {
                IElement terminal = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
                if (terminal == null || !terminal.IsTT(TokenType.SemiColon))
                {
                    throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
                }
            }

            // build
            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            expStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, expStatement);

            return(true);
        }
예제 #21
0
        private static void ParseLocal(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            DelegateDef delegDef = new DelegateDef();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            delegDef._nameSpaceElem = (Token)moveInfo.Current;

            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // jump behind ::
            delegDef._name = moveInfo.Current.ToString();

            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            delegDef.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, delegDef);
        }
예제 #22
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            CaseSwitchStatement caseSwitch = new CaseSwitchStatement();
            MoveInfo            moveInfo   = new MoveInfo(parentInfo);

            // expression
            IElement   next = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            Expression exp  = Expression.Parse(moveInfo, parsingInfo, scriptInfo);

            if (exp == null)
            {
                throw new SyntaxException("Could not parse case expression", parentInfo.GetErrorInfo());
            }

            // terminal
            IElement tryTerminal = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryTerminal == null || !tryTerminal.IsTT(TokenType.Colon))
            {
                throw new SyntaxException("Missing directive ':'?", parentInfo.GetErrorInfo());
            }

            // statements
            IElement nextStatement = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            while (nextStatement != null) // end of switch
            {
                if (CaseSwitchStatement.Check(moveInfo, parsingInfo, scriptInfo, false) ||
                    DefaultSwitchStatement.Check(moveInfo, parsingInfo, scriptInfo, false))
                {
                    break;
                }

                Statement.Check(moveInfo, parsingInfo, scriptInfo);

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

            // build
            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex) - startIndex;

            caseSwitch.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, caseSwitch);
        }
예제 #23
0
        /// <summary>
        /// Vytvorí grupu s obsahom [[ ]] a prepíše ju v strome.
        /// </summary>
        /// <param name="moveInfo"></param>
        /// <param name="dir"></param>
        /// <param name="startIndex"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            SQBracketGroup  outerGroup         = (SQBracketGroup)parentInfo.Current;
            List <IElement> outerGroupChildren = outerGroup.GetChildren();

            MoveInfo        outerGroupInfo     = new MoveInfo(outerGroup, SearchTree.ContentBlock, 0, parentInfo);
            SQBracketGroup  innerGroup         = (SQBracketGroup)outerGroupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);
            List <IElement> innerGroupChildren = innerGroup.GetChildren();
            int             startElemsCount    = outerGroupChildren.IndexOf(innerGroup) + 1;
            int             endElemsCount      = outerGroupChildren.Count - startElemsCount + 1;

            outerGroupInfo.Replace(1, innerGroupChildren);

            List <IElement> children = outerGroup.GetChildren();

            DelegateCallGroup delegateCall = new DelegateCallGroup(children, startElemsCount, endElemsCount);

            parentInfo.Replace(1, delegateCall);
        }
예제 #24
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            StringArray strArray = new StringArray();

            MoveInfo moveInfo = new MoveInfo(parentInfo);
            IElement next     = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            int length = 1;

            if (next != null &&
                (ArrayIndexer.Check(moveInfo, parsingInfo, scriptInfo) ||
                 DataMember.Check(moveInfo, parsingInfo, scriptInfo)))
            {
                length = (moveInfo.CurrentIndex + 1) - parentInfo.CurrentIndex;
            }

            strArray.AddChildren(parentInfo.CurrentElements.GetRange(parentInfo.CurrentIndex, length));
            parentInfo.Replace(length, strArray);
        }
예제 #25
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ContinueStatement continueStatement = new ContinueStatement();
            MoveInfo          moveInfo          = new MoveInfo(parentInfo);

            // terminal
            IElement terminalTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (terminalTry == null || !terminalTry.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

            // build
            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            continueStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, continueStatement);
        }
예제 #26
0
        public static FuncDefParam Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            FuncDefParam param = new FuncDefParam();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            MoveInfo wordMoveInfo = moveInfo;
            IElement wordTry      = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);
            int      startIndex   = moveInfo.CurrentIndex;

            if (wordTry == null)
            {
                throw new SyntaxException("Could not parse FuncDef param", parentInfo.GetErrorInfo());
            }

            if (wordTry is SQBracketGroup)
            {
                param._group   = (SQBracketGroup)wordTry;
                param.Optional = true;

                MoveInfo bracketInfo = new MoveInfo((SQBracketGroup)wordTry, SearchTree.ContentBlock, 0, moveInfo);
                wordTry      = bracketInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);
                wordMoveInfo = bracketInfo;
            }

            if (wordTry == null || !wordTry.IsTT(TokenType.Word))
            {
                throw new SyntaxException("Could not parse FuncDef param", parentInfo.GetErrorInfo());
            }

            VarName.Parse(wordMoveInfo, parsingInfo, scriptInfo);
            param.VarName = (VarName)wordMoveInfo.Current;

            param.Name = wordTry.ToString();
            param.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, moveInfo.CurrentIndex - startIndex + 1));
            parentInfo.Replace((moveInfo.CurrentIndex + 1) - startIndex, param);
            return(param);
        }
예제 #27
0
        public static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            VarName varName = new VarName();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            int startIndex = parentInfo.CurrentIndex;
            int length;

            // 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)));

            varName.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, varName);
        }
예제 #28
0
        public static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            Vector vec = new Vector();

            ParenthesesGroup group     = (ParenthesesGroup)parentInfo.Current;
            MoveInfo         groupInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);

            for (int i = 0; i < 3; i++)
            {
                Expression exp  = Expression.Parse(groupInfo, parsingInfo, scriptInfo);
                IElement   next = groupInfo.FindNextBlack(SearchDirection.LeftToRight);
                if ((i < 2 && !next.IsTT(TokenType.Comma)) ||
                    (i == 2 && next != null))
                {
                    throw new SyntaxException("Could not parse vector " + (i + 1) + " expression", parentInfo.GetErrorInfo());
                }

                if (i != 2) // move behind ,
                {
                    groupInfo.Move(SearchDirection.LeftToRight);
                }
            }

            int startIndex = parentInfo.CurrentIndex;
            int length     = 1;

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            if (moveInfo.Current != null && ArrayIndexer.Check(moveInfo, parsingInfo, scriptInfo))
            {
                length = (moveInfo.CurrentIndex + 1) - startIndex;
            }

            vec.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, vec);
        }
예제 #29
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ReturnStatement returnStatement = new ReturnStatement();
            MoveInfo        moveInfo        = new MoveInfo(parentInfo);

            IElement tryExp = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryExp == null)
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

            // expression defined
            if (!tryExp.IsTT(TokenType.SemiColon))
            {
                Expression exp = Expression.Parse(moveInfo, parsingInfo, scriptInfo, false, false, true);
                if (exp == null)
                {
                    throw new SyntaxException("Could not parse return expression", parentInfo.GetErrorInfo());
                }

                moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            }

            // terminal
            if (moveInfo.Current == null || !moveInfo.Current.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

            // build
            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            returnStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, returnStatement);
        }
예제 #30
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            WhileStatement whileStatement = new WhileStatement();
            MoveInfo       moveInfo       = new MoveInfo(parentInfo);

            // expression
            IElement expGroupTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (expGroupTry == null || !(expGroupTry is ParenthesesGroup))
            {
                throw new SyntaxException("Could not find while expression", parentInfo.GetErrorInfo());
            }

            ParenthesesGroup expGroup     = (ParenthesesGroup)expGroupTry;
            MoveInfo         expGroupInfo = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, parentInfo);
            Expression       exp          = Expression.Parse(expGroupInfo, parsingInfo, scriptInfo);

            if (exp == null || expGroupInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse while expression", parentInfo.GetErrorInfo());
            }

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

            // build
            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            whileStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, whileStatement);
        }