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)
        {
            if (offset >= line.Data.Length)
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Too little data");
            }

            int pos = line.Data.Length;

            ++offset;
            string name = line.Data.Substring(offset, pos - offset);

            offset = pos;

            string trimmedData = line.Data.Trim();

            if (trimmedData.Length > 0 && trimmedData[trimmedData.Length - 1] == ';')
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Displayed code should not end with semicolon.");
            }

            DisplayCodeNode node = (DisplayCodeNode)prototypes.CreateNode("=", parent);

            node._code = name;
            if (parent == null)
            {
                node.LineInfo = line;
            }
            return(node);
        }
Example #2
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)
        {
            if (line.Data[offset] != '{')
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Attribute cant handle info at char " + offset + 1);
            }

            int endPos = GetEndPos(offset, line.Data, '}');

            if (endPos == -1)
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Failed to find end of attribute list: '" + line.UnparsedData + "'.");
            }

            List <Attribute> col        = new List <Attribute>();
            string           attributes = line.Data.Substring(offset + 1, endPos - offset - 1);

            ParseAttributes(line, attributes, col);
            offset = endPos + 1;


            AttributeNode node = (AttributeNode)prototypes.CreateNode("{", parent);

            node._attributes = col;
            return(AddMe(prototypes, parent, line, node));
        }
Example #3
0
        /// <summary>
        /// Creates a DIV node and add's the specified node to it.
        /// </summary>
        /// <param name="prototypes">Contains all prototypes for each control char. used to instanciate new nodes.</param>
        /// <param name="parent">parent node</param>
        /// <param name="line">current line information</param>
        /// <param name="me">node to add to the DIV node</param>
        /// <returns>current node</returns>
        public Node AddMe(NodeList prototypes, Node parent, LineInfo line, Node me)
        {
            if (parent == null)
            {
                TagNode tag = (TagNode)prototypes.CreateNode("%", parent);
                tag.Name     = "div";
                tag.LineInfo = line;
                tag.AddModifier(me);
                return(tag);
            }

            return(me);
        }
Example #4
0
        /// <summary>
        /// Creates a DIV node and add's the specified node to it.
        /// </summary>
        /// <param name="prototypes">Contains all prototypes for each control char. used to instanciate new nodes.</param>
        /// <param name="parent">parent node</param>
        /// <param name="line">current line information</param>
        /// <param name="me">node to add to the DIV node</param>
        /// <returns>current node</returns>
        public Node AddMe(NodeList prototypes, Node parent, LineInfo line, Node me)
        {
            if (parent == null)
            {
                TagNode tag = (TagNode)prototypes.CreateNode("%", null);
                tag.Name = "div";
                tag.LineInfo = line;
                tag.AddModifier(me);
                return tag;
            }

            return me;
        }
Example #5
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)
        {
            if (offset > line.Data.Length)
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Too little data");

            int pos = line.Data.Length;
            ++offset;
            string code = line.Data.Substring(offset, pos - offset);
            offset = pos;

            SilentCodeNode node = (SilentCodeNode)prototypes.CreateNode("-", parent);
            node._code = code;
            if (parent != null)
                node.LineInfo = line;
            return node;
        }
Example #6
0
        /// <summary>
        /// Parse node contents add return a fresh node.
        /// </summary>
        /// <param name="parent">Node that this is a subnode to. Can be null</param>
        /// <param name="prototypes">A list with node types</param>
        /// <param name="line">Line to parse</param>
        /// <param name="offset">Where to start the parsing. Will 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)
        {
            if (offset > line.Data.Length - 1)
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Tried to parse after end of line");
            }

            if (line.Data[offset] != '_')
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Not a PartialNode");
            }

            // From the first " sign (offset + 2) find the next " sign
            int pos = -1;

            for (int i = offset + 2; i < line.Data.Length; ++i)
            {
                if (line.Data[i] == '\"')
                {
                    pos = i;
                    break;
                }
            }
            if (pos == -1)
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "PartialNode does not contain an end paranthesis.");
            }

            // Cut out the data between the two above found " signs and then start processing the address
            // The address is converted from the format /example/example/ to \\example\\example.haml
            PartialNode node = (PartialNode)prototypes.CreateNode("_", parent);

            node._target = line.Data.Substring(offset + 2, pos - offset - 2);
            if (node._target[node._target.Length - 1] == '/')
            {
                node._target = node._target.Substring(0, node._target.Length - 1);
            }
            if (node._target[0] == '/')
            {
                node._target = node._target.Substring(1);
            }
            node._target  = node._target.Replace("/", "\\\\");
            node._target += ".haml";

            offset = pos + 1;
            return(node);
        }
Example #7
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)
        {
            if (line.Data[offset] != '#')
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Node is not an id node.");

            int endPos = GetEndPos(offset, line.Data);
            if (endPos == -1)
                endPos = line.Data.Length;

            ++offset;
            string id = line.Data.Substring(offset, endPos - offset);
            offset = endPos;

            IdNode node = (IdNode)prototypes.CreateNode("#", parent);
            node._id = id;
            return AddMe(prototypes, parent, line, node);
        }
Example #8
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)
        {
            if (offset > line.Data.Length - 1)
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Too little data");

            int pos = GetEndPos(offset, line.Data);
            if (pos == -1)
                pos = line.Data.Length;

            ++offset;
            string name = line.Data.Substring(offset, pos - offset);
            offset = pos;

            ClassNode node = (ClassNode)prototypes.CreateNode(".", parent);
            node._name = name;
            return AddMe(prototypes, parent, line, node);
        }
Example #9
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)
        {
            if (offset >= line.Data.Length)
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Too little data");

            int pos = line.Data.Length;

            ++offset;
            string name = line.Data.Substring(offset, pos - offset);
            offset = pos;

            string trimmedData = line.Data.Trim();
            if (trimmedData.Length > 0 && trimmedData[trimmedData.Length - 1] == ';')
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Displayed code should not end with semicolon.");

            DisplayCodeNode node = (DisplayCodeNode)prototypes.CreateNode("=", parent);
            node._code = name;
            if (parent == null)
                node.LineInfo = line;
            return node;
        }
Example #10
0
        /// <summary>
        /// Parse node contents add return a fresh node.
        /// </summary>
        /// <param name="parent">Node that this is a subnode to. Can be null</param>
        /// <param name="prototypes">A list with node types</param>
        /// <param name="line">Line to parse</param>
        /// <param name="offset">Where to start the parsing. Will 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)
        {
            if (offset > line.Data.Length - 1)
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Tried to parse after end of line");
            }

            if (line.Data[offset] != '%')
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Not a tag node");
            }

            int pos = -1;

            for (int i = offset + 1; i < line.Data.Length; ++i)
            {
                if (!char.IsLetterOrDigit(line.Data[i]))
                {
                    pos = i;
                    break;
                }
            }
            if (pos == -1)
            {
                pos = line.Data.Length;
            }

            TagNode node = (TagNode)prototypes.CreateNode("%", parent);

            node.Name = line.Data.Substring(offset + 1, pos - offset - 1);
            if (node._name == "br" || node._name == "input" || node._name == "style" || node._name == "img")
            {
                line.SelfClosed          = true;
                node.LineInfo            = line;
                node.LineInfo.SelfClosed = true;
            }

            offset = pos;
            return(node);
        }
        /// <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)
        {
            if (offset > line.Data.Length)
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Too little data");
            }

            int pos = line.Data.Length;

            ++offset;
            string code = line.Data.Substring(offset, pos - offset);

            offset = pos;

            SilentCodeNode node = (SilentCodeNode)prototypes.CreateNode("-", parent);

            node._code = code;
            if (parent != null)
            {
                node.LineInfo = line;
            }
            return(node);
        }
Example #12
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)
        {
            if (offset > line.Data.Length - 1)
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Too little data");
            }

            int pos = GetEndPos(offset, line.Data);

            if (pos == -1)
            {
                pos = line.Data.Length;
            }

            ++offset;
            string name = line.Data.Substring(offset, pos - offset);

            offset = pos;

            ClassNode node = (ClassNode)prototypes.CreateNode(".", parent);

            node._name = name;
            return(AddMe(prototypes, parent, line, node));
        }
Example #13
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)
        {
            if (line.Data[offset] != '#')
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Node is not an id node.");
            }

            int endPos = GetEndPos(offset, line.Data);

            if (endPos == -1)
            {
                endPos = line.Data.Length;
            }

            ++offset;
            string id = line.Data.Substring(offset, endPos - offset);

            offset = endPos;

            IdNode node = (IdNode)prototypes.CreateNode("#", parent);

            node._id = id;
            return(AddMe(prototypes, parent, line, node));
        }
Example #14
0
		/// <summary>
		/// Parse node contents add return a fresh node.
		/// </summary>
		/// <param name="parent">Node that this is a subnode to. Can be null</param>
		/// <param name="prototypes">A list with node types</param>
		/// <param name="line">Line to parse</param>
		/// <param name="offset">Where to start the parsing. Will 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)
		{
			if (offset > line.Data.Length - 1)
				throw new CodeGeneratorException(line.LineNumber, line.Data, "Tried to parse after end of line");

			if (line.Data[offset] != '_')
				throw new CodeGeneratorException(line.LineNumber, line.Data, "Not a PartialNode");

			// From the first " sign (offset + 2) find the next " sign
			int pos = -1;
			for (int i = offset + 2; i < line.Data.Length; ++i)
			{
				if (line.Data[i] == '\"')
				{
					pos = i;
					break;
				}
			}
			if (pos == -1)
				throw new CodeGeneratorException(line.LineNumber, line.Data, "PartialNode does not contain an end paranthesis.");

			// Cut out the data between the two above found " signs and then start processing the address
			// The address is converted from the format /example/example/ to \\example\\example.haml
			PartialNode node = (PartialNode)prototypes.CreateNode("_", parent);
			node._target = line.Data.Substring(offset + 2, pos - offset - 2);
			if (node._target[node._target.Length - 1] == '/')
				node._target = node._target.Substring(0, node._target.Length - 1);
			if (node._target[0] == '/')
				node._target = node._target.Substring(1);
			node._target = node._target.Replace("/", "\\\\");
			node._target += ".haml";

			offset = pos + 1;
			return node;
		}
Example #15
0
 public Node CreateNode() => Nodes.CreateNode();
Example #16
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)
        {
            if (line.Data[offset] != '{')
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Attribute cant handle info at char " + offset + 1);

            int endPos = GetEndPos(offset, line.Data, '}');
            if (endPos == -1)
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Failed to find end of attribute list: '" + line.UnparsedData + "'.");

            List<Attribute> col = new List<Attribute>();
            string attributes = line.Data.Substring(offset + 1, endPos - offset - 1);
            ParseAttributes(line, attributes, col);
            offset = endPos + 1;

            AttributeNode node = (AttributeNode)prototypes.CreateNode("{", parent);
            node._attributes = col;
            return AddMe(prototypes, parent, line, node);
        }