Example #1
0
        /// <summary>
        /// Parse node contents add return a fresh node.
        /// </summary>
        /// <param name="prototypes">List containing all node types</param>
        /// <param name="parent">Node that this is a subnode to. Can be null</param>
        /// <param name="line">Line to parse</param>
        /// <param name="offset">Where to start the parsing. Should be set to where the next node should start parsing.</param>
        /// <returns>A node corresponding to the bla bla; null if parsing failed.</returns>
        /// <exception cref="CodeGeneratorException"></exception>
        public override Node Parse(NodeList prototypes, Node parent, LineInfo line, ref int offset)
        {
            // text on tag rows are identified by a single space.
            if (parent != null && line.Data[offset] == ' ')
                ++offset;

            TextNode node = new TextNode(parent, line.Data.Substring(offset));
            if (parent == null)
                node.LineInfo = line;
            offset = line.Data.Length;
            return node;
        }
Example #2
0
        /// <summary>
        /// Parse a node
        /// todo: improve doc
        /// </summary>
        /// <param name="theLine"></param>
        /// <param name="prototypes"></param>
        /// <param name="parent"></param>
        /// <param name="textNode"></param>
        protected static void ParseNode(LineInfo theLine, NodeList prototypes, Node parent, TextNode textNode)
        {
            Node curNode = null;
            int offset = 0;

            // parse each part of a line
            while (offset <= theLine.Data.Length - 1)
            {
                Node node = prototypes.GetPrototype(GetWord(theLine.Data, offset), curNode == null) ?? textNode;
                node = node.Parse(prototypes, curNode, theLine, ref offset);

                // first node on line, set it as current
                if (curNode == null)
                {
                    curNode = node;
                    curNode.LineInfo = theLine;
                    parent.Children.AddLast(node);
                }
                else
                    curNode.AddModifier(node); // append attributes etc.
            }

            foreach (LineInfo child in theLine.Children)
                ParseNode(child, prototypes, curNode, textNode);
        }
Example #3
0
        /// <summary>
        /// Parse a file and convert into to our own template object code.
        /// </summary>
        /// <param name="reader">A <see cref="TextReader"/> containing our template</param>
        /// <exception cref="CodeGeneratorException">If something is incorrect in the template.</exception>
        public void Parse(TextReader reader)
        {
            _lineNo = -1;
            _reader = reader;
            _mother = new LineInfo(-1, string.Empty);
            _prevLine = null;
            _currentLine = null;

            PreParse(reader);

            NodeList prototypes = new NodeList();
            prototypes.Add(new AttributeNode(null));
            prototypes.Add(new TagNode(null));
            prototypes.Add(new IdNode(null));
            prototypes.Add(new SilentCodeNode(null));
            prototypes.Add(new ClassNode(null));
            prototypes.Add(new DisplayCodeNode(null));
            prototypes.Add(new DocTypeTag(null, null));
			prototypes.Add(new PartialNode(null));
            TextNode textNode = new TextNode(null, "prototype");
            _parentNode = new TextNode(null, string.Empty);

            foreach (LineInfo info in _mother.Children)
                ParseNode(info, prototypes, _parentNode, textNode);
        }
Example #4
0
        /// <summary>
        /// Convert node to HTML (with ASP-tags)
        /// </summary>
        /// <returns>HTML string</returns>
        public override string ToHtml()
        {
            StringBuilder sb     = new StringBuilder();
            string        intend = LineInfo == null ? string.Empty : string.Empty.PadLeft(LineInfo.Intendation, '\t');

            sb.Append(intend);
            sb.Append("<");
            sb.Append(_name);

            if (Modifiers.Count != 0)
            {
                sb.Append(' ');
            }

            TextNode textNode = null;

            foreach (Node node in Modifiers)
            {
                if (node.IsTextNode)
                {
                    textNode = node as TextNode;
                }
                else
                {
                    sb.Append(node.ToHtml());
                }
            }

            if (LineInfo.SelfClosed)
            {
                sb.Append("/>");
                return(sb.ToString());
            }
            else
            {
                sb.Append(">");
            }

            if (textNode != null)
            {
                sb.Append(textNode.ToHtml());
            }

            if (Children.Count != 0)
            {
                sb.AppendLine();
            }

            foreach (Node node in Children)
            {
                sb.Append(node.ToHtml());
            }


            sb.Append(intend);
            sb.Append("</");
            sb.Append(_name);
            sb.AppendLine(">");

            return(sb.ToString());
        }