Beispiel #1
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 + "\n(" + this.NodesString(n) + ")";
                    }
                    return(res);
                }
                nodes = nodes.Next;
            }
            res += nodes.NodeString(res != ""); // Test res, could be single node branch.
            return(res);
        }
Beispiel #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)
                {
                    // 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!");
        } // ParseNode
Beispiel #3
0
 public ParsedGame()
 {
     // nodes is the only public member.
     this.Nodes = null;
 }