Ejemplo n.º 1
0
 public ParsedNode()
 {
     this.Next           = null;
     this.Previous       = null;
     this.Branches       = null;
     this.Properties     = new Dictionary <string, List <string> >();
     this.BadNodeMessage = null;
 }
Ejemplo n.º 2
0
        } // ParseNodes

        //// _parse_node returns a ParseNode with its properties filled in.
        ////
        private static ParsedNode ParseNode(Lexer lexer)
        {
            var node = new ParsedNode();

            // Loop properties ...
            while (lexer.HasData())
            {
                var id = lexer.GetPropertyId();
                if (id == null)
                {
                    if (!(node.Properties.ContainsKey("B") || node.Properties.ContainsKey("W")))
                    {
                        // This is overwritten in game.cs ParsedNodeToMove.
                        node.BadNodeMessage = "hmmmm, no B or W, flagging this as hack/test to stop treeview clicks";
                    }
                    // Expected to return from here due to no properties or syntax at end of properties.
                    return(node);
                }
                if (node.Properties.ContainsKey(id))
                {
                    throw new Exception(string.Format("Encountered ID, {0}, twice for node -- file location {1}.",
                                                      id, lexer.Location));
                }
                lexer.ScanFor("[", "Expected property value");
                var i      = -1;
                var values = new List <string>();
                node.Properties[id] = values;
                // Loop values for one property
                while (lexer.HasData())
                {
                    // C and GC properties allow newline sequences in value.
                    values.Add(lexer.GetPropertyValue(id == "C" || id == "GC"));
                    i = lexer.PeekFor("[").Item1;
                    if (i == -1)
                    {
                        break;          // no new values
                    }
                    lexer.Location = i;
                }
            }
            //throw new FileFormatException("Unexpectedly hit EOF!");
            throw new IOException("Unexpectedly hit EOF!");
        } // ParseNode
Ejemplo n.º 3
0
        //// _nodes_string returns a string for a series of nodes, and the caller
        //// needs to supply the open and close parens that bracket the series.
        ////
        private string NodesString(ParsedNode nodes)
        {
            var res = "";

            while (nodes.Next != null)
            {
                // Get one node's string with a leading newline if it is not the
                // first.
                res += nodes.NodeString(res != "");
                if (nodes.Branches != null)
                {
                    foreach (var n in nodes.Branches)
                    {
                        res = res + Environment.NewLine + "(" + this.NodesString(n) + ")";
                    }
                    return(res);
                }
                nodes = nodes.Next;
            }
            res += nodes.NodeString(res != ""); // Test res, could be single node branch.
            return(res);
        }
Ejemplo n.º 4
0
 public ParsedGame()
 {
     // nodes is the only public member.
     this.Nodes = null;
 }