Example #1
0
        protected override void OnRun()
        {
            var argOut = CmdLine.Property("out", Path.Combine(Environment.CurrentDirectory, "functions.md"));

            using (var writer = new StreamWriter(argOut))
            {
                writer.Write("# Function reference\n\n");

                foreach (var group in RantUtils.GetFunctions().OrderBy(g => g.Name))
                {
                    writer.Write($"## {group.Name}\n\n");

                    var aliases = RantUtils.GetFunctionAliases(group.Name).Where(a => a != group.Name).ToArray();

                    if (aliases.Length > 0)
                    {
                        writer.Write($"**Aliases:** {aliases.Select(a => $"`{a}`").Aggregate((c, n) => c + ", " + n)}<br/>");
                    }
                    writer.Write($"**Overloads:** {group.Overloads.Count()}\n\n");

                    foreach (var func in group.Overloads.OrderBy(f => f.ParamCount))
                    {
                        writer.Write($"### {func}\n\n");
                        writer.Write(func.Description);

                        var fparams = func.GetParameters().ToArray();

                        if (fparams.Length > 0)
                        {
                            writer.Write("\n\n**Parameters**\n\n|Name|Type|Description|\n|---|---|---|\n");

                            foreach (var p in fparams)
                            {
                                if (p.RantType == RantFunctionParameterType.Mode || p.RantType == RantFunctionParameterType.Flags)
                                {
                                    var sb = new StringBuilder();
                                    sb.Append("<ul>");
                                    foreach (var mode in p.GetEnumValues())
                                    {
                                        sb.Append($"<li><b>{mode.Name}</b><br/>{mode.Description}</li>");
                                    }
                                    sb.Append("</ul>");
                                    writer.Write($"|{p.Name + (p.IsParams ? "..." : "")}|{p.RantType}|{(String.IsNullOrEmpty(p.Description) ? sb.ToString() : p.Description + "<br/><br/>" + sb.ToString())}|\n");
                                }
                                else
                                {
                                    writer.Write($"|{p.Name + (p.IsParams ? "..." : "")}|{p.RantType}|{(String.IsNullOrEmpty(p.Description) ? "*No description*" : p.Description)}|\n");
                                }
                            }
                        }

                        writer.Write("\n***\n");
                    }
                }
            }
        }
Example #2
0
 public void FunctionExists()
 {
     Assert.IsTrue(RantUtils.FunctionExists("rep"));             // Inherited function name
     Assert.IsTrue(RantUtils.FunctionExists("r"));               // Alias
 }
Example #3
0
 public void FunctionDescription()
 {
     Assert.AreEqual("Sets the repetition count for the next block.", RantUtils.GetFunctionDescription("rep", 1));
 }
Example #4
0
        private IEnumerator <Parser> ParseFunction(RantCompiler compiler, CompileContext context, TokenReader reader,
                                                   Action <RST> actionCallback)
        {
            var functionName = reader.Read(R.Text, "acc-function-name");

            var arguments = new List <RST>();

            if (reader.PeekType() == R.Colon)
            {
                reader.ReadToken();

                var iterator = ReadArguments(compiler, reader, arguments);
                while (iterator.MoveNext())
                {
                    yield return(iterator.Current);
                }

                compiler.SetNextActionCallback(actionCallback);
            }
            else
            {
                reader.Read(R.RightSquare);
            }

            RantFunctionSignature sig = null;

            if (functionName.Value != null)
            {
                if (!RantFunctionRegistry.FunctionExists(functionName.Value))
                {
                    compiler.SyntaxError(functionName, false, "err-compiler-nonexistent-function", functionName.Value, RantUtils.GetClosestFunctionName(functionName.Value));
                    yield break;
                }

                if ((sig = RantFunctionRegistry.GetFunction(functionName.Value, arguments.Count)) == null)
                {
                    compiler.SyntaxError(functionName, false, "err-compiler-nonexistent-overload", functionName.Value, arguments.Count);
                    yield break;
                }

                actionCallback(new RstFunction(functionName.ToLocation(), sig, arguments));
            }
        }