Example #1
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);
        }
Example #2
0
        /// <summary>
        /// Vráti XMLBlock, kt. sa nachádza pred pozíciou moveInfo
        /// </summary>
        /// <param name="moveInfo"></param>
        /// <returns></returns>
        public static XMLBlock GetXMLSummary(MoveInfo moveInfo)
        {
            IElement cur = moveInfo.Move(SearchDirection.RightToLeft);

            while (cur != null && !cur.Visible)
            {
                if (cur is XMLBlock)
                {
                    return((XMLBlock)cur);
                }

                cur = moveInfo.Move(SearchDirection.RightToLeft);
            }
            return(null);
        }
Example #3
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);
        }
Example #4
0
        public XmlElement ToXML(XmlDocument doc, XmlElement elem, ScriptInfo si)
        {
            MoveInfo treeInfo = new MoveInfo(this, SearchTree.ChildrenTree, 0, si.SF);
            IElement curElem  = treeInfo.Current;

            while (curElem != null)
            {
                if (curElem is Path)
                {
                    XmlElement pathElem = doc.CreateElement("path");
                    ((Path)curElem).ToXML(doc, pathElem, si);
                    elem.AppendChild(pathElem);
                }
                else if (curElem is Token &&
                         !treeInfo.IsIn <Path>(true)) // ignore path tokens
                {
                    XmlElement tokenElem = doc.CreateElement("token");
                    ((Token)curElem).ToXML(doc, tokenElem, si);
                    elem.AppendChild(tokenElem);
                }

                curElem = treeInfo.Move(SearchDirection.LeftToRight);
            }
            return(elem);
        }
Example #5
0
 public static void ParseStatementList(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
 {
     while (Check(parentInfo, parsingInfo, scriptInfo))
     {
         parentInfo.Move(SearchDirection.LeftToRight);
     }
 }
Example #6
0
        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            if (parentInfo.Current is ParenthesesGroup)
            {
                ParenthesesGroup group    = (ParenthesesGroup)parentInfo.Current;
                MoveInfo         moveInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);

                int i;
                for (i = 0; i < 2; i++)
                {
                    IElement next = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible, a => a.IsTT(TokenType.Comma));
                    if (next == null)
                    {
                        break;
                    }

                    moveInfo.Move(SearchDirection.LeftToRight);
                }

                if (i == 0)
                {
                    return(false);
                }
                else if (i == 2)
                {
                    Parse(parentInfo, parsingInfo, scriptInfo);
                    return(true);
                }
                else
                {
                    throw new SyntaxException("Only 3D vector is allowed", parentInfo.GetErrorInfo());
                }
            }
            return(false);
        }
Example #7
0
 /// <summary>
 /// Posunie MoveInfo na koniec pathu.
 /// Ukazuje na nasledujúci elem
 /// </summary>
 /// <param name="moveInfo"></param>
 public static void MoveToEnd(MoveInfo moveInfo, SearchDirection dir)
 {
     while (moveInfo.Current != null &&
            (moveInfo.Current.IsTT(TokenType.Word) || moveInfo.Current.IsTT(TokenType.BackSlash)))
     {
         moveInfo.Move(dir);
     }
 }
Example #8
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);
        }
Example #9
0
 public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
 {
     if (parentInfo.Current.IsTT(TokenType.PreComp))
     {
         MoveInfo moveInfo = new MoveInfo(parentInfo);
         IElement next     = moveInfo.Move(SearchDirection.LeftToRight);
         if (next != null && next.IsTT(TokenType.Word) && next.ToString() == "include")
         {
             Parse(parentInfo, parsingInfo, scriptInfo);
             return(true);
         }
     }
     return(false);
 }
Example #10
0
        public static void ParseRegion(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo        moveInfo = new MoveInfo(parentInfo);
            List <IElement> content  = new List <IElement>();

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

            moveInfo.Move(SearchDirection.LeftToRight);
            int nameStart = moveInfo.CurrentIndex;

            IElement end = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Unvisible, IsRegionEnd);

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

            content.AddRange(moveInfo.CurrentElements.GetRange(nameStart, moveInfo.CurrentIndex - nameStart));

            IBlock region = new PreProcessorRegion(content);

            parentInfo.Replace(moveInfo.CurrentIndex - parentInfo.CurrentIndex, region);
        }
Example #11
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);
        }
Example #12
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            PreProcessorInclude include = new PreProcessorInclude();
            int startIndex = parentInfo.CurrentIndex;

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.Move(SearchDirection.LeftToRight); // "include"
            moveInfo.Move(SearchDirection.LeftToRight); // after "include"
            moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

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

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

            include.Path = path;

            moveInfo.Move(SearchDirection.LeftToRight);
            IElement terminal = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

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


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

            include.AddChildren(children);
            parentInfo.Replace(length, include);

            // include file
            string SFPath = path.ToString();

            if (scriptInfo.Includes.Find(a => a.SFPath.EqualCode(SFPath)) != null)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("File '" + SFPath + "' already included",
                                      parentInfo.GetErrorInfo(include)));
            }

            ScriptFile includeFile = scriptInfo.SF.Manager.GetSF(SFPath);

            if (includeFile != null)
            {
                IncludeInfo includeInfo = new IncludeInfo(includeFile);
                scriptInfo.AddInclude(includeInfo);

                parsingInfo.IncludeDefList.Add(include);
            }
            else
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Could not include file '" + SFPath + "'",
                                      parentInfo.GetErrorInfo(include)));
            }
        }
Example #13
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;
        }