Beispiel #1
0
    def __init__(self,
                 student_context=None,
                 solution_context=None,
                 student_env=None,
                 solution_env=None,
                 student_parts=None,
                 solution_parts=None,
                 highlight=None,
                 highlighting_disabled=None,
                 messages=None,
                 force_diagnose=False,
                 **kwargs):

        # Set basic fields from kwargs
        self.__dict__.update(kwargs)

        self.student_parts = student_parts
        self.solution_parts = solution_parts
        self.messages = messages if messages else []
        self.force_diagnose = force_diagnose

        # parse code if didn't happen yet
        if not hasattr(self, 'student_tree'):
            self.student_tree_tokens, self.student_tree = State.parse_external(
                self.student_code)

        if not hasattr(self, 'solution_tree'):
            self.solution_tree_tokens, self.solution_tree = State.parse_internal(
                self.solution_code)

        if not hasattr(self, 'pre_exercise_tree'):
            _, self.pre_exercise_tree = State.parse_internal(
                self.pre_exercise_code)

        if not hasattr(self, 'parent_state'):
            self.parent_state = None

        self.student_context = Context(
            student_context) if student_context is None else student_context
        self.solution_context = Context(
            solution_context) if solution_context is None else solution_context
        self.student_env = Context(
            student_env) if student_env is None else student_env
        self.solution_env = Context(
            solution_env) if solution_env is None else solution_env

        self.highlight = self.student_tree if (
            not highlight) and self.parent_state else highlight
        self.highlighting_disabled = highlighting_disabled

        self.converters = get_manual_converters(
        )  # accessed only from root state

        self.manual_sigs = None
        self._parser_cache = {}
Beispiel #2
0
    def __init__(
        self,
        student_code,
        solution_code,
        pre_exercise_code,
        student_process,
        solution_process,
        raw_student_output,
        # solution output
        reporter,
        force_diagnose=False,
        highlight=None,
        highlighting_disabled=None,
        messages=None,
        creator=None,
        student_ast=None,
        solution_ast=None,
        student_ast_tokens=None,
        solution_ast_tokens=None,
        student_parts=None,
        solution_parts=None,
        student_context=Context(),
        solution_context=Context(),
        student_env=Context(),
        solution_env=Context(),
    ):
        args = locals().copy()
        self.params = list()

        for k, v in args.items():
            if k != "self":
                self.params.append(k)
                setattr(self, k, v)

        self.messages = messages if messages else []

        self.ast_dispatcher = self.get_dispatcher()

        # Parse solution and student code
        # if possible, not done yet and wanted (ast arguments not False)
        if isinstance(self.student_code, str) and student_ast is None:
            self.student_ast = self.parse(student_code)
        if isinstance(self.solution_code, str) and solution_ast is None:
            self.solution_ast = self.parse(solution_code, test=False)

        if highlight is None:  # todo: check parent_state? (move check to reporting?)
            self.highlight = self.student_ast

        self.converters = get_manual_converters()  # accessed only from root state

        self.manual_sigs = None
Beispiel #3
0
    def __init__(
            self,
            student_code,
            solution_code,
            pre_exercise_code,
            student_process,
            solution_process,
            raw_student_output,
            # solution output
            reporter,
            force_diagnose=False,
            highlight=None,
            highlighting_disabled=None,
            messages=None,
            parent_state=None,
            student_ast=None,
            solution_ast=None,
            student_ast_tokens=None,
            solution_ast_tokens=None,
            student_parts=None,
            solution_parts=None,
            student_context=Context(),
            solution_context=Context(),
            student_env=Context(),
            solution_env=Context(),
    ):
        args = locals().copy()
        self.params = list()

        for k, v in args.items():
            if k not in ["self", "args"]:
                self.params.append(k)
                setattr(self, k, v)

        self.ast_dispatcher = self.get_dispatcher()

        # parse code if didn't happen yet
        if student_ast is None:
            self.student_ast = self.parse(student_code)
        if solution_ast is None:
            self.solution_ast = self.parse(solution_code, test=False)

        if highlight is None and parent_state:
            self.highlight = self.student_ast

        self.messages = messages if messages else []

        self.converters = get_manual_converters(
        )  # accessed only from root state

        self.manual_sigs = None
Beispiel #4
0
    def __init__(self, 
                 student_context=None, solution_context=None,
                 student_parts=None, solution_parts=None, 
                 highlight = None, messages=None, 
                 **kwargs):

        # Set basic fields from kwargs
        self.__dict__.update(kwargs)

        self.student_parts = student_parts
        self.solution_parts = solution_parts
        self.messages = messages if messages else []

        # parse code if didn't happen yet
        if not hasattr(self, 'student_tree'):
            self.student_tree = State.parse_ext(self.student_code)

        if not hasattr(self, 'solution_tree'):
            self.solution_tree = State.parse_int(self.solution_code)

        if not hasattr(self, 'pre_exercise_tree'):
            self.pre_exercise_tree = State.parse_int(self.pre_exercise_code)

        if not hasattr(self, 'parent_state'):
            self.parent_state = None

        self.student_context  = Context(student_context)  if student_context is None else student_context
        self.solution_context = Context(solution_context) if solution_context is None else solution_context

        self.highlight = self.student_tree if (not highlight) and self.parent_state else highlight

        self.converters = get_manual_converters()    # accessed only from root state

        self.fun_usage = {}
        self.manual_sigs = None
        self._parser_cache = {}