public void ParseFile(StreamReader stream, PySection _main) { // _t = File.OpenText(filename); StringCollection coll = new StringCollection(); while (!stream.EndOfStream) { coll.Add(stream.ReadLine()); } ParseFileSection(coll, _main, 0, coll.Count); }
public int ParseFileSection(StringCollection sec, PySection section, int begin, int end) { // sec collection, doesn't contain # --- begin / # --- end int count = begin; for (int j=begin; j<end; j++) { string item = sec[j]; if (item.Contains("# begin")) { // here's we have a new section string trimstr = item.Trim(); string nn = trimstr.Substring(7); section.Children.Add(new PySection(nn.Trim())); PySection child = (PySection)section.Children[section.Children.Count - 1]; child.Begin = count; // find the end... string ends = item.Replace("begin", "end"); int end_idx = sec.IndexOf(ends); if ((end_idx >= begin) || (end_idx <= end)) { child.Size = end_idx - child.Begin - 1; ParseFileSection(sec, child, count + 1, end_idx); j = end_idx; count = end_idx; } else { // Not found error... } } else if (item.Contains("# end")) { // DO NOTHING } else { section.Lines.Add(item); } count++; } return count; }
public PyClassFile(string name) { _name = name; _base_class_section = new PySection(name + "_base_class"); _class_section = new PySection(name + "_class"); }
protected void CreateEmptyApp() { _app_file = new PySection("application"); Assembly a = Assembly.GetExecutingAssembly(); StreamReader str = new StreamReader(a.GetManifestResourceStream("mkdb.Python.app_template.py")); _parser.ParseFile(str, _app_file); }
public void Render(StringCollection box, PySection _main) { RenderSection(box, _main); }
public void ParseFile(string filename, PySection _main) { _t = File.OpenText(filename); ParseFile(_t, _main); }
public void RenderSection(StringCollection box, PySection section) { if (section.Name != "") { string str = "# begin " + section.Name + "\n"; InsertToPos(box, section.Begin, str); } if (section.Children.Count == 0) { int cnt = 1; foreach (string it in section.Lines) { InsertToPos(box, section.Begin + cnt, it + "\n"); cnt++; } } else { int cnt = 1; foreach (string it in section.Lines) { InsertToPos(box, section.Begin + cnt, it + "\n"); cnt++; } foreach (PySection sec in section.Children) { RenderSection(box, sec); } } if (section.Name != "") { InsertToPos(box, section.End, "# end " + section.Name + "\n"); } }
public void AddSection(PySection sec) { _children.Add(sec); Size += sec.Size; }
public void RemSection(PySection sec) { _children.Remove(sec); Size -= sec.Size; }