Beispiel #1
0
        void MakeTables(TreeList<CellBase> result)
        {
            string leader = string.Empty;
            TreeList<CellBase> table = null;
            scanner.MoveNext();
            do {
                if (scanner.Current.Type == TokenType.Leader) {
                    leader = scanner.Current.Content;
                    scanner.MoveNext();
                }
                else if (scanner.Current.Type == TokenType.Word) {
                    table = new TreeList<CellBase>(new CellBase(string.Empty));
                    table.Value.SetAttribute(CellAttribute.StartTag, "<p>");
                    table.Value.SetAttribute(CellAttribute.EndTag, "</p>");
                    if (leader.Length > 0) {
                        table.Value.SetAttribute(CellAttribute.Leader, leader);
                        leader = string.Empty;
                    }
                    result.AddBranch(table);
                    MakeRows(table);
                    if (scanner.Current.Type == TokenType.Newline) scanner.MoveNext();
                }
                else {
                    scanner.MoveNext();
                }
            } while (scanner.Current.Type != TokenType.End);

            if (table != null && scanner.Current.Content.Length > 0) {
                 table.Value.SetAttribute(CellAttribute.Trailer, scanner.Current.Content);
            }
        }
Beispiel #2
0
            Tree <CellBase> ParseElement(LexicalAnalyzer theAnalyzer)
            {
                string tag    = theAnalyzer.Token;
                string leader = theAnalyzer.Leader;

                theAnalyzer.PushEnd("/" + myKeyword);
                List <Tree <CellBase> > children = myChildParser.Parse(theAnalyzer);

                if (IRequireChildren && children.Count == 0)
                {
                    throw new ApplicationException(string.Format("Can't find tag: {0}", myChildParser.Keyword));
                }
                theAnalyzer.PopEnd();
                theAnalyzer.GoToNextToken("/" + myKeyword);
                if (theAnalyzer.Token.Length == 0)
                {
                    throw new ApplicationException("expected /" + myKeyword + " tag");
                }
                var result = new TreeList <CellBase>(new CellBase(HtmlToText(theAnalyzer.Leader)));

                result.Value.SetAttribute(CellAttribute.Body, theAnalyzer.Leader);
                result.Value.SetAttribute(CellAttribute.EndTag, theAnalyzer.Token);
                result.Value.SetAttribute(CellAttribute.Leader, leader);
                result.Value.SetAttribute(CellAttribute.StartTag, tag);
                foreach (Tree <CellBase> child in children)
                {
                    result.AddBranch(child);
                }
                return(result);
            }
Beispiel #3
0
 void MakeRows(TreeList<CellBase> table) {
     do {
         var row = new TreeList<CellBase>(new CellBase(string.Empty));
         row.Value.SetAttribute(CellAttribute.StartTag, startTags[1]);
         row.Value.SetAttribute(CellAttribute.EndTag, endTags[1]);
         table.AddBranch(row);
         MakeCells(row);
         if (scanner.Current.Type == TokenType.Newline) scanner.MoveNext();
     } while (scanner.Current.Type == TokenType.BeginCell || scanner.Current.Type == TokenType.Word);
 }
Beispiel #4
0
        protected static Tree <string> ParameterTree(Tree <string> input, int startingIndex)
        {
            var result = new TreeList <string>(input.Value);

            for (int i = startingIndex; i < input.Branches.Count; i++)
            {
                result.AddBranch(input.Branches[i]);
            }
            return(result);
        }
Beispiel #5
0
 void MakeCells(TreeList<CellBase> row)
 {
     while (scanner.Current.Type == TokenType.Word) {
         var cell = new TreeList<CellBase>(new CellBase(scanner.Current.Content));
         cell.Value.SetAttribute(CellAttribute.Body, scanner.Current.Content);
         cell.Value.SetAttribute(CellAttribute.StartTag, "<span>");
         cell.Value.SetAttribute(CellAttribute.EndTag, "</span> ");
         row.AddBranch(cell);
         scanner.MoveNext();
     }
 }
Beispiel #6
0
 public Tree<CellBase> Parse(string input) {
     var alternationParser = new AlternationParser();
     var cells = new ListParser("td", alternationParser, false);
     var rows = new ListParser("tr", cells, true);
     var tables = new ListParser("table", rows, true);
     var items = new ListParser("li", alternationParser, false);
     var lists = new ListParser("ul", items, true);
     alternationParser.ChildParsers = new [] {tables, lists};
     var root = new CellBase(string.Empty, "div");
     var result = new TreeList<CellBase>(root);
     foreach (Tree<CellBase> branch in tables.Parse(new LexicalAnalyzer(input))) result.AddBranch(branch);
     return result;
 }
Beispiel #7
0
 void MakeRows(TreeList <CellBase> table)
 {
     do
     {
         var row = new TreeList <CellBase>(new CellBase(string.Empty));
         row.Value.SetAttribute(CellAttribute.StartTag, startTags[1]);
         row.Value.SetAttribute(CellAttribute.EndTag, endTags[1]);
         table.AddBranch(row);
         MakeCells(row);
         if (scanner.Current.Type == TokenType.Newline)
         {
             scanner.MoveNext();
         }
     } while (scanner.Current.Type == TokenType.BeginCell || scanner.Current.Type == TokenType.Word);
 }
Beispiel #8
0
        private static TreeList <string> ReadList(string input)
        {
            int length = int.Parse(input.Substring(0, 6));
            var result = new TreeList <string>();
            int start  = 7;

            for (int i = 0; i < length; i++)
            {
                int itemLength = int.Parse(input.Substring(start, 6));
                start += 7;
                result.AddBranch(Read(input.Substring(start, itemLength)));
                start += itemLength + 1;
            }
            return(result);
        }
Beispiel #9
0
    public class ComposeList : ComposeOperator <string> { //todo: handle any enumerable type
        public bool TryCompose(Processor <string> processor, TypedValue instance, ref Tree <string> result)
        {
            if (instance.Type != typeof(List <object>))
            {
                return(false);
            }
            var list = instance.Value as List <object> ?? new List <object>();
            var tree = new TreeList <string>();

            foreach (object value in list)
            {
                tree.AddBranch(processor.Compose(value));
            }
            result = tree;
            return(true);
        }
Beispiel #10
0
 void MakeCells(TreeList<CellBase> row)
 {
     while (scanner.Current.Type == TokenType.BeginCell || scanner.Current.Type == TokenType.Word) {
         var cell = new TreeList<CellBase>(new CellBase(scanner.Current.Content));
         cell.Value.SetAttribute(CellAttribute.StartTag, startTags[2]);
         cell.Value.SetAttribute(CellAttribute.EndTag, endTags[2]);
         if (scanner.Current.Type == TokenType.BeginCell) {
             MakeTables(cell);
         }
         else if (scanner.Current.Type == TokenType.Word) {
             cell.Value.SetAttribute(CellAttribute.Body, HttpUtility.HtmlEncode(scanner.Current.Content));
         }
         row.AddBranch(cell);
         scanner.MoveNext();
     }
 }
Beispiel #11
0
        public Tree <CellBase> Parse(string input)
        {
            var alternationParser = new AlternationParser();
            var cells             = new ListParser("td", alternationParser, false);
            var rows   = new ListParser("tr", cells, true);
            var tables = new ListParser("table", rows, true);
            var items  = new ListParser("li", alternationParser, false);
            var lists  = new ListParser("ul", items, true);

            alternationParser.ChildParsers = new [] { tables, lists };
            var root   = new CellBase(string.Empty, "div");
            var result = new TreeList <CellBase>(root);

            foreach (Tree <CellBase> branch in tables.Parse(new LexicalAnalyzer(input)))
            {
                result.AddBranch(branch);
            }
            return(result);
        }
Beispiel #12
0
 void MakeCells(TreeList <CellBase> row)
 {
     while (scanner.Current.Type == TokenType.BeginCell || scanner.Current.Type == TokenType.Word)
     {
         var cell = new TreeList <CellBase>(new CellBase(scanner.Current.Content));
         cell.Value.SetAttribute(CellAttribute.StartTag, startTags[2]);
         cell.Value.SetAttribute(CellAttribute.EndTag, endTags[2]);
         if (scanner.Current.Type == TokenType.BeginCell)
         {
             MakeTables(cell);
         }
         else if (scanner.Current.Type == TokenType.Word)
         {
             cell.Value.SetAttribute(CellAttribute.Body, HttpUtility.HtmlEncode(scanner.Current.Content));
         }
         row.AddBranch(cell);
         scanner.MoveNext();
     }
 }
Beispiel #13
0
        void MakeTables(TreeList <CellBase> result)
        {
            string leader             = string.Empty;
            TreeList <CellBase> table = null;

            scanner.MoveNext();
            do
            {
                if (scanner.Current.Type == TokenType.Leader)
                {
                    leader = scanner.Current.Content;
                    scanner.MoveNext();
                }
                else if (scanner.Current.Type == TokenType.Word)
                {
                    SetTags();
                    table = new TreeList <CellBase>(new CellBase(string.Empty));
                    table.Value.SetAttribute(CellAttribute.StartTag, startTags[0]);
                    table.Value.SetAttribute(CellAttribute.EndTag, endTags[0]);
                    if (leader.Length > 0)
                    {
                        table.Value.SetAttribute(CellAttribute.Leader, leader);
                        leader = string.Empty;
                    }
                    result.AddBranch(table);
                    MakeRows(table);
                    if (scanner.Current.Type == TokenType.Newline)
                    {
                        scanner.MoveNext();
                    }
                }
                else
                {
                    scanner.MoveNext();
                }
            } while (scanner.Current.Type != TokenType.End && scanner.Current.Type != TokenType.EndCell);

            if (table != null && scanner.Current.Content.Length > 0)
            {
                table.Value.SetAttribute(CellAttribute.Trailer, scanner.Current.Content);
            }
        }
Beispiel #14
0
 public SlimTree AddBranchValue(object branch)
 {
     tree.AddBranch(branch as Tree <string> ?? new SlimLeaf(branch.ToString()));
     return(this);
 }
Beispiel #15
0
 Tree<CellBase> ParseElement(LexicalAnalyzer theAnalyzer) {
     string tag = theAnalyzer.Token;
     string leader = theAnalyzer.Leader;
     theAnalyzer.PushEnd("/" + myKeyword);
     List<Tree<CellBase>> children = myChildParser.Parse(theAnalyzer);
     if (IRequireChildren && children.Count == 0) {
         throw new ApplicationException(string.Format("Can't find tag: {0}", myChildParser.Keyword));
     }
     theAnalyzer.PopEnd();
     theAnalyzer.GoToNextToken("/" + myKeyword);
     if (theAnalyzer.Token.Length == 0) throw new ApplicationException("expected /" + myKeyword + " tag");
     var result = new TreeList<CellBase>(new CellBase(HtmlToText(theAnalyzer.Leader)));
     result.Value.SetAttribute(CellAttribute.Body, theAnalyzer.Leader);
     result.Value.SetAttribute(CellAttribute.EndTag, theAnalyzer.Token);
     if (leader.Length > 0) result.Value.SetAttribute(CellAttribute.Leader, leader);
     result.Value.SetAttribute(CellAttribute.StartTag, tag);
     foreach (Tree<CellBase> child in children) result.AddBranch(child);
     return result;
 }