Exemplo n.º 1
0
        private void ParseClass(AccessLevel accessLevel, bool isStatic)
        {
            Token classKeyword = _lexer.Eat(TokenType.ClassKeyword);
            Token name         = _lexer.Eat(TokenType.Identifer);

            if (accessLevel != AccessLevel.Public)
            {
                accessLevel = AnalysisAccessLevel(name.Content);
            }
            Token  colon = null, inheritanceToken = null;
            string inheritanceName = "object";

            if (_lexer.Match(":"))
            {
                colon            = _lexer.Eat(TokenType.Colon);
                inheritanceToken = _lexer.Eat(TokenType.Identifer);
                inheritanceName  = inheritanceToken.Content;
            }
            ClassDefinition classDefinition =
                new ClassDefinition(classKeyword, name, colon, inheritanceToken, inheritanceName, _endNameSpace, accessLevel, isStatic);

            _endNameSpace.AddStructure(classDefinition);
            FilesDefinitions[_lexer.FileIndex].Add(classDefinition);
            _parsingStructure = classDefinition;
            classDefinition.AddFunction(new FunctionDefinition(classDefinition, ".ctor", classDefinition.AccessLevel, false));
            classDefinition.AddFunction(new FunctionDefinition(classDefinition, ".cctor", classDefinition.AccessLevel, true));
            ChunkNode chunk = ParseChunk(s_cusDefinitionOrder, out Token openBrace, out Token closeBrace);

            classDefinition.SetBraces(openBrace, closeBrace);
            foreach (SyntaxNode analysisNode in chunk.Nodes)
            {
                if (analysisNode.NodeType == NodeType.Assign)
                {
                    classDefinition.GetFunctionDefinition(".ctor").ChunkNode.AddFirstNode(analysisNode);
                }
                classDefinition.AddField((DefineVariableNode)analysisNode);
            }
            _parsingStructure = null;
        }