Beispiel #1
0
        public override IElement CreateCopy()
        {
            FuncDefParam e = new FuncDefParam();

            e.AddChildren(this.CopyChildren());
            e.Name     = Name;
            e.Optional = Optional;

            if (_group != null)
            {
                e._group  = (SQBracketGroup)e.children[this.children.IndexOf(_group)];
                e.VarName = (VarName)e._group.GetChildren()[this._group.GetChildren().IndexOf(VarName)];
            }
            else
            {
                e.VarName = (VarName)e.children[this.children.IndexOf(VarName)];
            }

            return(e);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private static List <FuncDefParam> GetParameterList(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo            moveInfo  = new MoveInfo(parentInfo);
            string              error     = "Could not parse function parameters";
            List <FuncDefParam> defParams = new List <FuncDefParam>();

            bool?    isSeparator = null;
            IElement curElem     = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            while (curElem != null)
            {
                if (isSeparator == false || isSeparator == null)
                {
                    FuncDefParam param = FuncDefParam.Parse(moveInfo, parsingInfo, scriptInfo);
                    defParams.Add(param);
                    isSeparator = true;
                }
                else
                {
                    if (!curElem.IsTT(TokenType.Comma))
                    {
                        throw new SyntaxException(error, parentInfo.GetErrorInfo());
                    }

                    isSeparator = false;
                }
                curElem = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            }

            if (isSeparator == false)
            {
                throw new SyntaxException(error, parentInfo.GetErrorInfo());
            }

            return(defParams);
        }
Beispiel #4
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);
        }