private void ParseNode(IParseTree node)
        {
            if (node is StmtContext stmtContext)
            {
                Compound_stmtContext compound_Stmt = stmtContext.compound_stmt();

                if (compound_Stmt != null)
                {
                    ClassdefContext[] classdefs = compound_Stmt.GetRuleContexts <ClassdefContext>();

                    foreach (ClassdefContext classdef in classdefs)
                    {
                        string name = classdef.name().GetText();

                        this.WriteLine();
                        this.WriteKeyValue("Class", name);

                        this.WriteBeginBrace();

                        this.ParseClassContext(classdef);

                        this.WriteEndBrace();
                    }
                }
            }
        }
        private void ParseClassContext(ClassdefContext node)
        {
            var suits = node.GetRuleContexts <SuiteContext>();

            foreach (SuiteContext suit in suits)
            {
                var stmts = suit.stmt();

                foreach (StmtContext stmt in stmts)
                {
                    Simple_stmtContext   simple_Stmt   = stmt.simple_stmt();
                    Compound_stmtContext compound_Stmt = stmt.compound_stmt();

                    if (compound_Stmt != null)
                    {
                        var funcs = compound_Stmt.GetRuleContexts <FuncdefContext>();

                        foreach (FuncdefContext func in funcs)
                        {
                            string name = func.name().GetText();

                            this.WriteKeyValue("Method", name);
                        }
                    }
                    else if (simple_Stmt != null)
                    {
                        var exprs = simple_Stmt.GetRuleContexts <Expr_stmtContext>();

                        foreach (var expr in exprs)
                        {
                            Testlist_star_exprContext[] ss = expr.GetRuleContexts <Testlist_star_exprContext>();

                            string name = ss.FirstOrDefault()?.GetText();

                            if (!string.IsNullOrEmpty(name))
                            {
                                this.WriteKeyValue("Field", name);
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
	public Compound_stmtContext compound_stmt() {
		Compound_stmtContext _localctx = new Compound_stmtContext(Context, State);
		EnterRule(_localctx, 74, RULE_compound_stmt);
		try {
			State = 565;
			switch (TokenStream.La(1)) {
			case IF:
				EnterOuterAlt(_localctx, 1);
				{
				State = 557; if_stmt();
				}
				break;
			case WHILE:
				EnterOuterAlt(_localctx, 2);
				{
				State = 558; while_stmt();
				}
				break;
			case FOR:
				EnterOuterAlt(_localctx, 3);
				{
				State = 559; for_stmt();
				}
				break;
			case TRY:
				EnterOuterAlt(_localctx, 4);
				{
				State = 560; try_stmt();
				}
				break;
			case WITH:
				EnterOuterAlt(_localctx, 5);
				{
				State = 561; with_stmt();
				}
				break;
			case DEF:
				EnterOuterAlt(_localctx, 6);
				{
				State = 562; funcdef();
				}
				break;
			case CLASS:
				EnterOuterAlt(_localctx, 7);
				{
				State = 563; classdef();
				}
				break;
			case AT:
				EnterOuterAlt(_localctx, 8);
				{
				State = 564; decorated();
				}
				break;
			default:
				throw new NoViableAltException(this);
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}