예제 #1
0
        private bool ReadTree(SGFTree currentNode)
        {
            var nextChar     = '\0';
            var propertyName = string.Empty;

            do
            {
                nextChar = ConsumeWhiteSpaces();
                if (nextChar == ';')
                {
                    currentNode = currentNode.NewNode();
                }
                else if (nextChar == '(')
                {
                    ReadTree(currentNode);
                }
                else if (nextChar == ')')
                {
                    return(true);
                }
                else if (nextChar == '[')
                {
                    var attribute = ReadAttribute();
                    if (propertyName != string.Empty)
                    {
                        currentNode.AddAttribute(
                            new SGFProperty(propertyName, attribute));
                    }
                }
                else if (char.IsLetter(nextChar))
                {
                    propertyName = "";
                    do
                    {
                        propertyName = string.Concat(propertyName, nextChar);
                        nextChar     = ConsumeWhiteSpaces();
                    } while (nextChar != '[' && !stream.EndOfStream);

                    if (stream.EndOfStream)
                    {
                        throw new Exception("Unexpected end of stream");
                    }

                    currentNode.AddAttribute(
                        new SGFProperty(propertyName, ReadAttribute()));
                }
                else if (stream.EndOfStream)
                {
                    throw new Exception("Unexpected end of stream");
                }
            } while (nextChar != ')');
            return(true);
        }
예제 #2
0
 /// <summary>
 /// Generic property
 /// </summary>
 /// <param name="key">key of properties</param>
 /// <param name="value">pre-formated value</param>
 /// <returns></returns>
 public SgfBuilder p(string key, string value)
 {
     _cursor.AddAttribute(new SGFProperty(key, value));
     return(this);
 }