Ejemplo n.º 1
0
        private static PreParsedElement TryParseEnum(IList <string> lines, int index, out int end)
        {
            end = index + 1;
            var text  = lines[index].Trim();
            var parts = text.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length == 0)
            {
                return(null);
            }

            var name   = parts[0];
            var coment = string.Empty;

            if (parts.Length > 1)
            {
                coment = string.Join(" ", parts.Skip(2)).TrimStart(' ', '/', '<');
            }

            var field = new PreParsedElement
            {
                Name    = ToTitleCase(name),
                CppName = name,
                Comment = coment
            };

            return(field);
        }
Ejemplo n.º 2
0
        protected override PreParsedElement TryParseElement(PreParsedElement preParsedElement, string templateName)
        {
            var test = preParsedElement.CppText;

            if (!FuncRegex.IsMatch(test))// || VoidFuncRegex.IsMatch(test))
            {
                return(null);
            }

            var cppTypeMatch = FuncTypeRegex.Match(test);

            if (!cppTypeMatch.Success)
            {
                return(null);
            }

            var nameMatch = FuncNameRegex.Match(test);

            if (!nameMatch.Success)
            {
                return(null);
            }

            var paramsMatch = ParamsRegex.Match(test);

            if (!paramsMatch.Success)
            {
                return(null);
            }


            try
            {
                var field = new ParsedFunc();
                field.Type        = GetKnownTypeOrDefault(cppTypeMatch.Value, templateName);
                field.Name        = CashParser.ToTitleCase(nameMatch.Value);
                field.CppName     = nameMatch.Value;
                field.Params      = TryParseParams(paramsMatch.Value);
                field.Comment     = preParsedElement.Comment;
                field.MainComment = preParsedElement.MainComment;
                return(field);
            }
            catch (Exception e)
            {
            }

            var error = new ParsedFunc();

            error.Comment = "Parsing error: { preParsedElement.CppText}";
            return(error);
        }
Ejemplo n.º 3
0
        private void PrintParsedElements(StringBuilder sb, ParsedClass parsedClass, PreParsedElement parsedElement, int indentCount, string templateName)
        {
            var indent = new string(' ', indentCount);

            sb.AppendLine();

            if (!string.IsNullOrEmpty(parsedElement.MainComment))
            {
                sb.AppendLine(parsedElement.MainComment);
            }

            var comment = parsedElement.Comment ?? string.Empty;

            //comment = comment.Replace("\\", $@"/// {Environment.NewLine}");

            sb.AppendLine($"{indent}/// <summary>");
            sb.AppendLine($"{indent}/// API name: {parsedElement.CppName}");
            sb.AppendLine($"{indent}/// {TypeCorrection(comment)}");
            sb.AppendLine($"{indent}/// </summary>");

            var parsedFunc = parsedElement as ParsedFunc;

            if (parsedFunc != null)
            {
                foreach (var itm in parsedFunc.Params)
                {
                    sb.AppendLine($"{indent}/// <param name=\"{itm.Name}\">API type: {TypeCorrection(itm.CppType)}</param>");
                }
                if (parsedClass.ObjectType == ObjectType.Api)
                {
                    sb.AppendLine($"{indent}/// <param name=\"token\">Throws a <see cref=\"T:System.OperationCanceledException\" /> if this token has had cancellation requested.</param>");
                }
            }

            if (!string.IsNullOrEmpty(parsedElement.Type?.CppName))
            {
                sb.AppendLine($"{indent}/// <returns>API type: {TypeCorrection(parsedElement.Type.CppName)}</returns>");
            }

            if (parsedClass.ObjectType == ObjectType.Api)
            {
                sb.AppendLine($"{indent}/// <exception cref=\"T:System.OperationCanceledException\">The token has had cancellation requested.</exception>");
            }

            var type = GetTypeForPrint(parsedElement.Type, templateName);

            if (parsedFunc != null)
            {
                sb.AppendLine($"{indent}public JsonRpcResponse{(type.Equals("void", StringComparison.OrdinalIgnoreCase) ? string.Empty : $"<{type}>")} {parsedElement.Name}({string.Join(", ", parsedFunc.Params)}{(parsedClass.ObjectType == ObjectType.Api ? $"{(parsedFunc.Params.Any() ? ", " : string.Empty)}CancellationToken token" : string.Empty)})");
Ejemplo n.º 4
0
 protected abstract PreParsedElement TryParseElement(PreParsedElement preParsedElement, string templateName);
Ejemplo n.º 5
0
        protected override PreParsedElement TryParseElement(PreParsedElement preParsedElement, string templateName)
        {
            var test = preParsedElement.CppText;

            if (string.IsNullOrEmpty(test))
            {
                return(null);
            }

            if (test.StartsWith("static "))
            {
                test = test.Remove(0, 7);
            }
            if (test.StartsWith("const "))
            {
                test = test.Remove(0, 6);
            }

            if (!_fieldRules.IsMatch(test))
            {
                return(null);
            }

            var parts = test.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length < 2)
            {
                return(null);
            }

            var cppType = parts[0];

            if (_notTypeChar.IsMatch(cppType))
            {
                return(null);
            }

            var name = parts[1].Trim(' ', ';');

            if (NotNameChar.IsMatch(name))
            {
                return(null);
            }

            var coment = string.Empty;

            if (parts.Length > 2)
            {
                coment = string.Join(" ", parts.Skip(2)).TrimStart(' ', '/', '<');
            }

            var field = new PreParsedElement
            {
                Type        = GetKnownTypeOrDefault(cppType, templateName),
                Name        = CashParser.ToTitleCase(name),
                CppName     = name,
                Comment     = coment,
                MainComment = preParsedElement.MainComment
            };

            return(field);
        }
Ejemplo n.º 6
0
        private void PrintParsedElements(StringBuilder sb, ParsedClass parsedClass, PreParsedElement parsedElement, int indentCount, string templateName)
        {
            var indent = new string(' ', indentCount);

            sb.AppendLine();

            Comment briefComment = null;
            var     parsedFunc   = parsedElement as ParsedFunc;

            if (parsedFunc != null)
            {
                briefComment = Comment.TryParseMainComment(parsedFunc.MainComment);
                if (briefComment != null && !briefComment.IsEmpty())
                {
                    parsedFunc.MainComment = Comment.RemoveBriefFromMainComment(parsedFunc.MainComment);
                }
            }

            if (!string.IsNullOrEmpty(parsedElement.MainComment))
            {
                sb.Append(indent);
                sb.AppendLine(parsedElement.MainComment);
                sb.AppendLine();
            }

            var comment = parsedElement.Comment ?? string.Empty;

            //comment = comment.Replace("\\", $@"/// {Environment.NewLine}");

            sb.AppendLine($"{indent}/// <summary>");
            sb.AppendLine($"{indent}/// API name: {parsedElement.CppName}");
            if (!string.IsNullOrWhiteSpace(briefComment?.Brief))
            {
                sb.AppendLine($"{indent}/// {briefComment.Brief.Replace(Environment.NewLine, $"{Environment.NewLine}{indent}/// ")}");
                sb.AppendLine($"{indent}///");
            }
            if (parsedClass.ObjectType == ObjectType.Api && !string.IsNullOrWhiteSpace(parsedElement.CppName) && MethodDescriptions.ContainsKey(parsedElement.CppName))
            {
                var text = MethodDescriptions[parsedElement.CppName];
                if (!string.IsNullOrWhiteSpace(text) && (briefComment == null || !briefComment.IsBriefContainText(text)))
                {
                    sb.AppendLine($"{indent}/// *{text.Trim()}");
                }
            }
            sb.AppendLine($"{indent}/// {TypeCorrection(comment)}");
            sb.AppendLine($"{indent}/// </summary>");

            if (parsedFunc != null)
            {
                foreach (var itm in parsedFunc.Params)
                {
                    sb.Append($"{indent}/// <param name=\"{itm.Name}\">API type: {TypeCorrection(itm.CppType)}");

                    if (briefComment != null && briefComment.Params.ContainsKey(itm.CppName))
                    {
                        sb.Append(briefComment.Params[itm.CppName].Replace(Environment.NewLine, $"{Environment.NewLine}{indent}/// "));
                    }

                    sb.AppendLine("</param>");
                }

                if (parsedClass.ObjectType == ObjectType.Api)
                {
                    sb.AppendLine($"{indent}/// <param name=\"token\">Throws a <see cref=\"T:System.OperationCanceledException\" /> if this token has had cancellation requested.</param>");
                }
            }

            if (!string.IsNullOrWhiteSpace(briefComment?.Return) || !string.IsNullOrEmpty(parsedElement.Type?.CppName))
            {
                sb.Append($"{indent}/// <returns>");
                if (!string.IsNullOrEmpty(parsedElement.Type?.CppName))
                {
                    sb.Append($"API type: {TypeCorrection(parsedElement.Type.CppName)}");
                    if (!string.IsNullOrWhiteSpace(briefComment?.Return))
                    {
                        sb.Append(" ");
                    }
                }

                if (!string.IsNullOrWhiteSpace(briefComment?.Return))
                {
                    sb.Append($"{briefComment.Return.Replace(Environment.NewLine, $"{Environment.NewLine}{indent}/// ")}");
                }
                sb.AppendLine("</returns>");
            }


            if (parsedClass.ObjectType == ObjectType.Api)
            {
                sb.AppendLine($"{indent}/// <exception cref=\"T:System.OperationCanceledException\">The token has had cancellation requested.</exception>");
            }

            var type = GetTypeForPrint(parsedElement.Type, templateName);

            if (parsedFunc != null)
            {
                sb.AppendLine($"{indent}public JsonRpcResponse{(type.Equals("void", StringComparison.OrdinalIgnoreCase) ? string.Empty : $"<{type}>")} {parsedElement.Name}({string.Join(", ", parsedFunc.Params)}{(parsedClass.ObjectType == ObjectType.Api ? $"{(parsedFunc.Params.Any() ? ", " : string.Empty)}CancellationToken token" : string.Empty)})");