Пример #1
0
        public void Pretty()
        {
            List <SGFToken> lNewList         = new List <SGFToken>(Tokens.Count);
            SGFToken        lSGFNewLineToken = new SGFToken(Environment.NewLine);

            int lParamCnt = 0;
            int lLineLen  = 0;

            foreach (SGFToken lSGFToken in Tokens)
            {
                if (lSGFToken.Type == TokenType.OPENPARAN)
                {
                    lParamCnt++;
                    lNewList.Add(lSGFToken);
                    lLineLen = lLineLen + lSGFToken.ToString().Length;
                }
                else if (lSGFToken.Type == TokenType.CLOSEPARAN)
                {
                    lParamCnt--;
                    lNewList.Add(lSGFToken);
                    lNewList.Add(lSGFNewLineToken);
                    lLineLen = 0;
                }
                else if (lSGFToken.Type == TokenType.SEMICOMMA)
                {
                    lNewList.Add(lSGFToken);
                }
                else if (lSGFToken.Type == TokenType.PROPERTY)
                {
                    bool            lNewLine         = false;
                    SGFPropertyInfo lSGFPropertyInfo = SGFInfo.GetSGFPropertyInfo(lSGFToken.Property.Name);

                    if (lSGFPropertyInfo == null)
                    {
                        lNewLine = true;
                    }
                    else
                    if ((lSGFPropertyInfo.PropertyType == SGFPropertyType.GameInfo) || (lSGFPropertyInfo.PropertyType == SGFPropertyType.None))
                    {
                        lNewLine = true;
                    }

                    if (lLineLen + lSGFToken.ToString().Length > 65)
                    {
                        lNewLine = true;
                    }

                    if (lNewLine)
                    {
                        lNewList.Add(lSGFNewLineToken);
                        lLineLen = 0;
                    }

                    lNewList.Add(lSGFToken);
                    lLineLen = lLineLen + lSGFToken.ToString().Length;
                }
            }

            Tokens = lNewList;
        }
Пример #2
0
        public void AddWhitespace(string whitespace)
        {
            if (Tokens.Count > 0)
            {
                SGFToken lSGFToken = Tokens[Tokens.Count - 1];
                if (lSGFToken.Type == TokenType.WHITESPACE)
                {
                    lSGFToken.Whitespace = lSGFToken.Whitespace + whitespace;
                    return;
                }
            }

            Add(new SGFToken(whitespace));
        }
Пример #3
0
 public void Add(SGFToken token)
 {
     Tokens.Add(token);
 }
Пример #4
0
        public void Pretty()
        {
            List<SGFToken> lNewList = new List<SGFToken>(Tokens.Count);
            SGFToken lSGFNewLineToken = new SGFToken(Environment.NewLine);

            int lParamCnt = 0;
            int lLineLen = 0;

            foreach (SGFToken lSGFToken in Tokens)
            {
                if (lSGFToken.Type == TokenType.OPENPARAN)
                {
                    lParamCnt++;
                    lNewList.Add(lSGFToken);
                    lLineLen = lLineLen + lSGFToken.ToString().Length;
                }
                else if (lSGFToken.Type == TokenType.CLOSEPARAN)
                {
                    lParamCnt--;
                    lNewList.Add(lSGFToken);
                    lNewList.Add(lSGFNewLineToken);
                    lLineLen = 0;
                }
                else if (lSGFToken.Type == TokenType.SEMICOMMA)
                {
                    lNewList.Add(lSGFToken);
                }
                else if (lSGFToken.Type == TokenType.PROPERTY)
                {
                    bool lNewLine = false;
                    SGFPropertyInfo lSGFPropertyInfo = SGFInfo.GetSGFPropertyInfo(lSGFToken.Property.Name);

                    if (lSGFPropertyInfo == null)
                        lNewLine = true;
                    else
                        if ((lSGFPropertyInfo.PropertyType == SGFPropertyType.GameInfo) || (lSGFPropertyInfo.PropertyType == SGFPropertyType.None))
                            lNewLine = true;

                    if (lLineLen + lSGFToken.ToString().Length > 65)
                        lNewLine = true;

                    if (lNewLine)
                    {
                        lNewList.Add(lSGFNewLineToken);
                        lLineLen = 0;
                    }

                    lNewList.Add(lSGFToken);
                    lLineLen = lLineLen + lSGFToken.ToString().Length;
                }
            }

            Tokens = lNewList;
        }
Пример #5
0
        public static SGFTokens Tokenize(ReadFile input)
        {
            SGFTokens lTokens = new SGFTokens();

            if (!input.IsOk())
            {
                lTokens.SetErrorMessage(input.GetErrorMessage());
                return(lTokens);
            }

            while (!input.EOF)
            {
                char c = input.Peek();

                if (Char.IsLetter(c))
                {
                    Property lProperty = ReadProperty(input);

                    if (lProperty == null)
                    {
                        lTokens.SetErrorMessage("ERROR: unable to parse sgf file");
                        return(lTokens);
                    }

                    lTokens.Add(new SGFToken(lProperty));
                }
                else
                {
                    input.Get();                     // read past the character

                    if (c == '[')
                    {
                        lTokens.RemovePreviousWhitespace();

                        SGFToken lSGFToken = lTokens.LastToken();

                        if ((lSGFToken == null) || (lSGFToken.Type != TokenType.PROPERTY))
                        {
                            lTokens.SetErrorMessage("ERROR: unable to parse sgf file");
                            return(lTokens);
                        }

                        string lValue = ReadPropertyValue(input);

                        lSGFToken.Property.AdditionalValues.Add(lValue);
                    }
                    else if (c == '(')
                    {
                        lTokens.Add(new SGFToken(TokenType.OPENPARAN));
                    }
                    else if (c == ')')
                    {
                        lTokens.Add(new SGFToken(TokenType.CLOSEPARAN));
                    }
                    else if (c == ';')
                    {
                        lTokens.Add(new SGFToken(TokenType.SEMICOMMA));
                    }
                    else
                    if (WhitespaceCharacters.IndexOf(c) >= 0)
                    {
                        lTokens.AddWhitespace(c.ToString());
                    }
                }
            }

            return(lTokens);
        }
Пример #6
0
 public void Add(SGFToken token)
 {
     Tokens.Add(token);
 }