NamespaceInfo GetOrCreateNamespace(string name) { NamespaceInfo ns; if (!_namespaces.TryGetValue(name, out ns)) { ns = new NamespaceInfo(name); AddNamespace(ns); } return(ns); }
void AddNamespace(NamespaceInfo ns) { // Find the parent namespace int dotPos = ns.Name.LastIndexOf('.'); if (dotPos > 0) { ns.Parent = GetOrCreateNamespace(ns.Name.Substring(0, dotPos)); ns.Parent.Children.Add(ns.NestedName, ns); } _namespaces.Add(ns.Name, ns); }
void ParseNamespace(string outerNamespace) { p.SkipWhitespaceAndComments(); // Parse the name of the namespace string name = outerNamespace; while (true) { if (!string.IsNullOrEmpty(name)) { name += "."; } name += p.SkipIdentifier(); if (p[0] == '.') { p.pos++; continue; } break; } // Find/create the namespace info NamespaceInfo ns = null; if (!_namespaces.TryGetValue(name, out ns)) { ns = new NamespaceInfo(name); AddNamespace(ns); } // Skip the opening brace p.SkipWhitespaceAndComments(); p.Skip("{"); p.SkipLineSpace(); p.SkipEOL(); int startPos = p.pos; int braceDepth = 0; while (true) { int currentPos = p.pos; p.SkipWhitespaceAndComments(); if (p.SkipString()) { continue; } // Nested whitespace? if (p.SkipMatchOptional("namespace")) { if (braceDepth == 0) { throw new BuildException("Unexpected 'namespace' keyword inside bracing"); } ns.StartSection(_currentFile); ns.Code.Append(p.code.Substring(startPos, currentPos - startPos)); ParseNamespace(name); startPos = p.pos; continue; } // Opening brace? if (p[0] == '{') { braceDepth++; p.pos++; continue; } // Closing brace? if (p[0] == '}') { if (braceDepth == 0) { break; } braceDepth--; p.pos++; continue; } if (p[0] == '\0') { throw new BuildException("Unterminated namespace block"); } // Anything else just skip it p.pos++; } ns.StartSection(_currentFile); ns.Code.Append(p.code.Substring(startPos, p.pos - startPos)); p.Skip("}"); p.SkipWhitespaceAndComments(); }
void ParseNamespace(string outerNamespace) { p.SkipWhitespaceAndComments(); // Parse the name of the namespace string name = outerNamespace; while (true) { if (!string.IsNullOrEmpty(name)) name += "."; name += p.SkipIdentifier(); if (p[0] == '.') { p.pos++; continue; } break; } // Find/create the namespace info NamespaceInfo ns = null; if (!_namespaces.TryGetValue(name, out ns)) { ns = new NamespaceInfo(name); AddNamespace(ns); } // Skip the opening brace p.SkipWhitespaceAndComments(); p.Skip("{"); p.SkipLineSpace(); p.SkipEOL(); int startPos = p.pos; int braceDepth = 0; while (true) { int currentPos = p.pos; p.SkipWhitespaceAndComments(); if (p.SkipString()) continue; // Nested whitespace? if (p.SkipMatchOptional("namespace")) { if (braceDepth == 0) throw new BuildException("Unexpected 'namespace' keyword inside bracing"); ns.StartSection(_currentFile); ns.Code.Append(p.code.Substring(startPos, currentPos-startPos)); ParseNamespace(name); startPos = p.pos; continue; } // Opening brace? if (p[0] == '{') { braceDepth++; p.pos++; continue; } // Closing brace? if (p[0] == '}') { if (braceDepth == 0) break; braceDepth--; p.pos++; continue; } if (p[0] == '\0') throw new BuildException("Unterminated namespace block"); // Anything else just skip it p.pos++; } ns.StartSection(_currentFile); ns.Code.Append(p.code.Substring(startPos, p.pos - startPos)); p.Skip("}"); p.SkipWhitespaceAndComments(); }
NamespaceInfo GetOrCreateNamespace(string name) { NamespaceInfo ns; if (!_namespaces.TryGetValue(name, out ns)) { ns = new NamespaceInfo(name); AddNamespace(ns); } return ns; }