예제 #1
0
        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);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
	public ClassdefContext classdef() {
		ClassdefContext _localctx = new ClassdefContext(Context, State);
		EnterRule(_localctx, 146, RULE_classdef);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 969; Match(CLASS);
			State = 970; Match(NAME);
			State = 976;
			_la = TokenStream.La(1);
			if (_la==OPEN_PAREN) {
				{
				State = 971; Match(OPEN_PAREN);
				State = 973;
				_la = TokenStream.La(1);
				if (((((_la - 20)) & ~0x3f) == 0 && ((1L << (_la - 20)) & ((1L << (LAMBDA - 20)) | (1L << (NOT - 20)) | (1L << (NONE - 20)) | (1L << (TRUE - 20)) | (1L << (FALSE - 20)) | (1L << (NAME - 20)) | (1L << (STRING_LITERAL - 20)) | (1L << (BYTES_LITERAL - 20)) | (1L << (DECIMAL_INTEGER - 20)) | (1L << (OCT_INTEGER - 20)) | (1L << (HEX_INTEGER - 20)) | (1L << (BIN_INTEGER - 20)) | (1L << (FLOAT_NUMBER - 20)) | (1L << (IMAG_NUMBER - 20)) | (1L << (ELLIPSIS - 20)) | (1L << (STAR - 20)) | (1L << (OPEN_PAREN - 20)) | (1L << (POWER - 20)) | (1L << (OPEN_BRACK - 20)) | (1L << (ADD - 20)) | (1L << (MINUS - 20)) | (1L << (NOT_OP - 20)) | (1L << (OPEN_BRACE - 20)))) != 0)) {
					{
					State = 972; arglist();
					}
				}

				State = 975; Match(CLOSE_PAREN);
				}
			}

			State = 978; Match(COLON);
			State = 979; suite();
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}