示例#1
0
 public static TokenTree Parse(TextReader textReader)
 {
     Reader reader = new Reader(textReader);
     Splitter splitter = new Splitter();
     Dictionary<int, TokenTree> lastAtLevel = new Dictionary<int, TokenTree>
     {
         [-1] = new TokenTree()
     };
     foreach (Line line in reader)
     {
         TokenTree tokenTree = splitter.Split(line.Content);
         TokenTree parent = lastAtLevel[line.Offset - 1];
         lastAtLevel[line.Offset] = tokenTree;
         parent.Children.Add(tokenTree);
     }
     return lastAtLevel[lastAtLevel[-1].Children.Count == 1 ? 0 : -1];
 }
示例#2
0
 private static void Test(string toSplit, string key, string value)
 {
     TokenTree tokenTree = new Splitter().Split(toSplit);
     Assert.AreEqual(key, tokenTree.Name, toSplit);
     Assert.AreEqual(value, tokenTree.Value.Text, toSplit);
 }