internal protected override SmarterStringBuilder Build(SmarterStringBuilder b, bool closeScope) { if (_fDef != null) { if (b.Builder != null) { _fDef.Write(b.Builder); } else { b.Append(_fDef.ToString()); } b.HasNewLine = false; } bool lambda = CodePart.StartsWith("=>") == true; if (!lambda) { b.AppendLine().Append("{").AppendLine(); } CodePart.Build(b); _funcs.Build(b); if (closeScope && !lambda) { b.AppendLine().Append("}"); } return(b); }
protected SmarterStringBuilder BuildTypes(SmarterStringBuilder b) { foreach (var t in _types.Values) { t.Build(b, true); } return(b); }
public SmarterStringBuilder Build(SmarterStringBuilder b) { foreach (var t in _funcs.Values) { t.Build(b, true); } return(b); }
internal void Initialize() { var b = new SmarterStringBuilder(new StringBuilder()); // We store the declaration and clears the code buffer. var declaration = CodePart.Build(b).ToString(); CodePart.Parts.Clear(); _fDef = FunctionDefinition.Parse(declaration, out string?bodyStart); if (bodyStart != null) { CodePart.Parts.Add(bodyStart); } SetName(_fDef.Key); }
private void WriteThisUsings(SmarterStringBuilder b) { foreach (var e in _usings) { b.AppendLine().Append("using ").Append(e.Key); if (e.Value.Value == null) { b.Append(";"); } else { b.Append(" = ").Append(e.Value.Value); } b.AppendLine(); } }
internal SmarterStringBuilder Build(SmarterStringBuilder b) { b.AppendLine(); foreach (var c in Parts) { if (c is BaseCodePart p) { p.Build(b); } else { b.Append((string)c); } } b.AppendLine(); return(b); }
/// <summary> /// Extracts the name. /// The declaration itself is updated as one string and the scope opener is injected if needed. /// </summary> internal void Initialize() { var b = new SmarterStringBuilder(new StringBuilder()); // We store the declaration and clears the code buffer. var declaration = CodePart.Build(b).ToString(); CodePart.Parts.Clear(); var m = declaration.AsSpan(); m.SkipWhiteSpacesAndJSComments(); if (!m.MatchTypeDefinition(out var typeDef, IsNestedType, out bool hasCodeOpener)) { Throw.InvalidOperationException($"Error: Unable to parse type declaration '{declaration}'."); } _typeDef = typeDef; if (hasCodeOpener) { CodePart.Parts.Add(declaration.Substring(declaration.Length - m.Length)); } SetName(_typeDef.Name.ToString()); }
internal protected override SmarterStringBuilder Build(SmarterStringBuilder b, bool closeScope) { _beforeNamespace.Build(b); // A global using prevent any attribute definition (and [assembly::...] attributes cannot be defined // in a namespace. // We write the global usings in the TOP namespaces: they are duplicated among the top-level namespaces // but this enables to define attributes at the top of one file. if (Workspace.Global != this) { b.Append("namespace ") .Append(Name) .AppendLine() .Append("{") .AppendLine(); if (Parent == Workspace.Global) { Parent.WriteThisUsings(b); } WriteThisUsings(b); } else if (_subNamespaces.Count == 0) { // However, if there is no namespace defined, the global // usings must be written. We have no choice. WriteThisUsings(b); } CodePart.Build(b); foreach (var ns in _subNamespaces) { ns.Build(b, true); } BuildTypes(b); if (Workspace.Global != this && closeScope) { b.AppendLine().Append("}"); } return(b); }
internal protected override SmarterStringBuilder Build(SmarterStringBuilder b, bool closeScope) { if (_typeDef != null) { if (b.Builder != null) { _typeDef.Write(b.Builder); } else { b.Append(_typeDef.ToString()); } b.HasNewLine = false; } b.AppendLine().Append("{").AppendLine(); CodePart.Build(b); _funcs.Build(b); BuildTypes(b); if (closeScope) { b.AppendLine().Append("}").AppendLine(); } return(b); }
internal protected abstract SmarterStringBuilder Build(SmarterStringBuilder b, bool closeScope);