Exemplo n.º 1
0
 public PyModule _process()
 {
     PyModule pm = new PyModule();
     pm.Name = this.FileName;
     int i = 0;
     List<string> current_doc = new List<string>();
     while (i < this._lines.Length)
     {
         string line = _lines[i];
         if (line.Trim().Trim('\t').Trim().StartsWith("#"))
         {
             Debug.Print("comment start");
             line = line.Trim().Trim('#').Trim();
             current_doc.Add(line);
         }
         else if (line.Trim().Trim('\t').Trim().StartsWith("def "))
         {
             // a normal function starts here
             PyFunction pf = _processPyFunction(ref i, current_doc);
             if (_inClassDef && pc != null)
             {
                 pc.Methods.Add(pf);
             }
             else
             {
                 pm.Functions.Add(pf);
             }
             current_doc = new List<string>();
         }
         else if (line.StartsWith("class "))
         {
             PyClass pc = _processPyClass(ref i, current_doc);
             current_doc.Clear();
             pm.Classes.Add(pc);
             pc = null;
         }
         else if (line.Trim().Trim('\t').Trim().StartsWith("import "))
         {
             string[] imports = line.Replace("import ", "").Split(',');
             Debug.Print("Dependency found");
             pm.Imports.AddRange(imports);
         }
         else if (line.Trim().Trim('\t').Trim().StartsWith("@"))
         {
             current_doc.Add(line.Trim().Trim('\t').Trim());
             System.Diagnostics.Debug.Print(line);
         }
         else
         {
             if (current_doc.Count == i)
             {
                 pm.Description = string.Join("\n", current_doc.ToArray());
                 pm.RawDocLine = current_doc;
             }
             current_doc.Clear();
         }
         i++;
     }
     return pm;
 }
Exemplo n.º 2
0
 private PyClass _processPyClass(ref int i, List<string> doc)
 {
     Debug.Print("class starts");
     pc = new PyClass();
     pc.RawDocLine = doc;
     _inClassDef = true;
     // **********************
     string header = _lines[i];
     header = header.Replace("class ", "");
     string[] parts = _parseClassHead(header);
     string name = parts[0];
     pc.Name = name;
     pc.BaseClasses = parts[1].Split(',');
     i++;
     int start = i;
     while (i < _lines.Length)
     {
         string line = _lines[i];
         int Indent = _indentLevel(line);
         if (Indent == 0 && line != "\r")
         {
             i--;
             break; // class ends here
         }
         else
         {
             i++;
         }
     }
     string[] _tmp_line = _lines;
     this._lines = new ArraySegment<string>(_lines, start, i - start).ToArray();
     _process();
     this._lines = _tmp_line;
     foreach (string item in doc)
     {
         if (item.StartsWith("@"))
         {
             if (item.StartsWith("@ref"))
             {
                 string[] refernce = _splitRefTag(item);
                 pc.Description += "<a href=\"" + refernce[0] + "\">" + refernce[1] + "</a>";
             }
         }
         else
         {
             pc.Description += item + " ";
         }
     }
     Debug.Print("class ends");
     // **********************
     _inClassDef = false;
     return pc;
 }