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); } } } } } }
public Simple_stmtContext simple_stmt() { Simple_stmtContext _localctx = new Simple_stmtContext(Context, State); EnterRule(_localctx, 26, RULE_simple_stmt); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 375; small_stmt(); State = 380; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream,40,Context); while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) { if ( _alt==1 ) { { { State = 376; Match(SEMI_COLON); State = 377; small_stmt(); } } } State = 382; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream,40,Context); } State = 384; _la = TokenStream.La(1); if (_la==SEMI_COLON) { { State = 383; Match(SEMI_COLON); } } State = 386; Match(NEWLINE); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return _localctx; }