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); }
public void Test_Parse() { VelocityCharStream vcs = GetTemplateStream(); Parser p = new Parser(vcs); SimpleNode root = p.process(); String javaNodes = "19,18,9,5,23,56,23,42,23,24,6,18,56,18,9,5,23,56,23,42,23,25,6,18,44,23,5,56,6,18,46,18,43,0"; String nodes = String.Empty; if (root != null) { Token t = root.FirstToken; nodes += t.kind.ToString(); while (t != root.LastToken) { t = t.next; nodes += "," + t.kind.ToString(); } } if (!javaNodes.Equals(nodes)) { Console.Out.WriteLine(""); Console.Out.WriteLine(".Net parsed nodes did not match java nodes."); Console.Out.WriteLine("java=" + javaNodes); Console.Out.WriteLine(".net=" + nodes); Assertion.Fail(".Net parsed nodes did not match java nodes."); } }
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_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.True(s1.Equals(s2), "read stream did not match source string"); }
public IEnumerable <ITagSpan <TokenTag> > GetTags(NormalizedSnapshotSpanCollection spans) { var tags = Enumerable.Empty <ITagSpan <TokenTag> >(); foreach (SnapshotSpan span in spans) { var text = span.GetText(); //Perf hack - if we don't have any of the following, then there's no special velocity if (text.IndexOfAny(new[] { '$', '#' }) < 0) { yield break; } using (var reader = new StringReader(text)) { var charStream = new VelocityCharStream(reader, 0, 1, text.Length); _parser.ReInit(charStream); int position = span.Start.Position; while (true) { Token token; try { token = _parser.NextToken; } catch { //TODO: return some kind of error yield break; } if (token.Kind == ParserConstants.EOF) { yield break; } var tag = TagToken(token, position, span.Snapshot); if (tag != null) { yield return(tag); } position += token.Image.Length; } } } }
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 (System.IO.IOException) { // this is expected to happen when the stream has been read } Assertion.Assert("read stream did not match source string", s1.Equals(s2)); }
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; }