コード例 #1
0
ファイル: LayoutEngine.cs プロジェクト: kjin/Ribbons
 public static Text SaveLayout(LayoutTree layout)
 {
     List<string> strings = new List<string>();
     SaveNode(layout.Root, strings, "");
     return new Text(strings.ToArray());
 }
コード例 #2
0
ファイル: LayoutEngine.cs プロジェクト: kjin/Ribbons
 public static LayoutTree BuildLayout(Text source)
 {
     int length = source.Length;
     StringBuilder processed = new StringBuilder();
     for (int i = 0; i < length; i++)
     {
         String preprocessed = source[i];
         // State flags
         bool quote = false;
         bool array = false;
         bool script = false;
         bool comment = false;
         bool followsRightBracket = false;
         // Filter out all non-quote whitespace, turn
         // semicolons into empty brackets, and clear comments.
         for (int j = 0; j < preprocessed.Length; j++)
         {
             if (quote && preprocessed[j] != '\"')
             {
                 processed.Append(preprocessed[j]);
                 continue;
             }
             switch (preprocessed[j])
             {
                 case '\"':
                     quote = !quote;
                     break;
                 case '[':
                     array = true;
                     processed.Append('[');
                     break;
                 case ']':
                     array = false;
                     processed.Append(']');
                     break;
                 case ' ':
                     break;
                 case ',':
                     if (array)
                         processed.Append(',');
                     else if (!followsRightBracket)
                         processed.Append("()");
                     break;
                 case ')':
                     processed.Append("())");
                     followsRightBracket = true;
                     break;
                 case '#':
                     comment = true;
                     break;
                 default:
                     processed.Append(preprocessed[j]);
                     followsRightBracket = false;
                     break;
             }
             if (comment)
                 break;
         }
     #if DEBUG
         if (quote)
             Console.WriteLine("LayoutEngine WARNING: No matching endquote on line {0}.", i);
     #endif
     }
     // Dummy node because the root has not yet been born
     LayoutTreeNode dummy = new LayoutTreeNode("dummy", "dummy");
     Parse(processed.ToString(), dummy);
     LayoutTree layoutTree = new LayoutTree();
     layoutTree.Root = dummy.Children.First.Value;
     #if DEBUG
     Console.WriteLine("------------\r\n" + layoutTree.RepresentativeString + "------------");
     if (dummy.Children.Count > 1)
         Console.WriteLine("LayoutEngine WARNING: {0} top-level nodes found... the last {1} will be ignored.", dummy.Children.Count, dummy.Children.Count - 1);
     #endif
     return layoutTree;
 }