Beispiel #1
0
        //classdef: 'class' NAME ['(' testlist ')'] ':' suite
        private ClassDefinition ParseClassDef() {
            Eat(TokenKind.KeywordClass);
            
            SourceLocation start = GetStart();
            SymbolId name = ReadName();
            if (name == SymbolId.Empty) {
                // no name, assume there's no class.
                return new ClassDefinition(SymbolId.Empty, new Expression[0], new ExpressionStatement(new ErrorExpression()));
            }

            Expression[] bases = new Expression[0];
            if (MaybeEat(TokenKind.LeftParenthesis)) {
                List<Expression> l = ParseTestList();
                
                if (l.Count == 1 && l[0] is ErrorExpression) {
                    // error handling, classes is incomplete.
                    return new ClassDefinition(name, new Expression[0], new ExpressionStatement(new ErrorExpression()));
                }
                bases = l.ToArray();
                Eat(TokenKind.RightParenthesis);
            }
            SourceLocation mid = GetEnd();

            // Save private prefix
            string savedPrefix = SetPrivatePrefix(name);

            // Parse the class body
            Statement body = ParseSuite();

            // Restore the private prefix
            _privatePrefix = savedPrefix;

            ClassDefinition ret = new ClassDefinition(name, bases, body);
            ret.Header = mid;
            ret.SetLoc(start, GetEnd());
            return ret;
        }
Beispiel #2
0
        //classdef: 'class' NAME ['(' testlist ')'] ':' suite
        private ClassDefinition ParseClassDef() {
            Eat(TokenKind.KeywordClass);

            var start = GetStart();
            string name = ReadName();
            if (name == null) {
                // no name, assume there's no class.
                return new ClassDefinition(null, new Expression[0], ErrorStmt());
            }

            Expression[] bases = new Expression[0];
            if (MaybeEat(TokenKind.LeftParenthesis)) {
                List<Expression> l = ParseTestList();

                if (l.Count == 1 && l[0] is ErrorExpression) {
                    // error handling, classes is incomplete.
                    return new ClassDefinition(name, new Expression[0], ErrorStmt());
                }
                bases = l.ToArray();
                Eat(TokenKind.RightParenthesis);
            }
            var mid = GetEnd();

            // Save private prefix
            string savedPrefix = SetPrivatePrefix(name);

            // Parse the class body
            Statement body = ParseClassOrFuncBody();

            // Restore the private prefix
            _privatePrefix = savedPrefix;

            ClassDefinition ret = new ClassDefinition(name, bases, body);
            ret.HeaderIndex =  mid;
            ret.SetLoc(_globalParent, start, GetEnd());
            return ret;
        }
Beispiel #3
0
        //classdef: 'class' NAME ['(' testlist ')'] ':' suite
        private ClassDefinition ParseClassDef()
        {
            Eat(TokenKind.KeywordClass);
            Location start = GetStart();
            SymbolId name = ReadName();
            Expression[] bases = new Expression[0];
            if (MaybeEat(TokenKind.LeftParenthesis)) {
                List<Expression> l = ParseTestList();
                if (!Options.Python25 && l.Count == 0) {
                    ReportSyntaxError(PeekToken());
                }
                bases = l.ToArray();
                Eat(TokenKind.RightParenthesis);
            }
            Location mid = GetEnd();

            // Save private prefix
            string savedPrefix = SetPrivatePrefix(name);

            // Parse the class body
            Statement body = ParseSuite();

            // Restore the private prefix
            privatePrefix = savedPrefix;

            ClassDefinition ret = new ClassDefinition(name, bases, body);
            ret.Header = mid;
            ret.SetLoc(GetExternal(), start, GetEnd());
            return ret;
        }