public void TestLineWrap1() { string templates = "array(values) ::= <<int[] a = { <values; wrap=\"\\n\", separator=\",\"> };>>" + newline; writeFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); Template a = group.GetInstanceOf("array"); a.Add("values", new int[] { 3, 9, 20, 2, 1, 4, 6, 32, 5, 6, 77, 888, 2, 1, 6, 32, 5, 6, 77, 4, 9, 20, 2, 1, 4, 63, 9, 20, 2, 1, 4, 6, 32, 5, 6, 77, 6, 32, 5, 6, 77, 3, 9, 20, 2, 1, 4, 6, 32, 5, 6, 77, 888, 1, 6, 32, 5 }); string expecting = "int[] a = { 3,9,20,2,1,4,6,32,5,6,77,888,\n" + "2,1,6,32,5,6,77,4,9,20,2,1,4,63,9,20,2,1,\n" + "4,6,32,5,6,77,6,32,5,6,77,3,9,20,2,1,4,6,\n" + "32,5,6,77,888,1,6,32,5 };"; StringWriter sw = new StringWriter(); ITemplateWriter stw = new AutoIndentWriter(sw, "\n"); // force \n as newline stw.LineWidth = 40; a.Write(stw); string result = sw.ToString(); Assert.AreEqual(expecting, result); }
public virtual List <InterpEvent> GetEvents(CultureInfo locale, int lineWidth) { StringWriter @out = new StringWriter(); ITemplateWriter wr = new AutoIndentWriter(@out); wr.LineWidth = lineWidth; return(GetEvents(locale, wr)); }
public virtual List <InterpEvent> GetEvents(CultureInfo locale, int lineWidth) { StringWriter @out = new StringWriter(); ITemplateWriter wr = new AutoIndentWriter(@out); wr.LineWidth = lineWidth; Interpreter interp = new Interpreter(groupThatCreatedThisInstance, locale); interp.Execute(wr, this); // Render and track events return(interp.GetEvents()); }
public static TemplateVisualizer Visualize(this Template template, ErrorManager errorManager, CultureInfo culture, int lineWidth) { ErrorBuffer errors = new ErrorBuffer(); template.impl.NativeGroup.Listener = errors; StringWriter @out = new StringWriter(); ITemplateWriter wr = new AutoIndentWriter(@out); wr.LineWidth = lineWidth; Interpreter interp = new Interpreter(template.Group, culture, true); TemplateFrame frame = new TemplateFrame(template, null); interp.Execute(wr, frame); // Render and track events TemplateVisualizer visualizer = new TemplateVisualizer(errorManager, frame, @out.ToString(), interp, interp.GetExecutionTrace(), errors.Errors); visualizer.Show(); return visualizer; }
public static void Visualize(this DebugTemplate template, ErrorManager errorManager, CultureInfo culture, int lineWidth) { ErrorBuffer errors = new ErrorBuffer(); template.impl.NativeGroup.Listener = errors; StringWriter @out = new StringWriter(); ITemplateWriter wr = new AutoIndentWriter(@out); wr.LineWidth = lineWidth; Interpreter interp = new Interpreter(template.groupThatCreatedThisInstance, culture); interp.Execute(wr, template); // Render and track events TemplateVisualizer visualizer = new TemplateVisualizer(errorManager, template, @out.ToString(), interp, interp.GetExecutionTrace(), errors.Errors); visualizer.Show(); }
public static TemplateVisualizer Visualize(this Template template, ErrorManager errorManager, CultureInfo culture, int lineWidth) { ErrorBuffer errors = new ErrorBuffer(); template.impl.NativeGroup.Listener = errors; StringWriter @out = new StringWriter(); ITemplateWriter wr = new AutoIndentWriter(@out); wr.LineWidth = lineWidth; Interpreter interp = new Interpreter(template.Group, culture, true); TemplateFrame frame = new TemplateFrame(template, null); interp.Execute(wr, frame); // Render and track events TemplateVisualizer visualizer = new TemplateVisualizer(errorManager, frame, @out.ToString(), interp, interp.GetExecutionTrace(), errors.Errors); visualizer.Show(); return(visualizer); }
public virtual void Write(Template code, string fileName) { try { Stopwatch stopwatch = Stopwatch.StartNew(); using (TextWriter w = tool.GetOutputFileWriter(g, fileName)) { ITemplateWriter wr = new AutoIndentWriter(w); wr.LineWidth = lineWidth; code.Write(wr); } stopwatch.Stop(); } catch (IOException ioe) { tool.errMgr.ToolError(ErrorType.CANNOT_WRITE_FILE, ioe, fileName); } }
/** <summary> * Return an instance of a StringTemplateWriter that spits output to w. * If a writer is specified, use it instead of the default. * </summary> */ public virtual IStringTemplateWriter GetStringTemplateWriter( TextWriter w ) { IStringTemplateWriter stw = null; if ( _userSpecifiedWriter != null ) { try { stw = (IStringTemplateWriter)Activator.CreateInstance(_userSpecifiedWriter, new object[] { typeof(TextWriter) }); } catch ( Exception e ) { Error( "problems getting StringTemplateWriter", e ); } } if ( stw == null ) { stw = new AutoIndentWriter( w ); } return stw; }
/** <summary> * Return an instance of a StringTemplateWriter that spits output to w. * If a writer is specified, use it instead of the default. * </summary> */ public virtual IStringTemplateWriter GetStringTemplateWriter( TextWriter w ) { IStringTemplateWriter stw = null; if ( _userSpecifiedWriter != null ) { try { ConstructorInfo ctor = _userSpecifiedWriter.GetConstructor( new Type[] { typeof( TextWriter ) } ); stw = (IStringTemplateWriter)ctor.Invoke( new Object[] { w } ); } catch ( Exception e ) { Error( "problems getting StringTemplateWriter", e ); } } if ( stw == null ) { stw = new AutoIndentWriter( w ); } return stw; }
public IList<InterpEvent> GetEvents(CultureInfo culture, int lineWidth) { StringWriter stream = new StringWriter(); ITemplateWriter writer = new AutoIndentWriter(stream); writer.SetLineWidth(lineWidth); Interpreter interp = new Interpreter(groupThatCreatedThisInstance, culture); interp.Exec(writer, this); return interp.Events; }
public void TestLineWrapWithNormalizedNewlines() { string templates = "group test;" + newline + "array(values) ::= <<int[] a = { <values; wrap=\"\\r\\n\", separator=\",\"> };>>" + newline; StringTemplateGroup group = new StringTemplateGroup( new StringReader( templates ) ); StringTemplate a = group.GetInstanceOf( "array" ); a.SetAttribute( "values", new int[] {3,9,20,2,1,4,6,32,5,6,77,888,2,1,6,32,5,6,77, 4,9,20,2,1,4,63,9,20,2,1,4,6,32,5,6,77,6,32,5,6,77, 3,9,20,2,1,4,6,32,5,6,77,888,1,6,32,5} ); string expecting = "int[] a = { 3,9,20,2,1,4,6,32,5,6,77,888,\n" + // wrap is \r\n, normalize to \n "2,1,6,32,5,6,77,4,9,20,2,1,4,63,9,20,2,1,\n" + "4,6,32,5,6,77,6,32,5,6,77,3,9,20,2,1,4,6,\n" + "32,5,6,77,888,1,6,32,5 };"; StringWriter sw = new StringWriter(); IStringTemplateWriter stw = new AutoIndentWriter( sw, "\n" ); // force \n as newline stw.SetLineWidth( 40 ); a.Write( stw ); string result = sw.ToString(); Assert.AreEqual( expecting, result ); }
public virtual List<InterpEvent> GetEvents(CultureInfo locale, int lineWidth) { StringWriter @out = new StringWriter(); ITemplateWriter wr = new AutoIndentWriter(@out); wr.LineWidth = lineWidth; return GetEvents(locale, wr); }