Example #1
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 #2
0
        public override IElement CreateCopy()
        {
            XMLBlock e = new XMLBlock(this.CopyChildren());

            return(e);
        }
Example #3
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;
            //}
        }
Example #4
0
        private static ConstInfo GetInfo(string name, MemberAccess access, Expression value, bool isSealed, XMLBlock xml, ParsingInfo parsingInfo, ConstDef constDef)
        {
            string summary = string.Empty;

            if (xml != null)
            {
                string str = xml.GetStringContent();
                if (str.Length > 0 && str[0] != '<')
                {
                    summary = str;
                }
                else
                {
                    str = "<root>" + str + "</root>";
                    XmlDocument doc = new XmlDocument();
                    try
                    {
                        doc.LoadXml(str);

                        foreach (XmlNode n in doc.ChildNodes[0].ChildNodes)
                        {
                            if (n.Name == "summary")
                            {
                                summary = n.InnerText;
                            }
                        }
                    }
                    catch
                    {
                        summary = "Could not parse XML.";
                    }
                }
            }
            return(new ConstInfo(parsingInfo.SF, name, value.ToString().Replace("\r", "").Replace("\n", ""),
                                 value, access, summary, isSealed, constDef));
        }
Example #5
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;
        }
Example #6
0
        private static FuncInfo GetInfo(string name, MemberAccess access, List <FuncDefParam> defParams, XMLBlock xml, ParsingInfo parsingInfo, FuncDef funcDef)
        {
            string summary = string.Empty;
            string returns = string.Empty;
            string self    = string.Empty;
            string example = string.Empty;
            List <FuncParamInfo> xmlParams = new List <FuncParamInfo>();

            if (xml != null)
            {
                string str = xml.GetStringContent();
                if (str.Length > 0 && str[0] != '<')
                {
                    summary = str;
                }
                else
                {
                    str = "<root>" + str + "</root>";
                    XmlDocument doc = new XmlDocument();
                    try
                    {
                        doc.LoadXml(str);

                        foreach (XmlNode n in doc.ChildNodes[0].ChildNodes)
                        {
                            XmlElement e = (XmlElement)n;
                            if (e.Name == "summary")
                            {
                                summary = e.InnerText.Trim();
                            }
                            else if (e.Name == "returns")
                            {
                                returns = e.InnerText.Trim();
                            }
                            else if (e.Name == "self")
                            {
                                self = e.InnerText.Trim();
                            }
                            else if (e.Name == "example")
                            {
                                example = e.InnerText.Trim();
                            }
                            else if (e.Name == "param")
                            {
                                string paramName = e.GetAttribute("name");

                                if (!String.IsNullOrEmpty(paramName))
                                {
                                    FuncDefParam defParam = defParams.Find(a => a.Name.EqualCode(paramName));
                                    xmlParams.Add(new FuncParamInfo(paramName, e.InnerText.Trim(), false, defParam.Optional));
                                }
                            }
                        }
                    }
                    catch
                    {
                        summary = "Could not parse XML.";
                    }
                }
            }

            FuncInfo funcInfo = new FuncInfo(parsingInfo.SF, name, access, summary, returns, self, example, funcDef);

            bool anyOptional = false;

            foreach (FuncDefParam param in defParams)
            {
                if (param.Optional)
                {
                    anyOptional = true;
                }

                FuncParamInfo paramInfo = xmlParams.Find(a => a.Name.EqualCode(param.Name));
                if (paramInfo == null)
                {
                    paramInfo = new FuncParamInfo(param.Name, "", false, anyOptional);
                }
                else
                {
                    paramInfo.IsOpt = anyOptional; // update in FuncParamInfos from XML
                }
                funcInfo.AddParam(paramInfo);
            }
            return(funcInfo);
        }