Пример #1
0
        static void MakeNodesRecoursive(TextProccesor proc, TextNode root, INodeMarkUpSpecification specs,
                                        NodeHeader openedHeader = null)
        {
            TextNodeType currType = openedHeader == null ? TextNodeType.NONE : openedHeader.type;
            TextNode     currNode;

            while (proc.IsNext())
            {
                currNode = null;
                var text = proc.NextTill(specs.OpenMark); // look for "{|"
                if (!string.IsNullOrEmpty(text))
                {
                    currNode = new TextNode(text);
                }
                if (!proc.IsNext())
                {
                    if (currNode != null)
                    {
                        root.AddChild(currNode);
                    }
                    break;
                }
                proc.Move(specs.OpenMark.Length); // skips "{|"
                NodeHeader newNodeHeader = null;
                try {
                    newNodeHeader = new NodeHeader(proc.NextTill(specs.CloseMark), specs); //look for "}"
                }
                catch (TextParseException e) {
                    throw new TextParseException(e.Message + " at: " + proc.AllTextTillCurent());
                }
                proc.Move(specs.CloseMark.Length); // skips "}"
                if (specs.DestroyNewLineAfterMarkUp)
                {
                    proc.TryEat(specs.NewLineSymbol);
                }
                if (newNodeHeader.Enclosing)
                {
                    if (newNodeHeader.type == currType)
                    {
                        if (currNode != null)
                        {
                            root.AddChild(currNode);
                        }
                        break; //node done
                    }
                    else
                    {
                        throw new TextParseException("Unexpected enclosing keyword: " + newNodeHeader.Name);
                    }
                }
                var subRootNode = new TextNode(newNodeHeader.type);
                subRootNode.paramsString = newNodeHeader.Params;
                if (currNode != null)
                {
                    root.AddChild(currNode);
                }
                root.AddChild(subRootNode);
                MakeNodesRecoursive(proc, subRootNode, specs, newNodeHeader);
            }
        }
Пример #2
0
 static TextNodeType StrToNodeType(string str, INodeMarkUpSpecification specs)
 {
     try {
         return(specs.Keywords[str]);
     }
     catch (KeyNotFoundException) {
         throw new TextParseException("Unknown node type: " + str);
     }
 }
Пример #3
0
        /// <summary>
        /// Splits the raw text to nodes, according to given INodeMarkUpSpecification.
        /// if no INodeMarkUpSpecification default specifiction will be used.
        /// Returns rootNode.
        /// </summary>
        /// <returns></returns>
        public static TextNode SplitTextToNodes(string rawText, INodeMarkUpSpecification specs = null)
        {
            if (specs == null)
            {
                specs = new DefaultMarkUpSpecification();
            }
            TextNode root = new TextNode(TextNodeType.root);

            MakeNodesRecoursive(new TextProccesor(rawText), root, specs);
            return(root);
        }
Пример #4
0
            public NodeHeader(string nodeHeaderFullString, INodeMarkUpSpecification specs)
            {
                var strings = nodeHeaderFullString.Split(splitters, StringSplitOptions.RemoveEmptyEntries);

                if (strings[0].StartsWith(specs.NodeClose_OpenMarkPostfix))
                {
                    Enclosing  = true;
                    strings[0] = strings[0].Substring(1);
                }
                Name   = strings[0];
                type   = StrToNodeType(strings[0], specs);
                Params = nodeHeaderFullString;
            }
Пример #5
0
 public MessageProducer(IMessageTemplate templ, IEnumerable <KeyValuePair <string, string> > wildcards, INodeMarkUpSpecification specs)
 {
     try {
         headerTempl = TextNode.SplitTextToNodes(templ.MsgHeader + "  ", specs);
         bodyTempl   = TextNode.SplitTextToNodes(templ.MsgBody + "  ", specs);
     }
     catch (TextParseException e) {
         errorContainer.parseExceptions.Add(e);
         throw new MessageProducerException("Text parse Exception: " + e.Message);
     }
     this.wildcards = wildcards;
 }