public virtual void WriteIndented(string s, int?position = null) { var level = position.HasValue && position.Value == 0 ? this.InitialLevel : this.Level; var indented = new StringBuilder(AbstractEmitterBlock.WriteIndentToString(s, level)); this.WriteIndent(indented, level, 0); this.Write(this.Output, indented.ToString(), position); }
public static string ReplaceInlineArgs(AbstractEmitterBlock block, string inline, Expression[] args) { var emitter = block.Emitter; inline = _formatArg.Replace(inline, delegate(Match m) { int count = emitter.Writers.Count; string key = m.Groups[2].Value; string modifier = m.Groups[1].Success ? m.Groups[4].Value : null; StringBuilder oldSb = emitter.Output; emitter.Output = new StringBuilder(); Expression expr = null; if (Regex.IsMatch(key, "^\\d+$")) { expr = args.Skip(int.Parse(key)).FirstOrDefault(); } else { expr = args.FirstOrDefault(e => e.ToString() == key); } string s = ""; if (expr != null) { var writer = block.SaveWriter(); block.NewWriter(); expr.AcceptVisitor(emitter); s = emitter.Output.ToString(); block.RestoreWriter(writer); if (modifier == "raw") { s = s.Trim('"'); } } block.Write(block.WriteIndentToString(s)); if (emitter.Writers.Count != count) { block.PopWriter(); } string replacement = emitter.Output.ToString(); emitter.Output = oldSb; return(replacement); }); return(inline); }
protected virtual Dictionary <string, string> CombineOutputs() { this.Log.Trace("Combining outputs..."); Dictionary <string, string> result = new Dictionary <string, string>(); bool metaDataWritten = false; var disableAsm = this.AssemblyInfo.Assembly.DisableInitAssembly; foreach (var outputPair in this.Outputs) { var fileName = outputPair.Key; var output = outputPair.Value; this.Log.Trace("File name " + (fileName ?? "")); string extension = Path.GetExtension(fileName); bool isJs = extension == ('.' + Bridge.Translator.AssemblyInfo.JAVASCRIPT_EXTENSION); foreach (var moduleOutput in output.ModuleOutput) { WriteNewLine(output.NonModuletOutput, moduleOutput.Value.ToString()); } var tmp = new StringBuilder(output.TopOutput.Length + output.BottomOutput.Length + output.NonModuletOutput.Length + 100); if (output.TopOutput.Length > 0) { tmp.Append(output.TopOutput.ToString()); tmp.Append("\n"); } if (output.NonModuletOutput.Length > 0) { if (isJs) { if (!disableAsm) { tmp.Append("Bridge.initAssembly("); string asmName = this.AssemblyInfo.Assembly.FullName ?? this.Translator.AssemblyName; if (!string.IsNullOrEmpty(asmName)) { tmp.Append("\""); tmp.Append(asmName); tmp.Append("\""); } else { tmp.Append("null"); } tmp.Append(", "); if (!metaDataWritten && (this.MetaDataOutputName == null || fileName == this.MetaDataOutputName)) { var res = this.GetIncludedResources(); if (res != null) { tmp.Append(res); tmp.Append(", "); } metaDataWritten = true; } tmp.Append("function ($asm, globals) {"); tmp.Append("\n"); tmp.Append(" "); tmp.Append(this.GetOutputHeader()); tmp.Append("\n"); } } var afterOutput = (isJs && !disableAsm ? "\nBridge.init();" : ""); var code = output.NonModuletOutput.ToString() + afterOutput; if (isJs) { code = " " + AbstractEmitterBlock.WriteIndentToString(code, 1); } tmp.Append(code); if (isJs && !disableAsm) { tmp.Append("\n"); tmp.Append("});"); tmp.Append("\n"); } } if (output.BottomOutput.Length > 0) { tmp.Append("\n"); tmp.Append(output.BottomOutput.ToString()); } result.Add(fileName, tmp.ToString()); } this.Log.Trace("Combining outputs done"); return(result); }
protected virtual Dictionary <string, string> CombineOutputs() { this.Log.Trace("Combining outputs..."); Dictionary <string, string> result = new Dictionary <string, string>(); foreach (var outputPair in this.Outputs) { var fileName = outputPair.Key; var output = outputPair.Value; this.Log.Trace("File name " + (fileName ?? "")); string extension = Path.GetExtension(fileName); bool isJs = extension == ('.' + Bridge.Translator.AssemblyInfo.JAVASCRIPT_EXTENSION); foreach (var moduleOutput in output.ModuleOutput) { WriteNewLine(output.NonModuletOutput, moduleOutput.Value.ToString()); } var tmp = new StringBuilder(output.TopOutput.Length + output.BottomOutput.Length + output.NonModuletOutput.Length + 100); if (output.TopOutput.Length > 0) { tmp.Append(output.TopOutput.ToString()); tmp.Append("\n"); } if (output.NonModuletOutput.Length > 0) { if (isJs) { tmp.Append("(function (globals) {"); tmp.Append("\n"); tmp.Append(" "); tmp.Append(this.GetOutputHeader()); tmp.Append("\n"); } var code = output.NonModuletOutput.ToString() + (isJs ? "\n\nBridge.init();" : ""); if (isJs) { code = " " + AbstractEmitterBlock.WriteIndentToString(code, 1); } tmp.Append(code); if (isJs) { tmp.Append("\n"); tmp.Append("})(this);"); tmp.Append("\n"); } } if (output.BottomOutput.Length > 0) { tmp.Append("\n"); tmp.Append(output.BottomOutput.ToString()); } result.Add(fileName, tmp.ToString()); } this.Log.Trace("Combining outputs done"); return(result); }
public static string ReplaceInlineArgs(AbstractEmitterBlock block, string inline, Expression[] args) { var emitter = block.Emitter; inline = _formatArg.Replace(inline, delegate(Match m) { int count = emitter.Writers.Count; string key = m.Groups[2].Value; string modifier = m.Groups[1].Success ? m.Groups[4].Value : null; StringBuilder oldSb = emitter.Output; emitter.Output = new StringBuilder(); Expression expr = null; if (Regex.IsMatch(key, "^\\d+$")) { expr = args.Skip(int.Parse(key)).FirstOrDefault(); } else { expr = args.FirstOrDefault(e => e.ToString() == key); } string s = ""; if (expr != null) { var writer = block.SaveWriter(); block.NewWriter(); expr.AcceptVisitor(emitter); s = emitter.Output.ToString(); block.RestoreWriter(writer); if (modifier == "raw") { s = s.Trim('"'); } } block.Write(block.WriteIndentToString(s)); if (emitter.Writers.Count != count) { block.PopWriter(); } string replacement = emitter.Output.ToString(); emitter.Output = oldSb; return replacement; }); return inline; }