Beispiel #1
0
        public IrisCharacter parseCharacter()
        {
            IrisCharacter charac = new IrisCharacter();
            String        fieldName, fieldValue;

            nextTokenIfEquals(Token.TokenValue.CHARACTER);

            if (currentTokenEquals(Token.TokenValue.VALUE_IDENTIFIER))
            {
                charac.name = currentToken.stringValue;

                nextToken();

                nextTokenIfEquals(Token.TokenValue.LBRACE);

                while (!currentTokenEquals(Token.TokenValue.RBRACE))
                {
                    if (currentTokenEquals(Token.TokenValue.VALUE_IDENTIFIER))
                    {
                        fieldName = currentToken.stringValue;

                        nextToken();

                        nextTokenIfEquals(Token.TokenValue.EQ);

                        //name = "name";
                        if (fieldName.Equals("name"))
                        {
                            if (currentTokenEquals(Token.TokenValue.STRING))
                            {
                                charac.charName = currentToken.stringValue;

                                nextToken();

                                nextTokenIfEquals(Token.TokenValue.SEMICOLON);
                            }
                            else
                            {
                                throw new SyntaxError(lineNumber, colNumber, Token.TokenValue.STRING);
                            }
                        }
                        //color = "#0077FF";
                        else if (fieldName.Equals("color"))
                        {
                            if (currentTokenEquals(Token.TokenValue.STRING))
                            {
                                charac.setColor(currentToken.stringValue);
                            }
                            else
                            {
                                throw new SyntaxError(lineNumber, colNumber, Token.TokenValue.STRING);
                            }
                        }
                        //images = {
                        //  happy = "happy_and_cool.png";
                        //  light = "emotions/shining.png";
                        //  ..... = ....................;
                        //};
                        else if (fieldName.Equals("images"))
                        {
                            nextTokenIfEquals(Token.TokenValue.LBRACE);

                            while (!currentTokenEquals(Token.TokenValue.RBRACE))
                            {
                                if (currentTokenEquals(Token.TokenValue.VALUE_IDENTIFIER))
                                {
                                    fieldName = currentToken.stringValue;
                                    nextToken();

                                    nextTokenIfEquals(Token.TokenValue.EQ);

                                    if (currentTokenEquals(Token.TokenValue.STRING))
                                    {
                                        fieldValue = currentToken.stringValue;

                                        nextToken();
                                        nextTokenIfEquals(Token.TokenValue.SEMICOLON);

                                        charac.addImage(fieldName, fieldValue);
                                    }
                                    else
                                    {
                                        throw new SyntaxError(lineNumber, colNumber, Token.TokenValue.STRING);
                                    }
                                }
                                else
                                {
                                    throw new SyntaxError(lineNumber, colNumber, Token.TokenValue.VALUE_IDENTIFIER);
                                }
                            }

                            nextTokenIfEquals(Token.TokenValue.RBRACE);
                            nextTokenIfEquals(Token.TokenValue.SEMICOLON);
                        }
                        else
                        {
                            throw new UnknownField(lineNumber, colNumber, charac.name, fieldName);
                        }
                    }
                }

                nextTokenIfEquals(Token.TokenValue.RBRACE);
                //nextTokenIfEquals(Token.TokenValue.SEMICOLON);

                return(charac);
            }
            else
            {
                throw new SyntaxError(lineNumber, colNumber, Token.TokenValue.VALUE_IDENTIFIER);
            }

            //erreur
            //return null;
        }