Ejemplo n.º 1
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo, string word)
        {
            AccessModifier modifier = new AccessModifier(parentInfo.Current, (MemberAccess)Enum.Parse(typeof(MemberAccess), word));

            parentInfo.Replace(1, modifier);
        }
Ejemplo n.º 2
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ConstDef     constDef = new ConstDef(parentInfo.Current.CharIndex, parentInfo.Current.CharLength, parentInfo.Current.LineIndex);
            MemberAccess access   = MemberAccess.Public;
            bool         isSealed = false;

            int      startIndex = parentInfo.CurrentIndex;
            MoveInfo moveInfo   = new MoveInfo(parentInfo);

            // sealed modifier
            SealedModifier trySealed = SealedModifier.GetModifier(moveInfo);

            if (trySealed != null)
            {
                startIndex = moveInfo.CurrentIndex;
                isSealed   = true;
            }
            else
            {
                moveInfo = new MoveInfo(parentInfo);
            }

            // visibility modifier
            AccessModifier tryAccess = AccessModifier.GetModifier(moveInfo, out access);

            if (tryAccess != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }
            else
            {
                moveInfo = new MoveInfo(parentInfo);
            }

            // xml
            XMLBlock xml = XMLBlock.GetXMLSummary(moveInfo);

            constDef.xmlBlock = xml;
            if (xml != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }

            // assign
            moveInfo = new MoveInfo(parentInfo);
            IElement nameElem = moveInfo.Current;

            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // =
            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // behind =

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

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

            constDef._compiledContent = exp;

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

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

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

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

            // info
            string name = nameElem.ToString();

            // add const def to list
            parsingInfo.ConstDefList.Add(constDef);

            /*if (scriptInfo.Constants.FindIndex(a => a.Name == name) != -1)
             *  ErrorManager.Semantic("Constant '" + name + "' already defined", new ErrorInfo(parentInfo.ErrorInfo));
             * else
             * {*/
            ConstInfo constInfo = GetInfo(name, access, exp, isSealed, constDef.xmlBlock, parsingInfo, constDef);

            scriptInfo.AddConstant(constInfo);
            constDef._constInfo = constInfo;
            //}
        }
Ejemplo n.º 3
0
        public static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            FuncDef function = new FuncDef(parentInfo.Current.CharIndex, parentInfo.Current.CharLength, parentInfo.Current.LineIndex, parsingInfo.SF);

            // začiatok názvu
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            int startIndex = parentInfo.CurrentIndex;

            // modifier
            MemberAccess   access;
            AccessModifier modifier = AccessModifier.GetModifier(moveInfo, out access);

            if (modifier != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }
            else
            {
                moveInfo = new MoveInfo(parentInfo);
            }

            // xml
            XMLBlock xml = XMLBlock.GetXMLSummary(moveInfo);

            function.xmlBlock = xml;
            if (xml != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }

            // začiatok názvu
            moveInfo = new MoveInfo(parentInfo);
            IElement nameElem = moveInfo.Current;

            moveInfo.Move(SearchDirection.LeftToRight);

            // parametry
            IElement paramsTry = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (!(paramsTry is ParenthesesGroup))
            {
                throw new SyntaxException("Could not find FuncDef parameters", parentInfo.GetErrorInfo());
            }

            ParenthesesGroup paramsGroup = (ParenthesesGroup)paramsTry;
            // získaj zoznam parametrov
            MoveInfo            paramsMoveInfo = new MoveInfo(paramsGroup, SearchTree.ContentBlock, 0, moveInfo);
            List <FuncDefParam> defParams      = GetParameterList(paramsMoveInfo, parsingInfo, scriptInfo);

            // pridaj zoznam parametrov do stromu a posuň sa zaň
            moveInfo.Move(SearchDirection.LeftToRight);

            // body
            IElement bodyTry = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (!(bodyTry is ScopeGroup))
            {
                throw new SyntaxException("Could not find FuncDef body", parentInfo.GetErrorInfo());
            }

            ScopeGroup      bodyGroup         = (ScopeGroup)bodyTry;
            List <IElement> bodyGroupChildren = bodyGroup.GetChildren();

            moveInfo.Move(SearchDirection.LeftToRight); // skoč za telo

            // add func to tree
            int             totalLength = moveInfo.CurrentIndex - startIndex;
            List <IElement> children    = parentInfo.CurrentElements.GetRange(startIndex, totalLength);

            function.AddChildren(children);


            foreach (FuncDefParam p in defParams)
            {
                function.LocalVars.Add(new LocalVarInfo(parsingInfo.SF, p.Name, (int)function.ImportantCharIndex, (int)function.ImportantCharLength, null, p.VarName)); // it must be after function.AddChildren() !!
            }
            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(totalLength, function);

            // set current function
            parsingInfo.CurrentFunc = function;
            parsingInfo.FuncDefList.Add(function);

            // go inside body
            MoveInfo bodyInfo = new MoveInfo(bodyGroup, SearchTree.ContentBlock, 0, parentInfo);

            Statement.ParseStatementList(bodyInfo, parsingInfo, scriptInfo);

            // info
            string name = nameElem.ToString();

            /*if (scriptInfo.)
             * if (scriptInfo.Functions.FindIndex(a => a.Name.EqualCode(name)) != -1)
             * {
             *  ErrorManager.Semantic("Function '" + name + "' already defined", new ErrorInfo(parentInfo.ErrorInfo));
             *  return;
             * }*/

            FuncInfo funcInfo = GetInfo(name, access, defParams, xml, parsingInfo, function);

            scriptInfo.AddFunction(funcInfo);

            function.funcInfo = funcInfo;
        }