示例#1
0
        private Decl.Class parseClass()
        {
            ParserState ps = new ParserState(this);

            Decl.Class rst = new Decl.Class();

            if (peek().Type == DeclTokenType.Comment)
            {
                rst.Desc = peek().Data;
                m_pos++;
            }

            if (peek().Type != DeclTokenType.KW_Class)
            {
                ps.restore();
                return(null);
            }
            m_pos++;
            if (peek().Type == DeclTokenType.Identifier)
            {
                rst.Name = peek().Data;
                m_pos++;
            }
            else
            {
                rst.Name = "__unnamed@" + getUniqueString();
            }
            if (peek().Type == DeclTokenType.OP_Colon)
            {
                m_pos++;
                if (peek().Type == DeclTokenType.Identifier)
                {
                    rst.BaseClass = peek().Data;
                    m_pos++;
                }
                else
                {
                    throw new System.Exception("Line " + peek().Line + ": baseClass expected");
                }
            }

            if (peek().Type != DeclTokenType.OP_LBrace)
            {
                throw new System.Exception("Line " + peek().Line + ": '{' expected");
            }
            m_pos++;
            rst.Declarations = parseDeclarations();

            if (peek().Type != DeclTokenType.OP_RBrace)
            {
                throw new System.Exception("Line " + peek().Line + ": '}' expected");
            }
            m_pos++;
            if (peek().Type == DeclTokenType.Identifier)
            {
                rst.Object = peek().Data;
                m_pos++;
            }

            return(rst);
        }
示例#2
0
        private Decl.Class parseClass()
        {
            ParserState ps = new ParserState(this);
            Decl.Class rst = new Decl.Class();

            if (peek().Type == DeclTokenType.Comment)
            {
                rst.Desc = peek().Data;
                m_pos++;
            }

            if (peek().Type != DeclTokenType.KW_Class)
            {
                ps.restore();
                return null;
            }
            m_pos++;
            if (peek().Type == DeclTokenType.Identifier)
            {
                rst.Name = peek().Data;
                m_pos++;
            }
            else
            {
                rst.Name = "__unnamed@" + getUniqueString();
            }
            if (peek().Type == DeclTokenType.OP_Colon)
            {
                m_pos++;
                if (peek().Type == DeclTokenType.Identifier)
                {
                    rst.BaseClass = peek().Data;
                    m_pos++;
                }
                else
                {
                    throw new System.Exception("Line " + peek().Line + ": baseClass expected");
                }
            }

            if (peek().Type != DeclTokenType.OP_LBrace)
            {
                throw new System.Exception("Line " + peek().Line + ": '{' expected");
            }
            m_pos++;
            rst.Declarations = parseDeclarations();

            if (peek().Type != DeclTokenType.OP_RBrace)
            {
                throw new System.Exception("Line " + peek().Line + ": '}' expected");
            }
            m_pos++;
            if (peek().Type == DeclTokenType.Identifier)
            {
                rst.Object = peek().Data;
                m_pos++;
            }

            return rst;
        }