/// <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> /// 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; }
/// <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; }
/// <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); }
/// <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); }
/// <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; }
/// <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); }