def enterIf_then(self, ctx: ReqBlockParser.If_thenContext): """ IF expression THEN (stmt | stmt_group) group_qualifier* label? else_clause?; """ if LOG_CONTEXT_PATH: print(context_path(ctx), file=sys.stderr) # Capture the conditional expression's terminals expr = ctx.expression() terminals = [] expression_terminals(expr, terminals)
def enterCourse_list(self, ctx: ReqBlockParser.Course_listContext): """ course_list : course_item (and_list | or_list)? course_qualifier* label?; course_item : discipline? catalog_number course_qualifier*; and_list : (list_and course_item )+; or_list : (list_or course_item)+; """ context_path_str = context_path(ctx) if LOG_CONTEXT_PATH: print(context_path_str, file=sys.stderr) if 'except' in context_path_str.lower( ) or 'includ' in context_path_str.lower(): return course_list = build_course_list(self.institution, ctx) self.sections[self.scribe_section].append(course_list)
def dispatch(ctx: any, institution: str, requirement_id: str): """ Invoke the appropriate handler given its top-level context. """ which_part = 'header' if context_path(ctx).lower().startswith('head') else 'body' key = class_name(ctx).lower() try: if which_part == 'header': return dispatch_header[key](ctx, institution, requirement_id) else: return dispatch_body[key](ctx, institution, requirement_id) except KeyError as key_error: key_error = str(key_error).strip('\'') nested = f' while processing “{key}”' if key != key_error else '' if DEBUG: # Missing handler: report it and recover ever so gracefully # print_stack(file=sys.stderr) print(f'No dispatch method for “{key_error}”{nested}: ' f'{institution=}; {requirement_id=}; {which_part=}', file=sys.stderr) return {'tag': 'Dispatch_Error', 'method': f'“{key_error}”{nested}', 'institution': institution, 'requirement_id': requirement_id, 'part': which_part}
def enterGroup_qualifier(self, ctx: ReqBlockParser.Group_qualifierContext): """ """ if LOG_CONTEXT_PATH: print(context_path(ctx), file=sys.stderr)
def enterEnd_if(self, ctx: ReqBlockParser.End_ifContext): """ """ if LOG_CONTEXT_PATH: print(context_path(ctx), file=sys.stderr)
def enterBody(self, ctx: ReqBlockParser.BodyContext): """ """ if LOG_CONTEXT_PATH: print(context_path(ctx), file=sys.stderr) self.scribe_section = ScribeSection.BODY