Ejemplo n.º 1
0
        static String[] ObtainExamples()
        {
            var parser  = new Parser();
            var doc     = Documentation.Create(parser.Context);
            var queries = new List <String>();

            foreach (var section in doc.Sections)
            {
                if (section is HelpFunctionSection)
                {
                    var f = (HelpFunctionSection)section;

                    foreach (var usage in f.Usages)
                    {
                        foreach (var example in usage.Examples)
                        {
                            if (!example.IsFile)
                            {
                                queries.Add(example.Example);
                            }
                        }
                    }
                }
            }

            return(queries.ToArray());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a new root class.
        /// </summary>
        /// <param name="cls">The entity, known to be a class.</param>
        /// <param name="unit">The <see cref="Unit"/> target of the loading.</param>
        /// <param name="rootEntities">The classes in the <see cref="Unit"/>.</param>
        /// <param name="allEntities">All entities in the <see cref="Unit"/>.</param>
        void AddRootClass(Entity cls,
                          Unit unit,
                          ISet <Entity> rootEntities,
                          IDictionary <Id, Entity> allEntities)
        {
            if (cls.Id.Path.Length == 1)
            {
                rootEntities.Add(cls);
            }
            else
            {
                // Is the class in a namespace ?
                Id parentId = cls.Id;

                do
                {
                    parentId = parentId.Parent;

                    if (!allEntities.TryGetValue(parentId, out Entity entity))
                    {
                        parentId.Type = Id.AType.Namespace;

                        var doc      = Documentation.Create(parentId);
                        var nsEntity = new Entity(unit)
                        {
                            Docs = doc
                        };

                        rootEntities.Add(nsEntity);
                    }
                } while(parentId.Path.Length > 1);
            }

            return;
        }
Ejemplo n.º 3
0
        HelpPrinter(IFormatter formatter)
        {
            this.formatter = formatter;
            var parser = new Parser();

            parser.LoadPlugin(typeof(UnitValue).Assembly);
            doc = Documentation.Create(parser.Context);
        }
Ejemplo n.º 4
0
        public void Load(IApiProvider provider)
        {
            provider.RegisterApi(_parser.Context);
            LoadPlugins();
            _documentation = Documentation.Create(Context);

            Environment.CurrentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            ExecuteGlobalScript();
            ExecuteLocalScript();

            _parser.InteractiveMode = true;
        }
        public StringValue Function(StringValue topic)
        {
            var docu = Documentation.Create(Context);

            if (docu.ContainsEntry(topic.Value))
            {
                var entry = docu.Get(topic.Value);
                var sb    = new StringBuilder();

                sb.Append(" ").AppendLine(entry.Name).AppendLine("--------------");

                sb.AppendLine().AppendLine("Description:").Append("\t").AppendLine(entry.Description);

                if (entry is HelpFunctionSection)
                {
                    var fe = entry as HelpFunctionSection;

                    foreach (var usage in fe.Usages)
                    {
                        var i = 1;
                        sb.AppendLine();
                        sb.AppendLine("** Usage **").Append("\t").AppendLine(usage.Usage);
                        sb.AppendLine("** Description **").Append("\t").AppendLine(usage.Description);
                        sb.AppendLine("** Arguments **").Append("\t").AppendLine(string.Join(", ", usage.Arguments.ToArray()));
                        sb.AppendLine("** Returns **");

                        foreach (var ret in usage.Returns)
                        {
                            sb.Append("\t").AppendLine(ret);
                        }

                        foreach (var example in usage.Examples)
                        {
                            sb.AppendFormat(" ({0}) Example:", i).AppendLine();
                            sb.Append("\t").Append("-> Call: ").AppendLine(example.Example);
                            sb.Append("\t").Append("-> Description: ").AppendLine(example.Description);
                            i++;
                        }
                    }
                }

                return(new StringValue(sb.ToString()));
            }
            else
            {
                return(new StringValue(String.Format("The specified entry was not found. Did you mean {0}?", docu.ClosestEntry(topic.Value))));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads the given XML documentation.
        /// </summary>
        /// <param name="unit">The <see cref="Unit"/> target of the loading.</param>
        /// <param name="xmlRoot">The XElement root of the info.</param>
        /// <param name="rootEntities">The classes in the <see cref="Unit"/>.</param>
        /// <param name="allEntities">All entities in the <see cref="Unit"/>.</param>
        public void LoadXmlElementsFrom(Unit unit,
                                        XElement xmlRoot,
                                        ISet <Entity> rootEntities,
                                        IDictionary <Id, Entity> allEntities)
        {
            IEnumerable <XElement> members =
                xmlRoot.Element("members").Elements("member");

            // Load entities with their associated documentation
            foreach (XElement member in members)
            {
                string name = (string)member.Attribute("name");

                // Load the documentation from the (flat) XML
                var xmlDoc = Documentation.Create(name, member);

                // Create the associated entity and store it
                var entity = new Entity(unit)
                {
                    Docs = xmlDoc
                };

                try {
                    allEntities.Add(entity.Id, entity);
                } catch (System.ArgumentException) {
                    string errorMsg = "Entity: " + entity
                                      + "\n\n\tis duplicated in the docs:\n"
                                      + "\n\t" + allEntities[entity.Id];
                    throw new System.ArgumentException(errorMsg);
                }
            }

            // Organize entities in the unit's structure
            this.FindRootClasses(unit, rootEntities, allEntities);
            this.Matrioska(allEntities);
        }
Ejemplo n.º 7
0
        static void TestExamples()
        {
            success = 0;
            total   = 0;
            var sw = Stopwatch.StartNew();

            var doc = Documentation.Create(Parser.PrimaryContext);

            Console.WriteLine();

            foreach (var section in doc.Sections)
            {
                if (section is HelpFunctionSection)
                {
                    var f = (HelpFunctionSection)section;

                    foreach (var usage in f.Usages)
                    {
                        foreach (var example in usage.Examples)
                        {
                            if (example.IsFile)
                            {
                                continue;
                            }

                            total++;

                            try
                            {
                                var parser = YAMP.Parser.Parse(example.Example);
                                parser.Execute();
                                success++;
                            }
                            catch (Exception ex)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("Caution:");
                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.WriteLine(ex.Message);
                                Console.ResetColor();
                                Console.WriteLine("At example: " + example.Example);
                                Console.Write("For usage: " + usage.Usage);
                                Console.WriteLine("In function: " + f.Name);
                                Console.WriteLine();
                            }

                            if (total % 20 == 0)
                            {
                                Console.WriteLine("{0} elements have been processed . . .", total);
                            }
                        }
                    }
                }
            }

            sw.Stop();

            Console.WriteLine();
            Console.WriteLine("{0} / {1} tests completed successfully ({2} %)", success, total, success * 100 / total);
            Console.WriteLine("Time for the tests ... {0} ms", sw.ElapsedMilliseconds);
        }