Esempio n. 1
0
        public static bool TryParse(string content, int start, int length, out KirinNode result)
        {
            result = null;
            if (!content.Contains("I learned "))
            {
                return(false);
            }
            var match = FunctionStart.Match(content);

            if (!match.Success)
            {
                return(false);
            }

            string functionName = match.Groups[1].Value;
            var    node         = new KirinFunctionStart(start, length)
            {
                IsMain = content.StartsWith("Today"),
            };

            if (FunctionReturn.Any(kw => functionName.Contains(kw)))
            {
                string keyword      = FunctionReturn.First(kw => functionName.Contains(kw));
                int    keywordIndex = functionName.IndexOf(keyword);
                string subContent   = functionName.Substring(keywordIndex + keyword.Length - 1);
                var    returnType   = FiMHelper.DeclarationType.Determine(subContent, out string sKeyword);

                node.Return = returnType;

                string returnString = keyword.Substring(0, keyword.Length - 1) + sKeyword;
                functionName = functionName.Substring(0, keywordIndex) + functionName.Substring(keywordIndex + returnString.Length);
            }
            if (functionName.Contains(FunctionParam))
            {
                int    keywordIndex = functionName.IndexOf(FunctionParam);
                string subcontent   = functionName.Substring(keywordIndex + FunctionParam.Length);
                node.args = new List <KirinFunctionArgument>();
                foreach (string param in subcontent.Split(new string[] { " and " }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var    returnType = FiMHelper.DeclarationType.Determine(" " + param, out string sKeyword);
                    string paramName  = param.Substring(sKeyword.Length);
                    node.args.Add(
                        new KirinFunctionArgument()
                    {
                        Type = returnType,
                        Name = paramName
                    }
                        );
                }

                functionName = functionName.Substring(0, keywordIndex) +
                               functionName.Substring(keywordIndex + FunctionParam.Length + subcontent.Length);
            }

            node.Name = functionName;

            result = node;
            return(true);
        }
Esempio n. 2
0
 public KirinFunction(KirinFunctionStart startNode, KirinFunctionEnd endNode)
     : base(startNode.Start, (endNode.Start + endNode.Length) - startNode.Start)
 {
     this.Name      = startNode.Name;
     this.Today     = startNode.IsMain;
     this.Arguments = startNode.args;
     this.Returns   = startNode.Return;
 }