Beispiel #1
0
        public static string ReadPropertyValue(ReadFile input)
        {
            string lValue   = string.Empty;
            bool   lEscaped = false;

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

                if ((c == ']') && (!lEscaped))
                {
                    return(lValue);
                }

                lValue = lValue + c.ToString();

                if (lEscaped)
                {
                    lEscaped = false;
                }
                else
                if (c == EscapeCharacter)
                {
                    lEscaped = true;
                }
            }

            return(lValue);
        }
Beispiel #2
0
        public static Property ReadProperty(ReadFile input)
        {
            string lName  = string.Empty;
            string lValue = string.Empty;

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

                if (Char.IsLetter(c))
                {
                    lName = lName + c.ToString();
                }

                if (c == '[')
                {
                    lValue = ReadPropertyValue(input);

                    return(new Property(lName, lValue));
                }
            }

            return(null);
        }
Beispiel #3
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);
        }