/// /// <summary> This constructor was added to allow the re-use of parsers. /// The normal constructor takes a single argument which /// an InputStream. This simply creates a re-usable parser /// object, we satisfy the requirement of an InputStream /// by using a newline character as an input stream. /// </summary> public Parser(RuntimeServices rs):this(new VelocityCharStream(new StringReader("\n"), 1, 1)) { InitBlock(); /* * now setup a VCS for later use */ velcharstream = new VelocityCharStream(new StringReader("\n"), 1, 1); /* * and save the RuntimeServices */ rsvc = rs; }
public void Test_VelocityTryCharStream() { String s1 = "this is a test"; VelocityCharStream vcs = new VelocityCharStream(new StringReader(s1), 1, 1); String s2 = String.Empty; while(vcs.ReadChar()) { s2 += vcs.CurrentCharacter; } Assert.IsTrue(s1.Equals(s2), "read stream did not match source string"); }
public void Test_VelocityCharStream() { String s1 = "this is a test"; VelocityCharStream vcs = new VelocityCharStream(new StringReader(s1), 1, 1); String s2 = String.Empty; try { Char c = vcs.ReadChar(); while (true) { s2 += c; c = vcs.ReadChar(); } } catch (IOException) { // this is expected to happen when the stream has been read } Assert.IsTrue(s1.Equals(s2), "read stream did not match source string"); }
private VelocityCharStream GetTemplateStream() { StringBuilder sb = new StringBuilder(); sb.Append("## This is an example velocity template\n"); sb.Append("\n"); sb.Append("#set( $this = \"Velocity\")\n"); sb.Append("\n"); sb.Append("$this is great!\n"); sb.Append("\n"); //TODO: parse fails for this segment for unknown reason // sb.Append("#foreach( $name in $list )\n"); // sb.Append("row $velocityCount :: $name is great!\n"); // sb.Append("#end\n"); // sb.Append("\n"); sb.Append("#set( $condition = true)\n"); sb.Append("\n"); sb.Append("#if ($condition)\n"); sb.Append(" The condition is true!\n"); sb.Append("#else\n"); sb.Append(" The condition is false!\n"); sb.Append("#end\n"); VelocityCharStream vcs = new VelocityCharStream(new StringReader(sb.ToString()), 1, 1); return vcs; }