Example #1
0
    def parse_ext(x):
        rep = Reporter.active_reporter

        res = None
        try:
            res = ast.parse(x)
            # enrich tree with end lines and end columns
            utils_ast.mark_text_ranges(res, x + '\n')

        except IndentationError as e:
            rep.set_tag("fun", "indentation_error")
            e.filename = "script.py"
            # no line info for now
            rep.feedback = Feedback("Your code could not be parsed due to an error in the indentation:<br>`%s.`" % str(e))
            rep.failed_test = True

        except SyntaxError as e:
            rep.set_tag("fun", "syntax_error")
            e.filename = "script.py"
            # no line info for now
            rep.feedback = Feedback("Your code can not be executed due to a syntax error:<br>`%s.`" % str(e))
            rep.failed_test = True

        # Can happen, can't catch this earlier because we can't differentiate between
        # TypeError in parsing or TypeError within code (at runtime).
        except:
            rep.set_tag("fun", "other_error")
            rep.feedback.message = "Something went wrong while parsing your code."
            rep.failed_test = True

        finally:
            if (res is None):
                res = False

        return(res)
Example #2
0
    def parse_int(x):
        res = None
        try:
            res = ast.parse(x)
            utils_ast.mark_text_ranges(res, x + '\n')

        except SyntaxError as e:
            raise SyntaxError(str(e))
        except TypeError as e:
            raise TypeError(str(e))
        finally:
            if (res is None):
                res = False

        return (res)
Example #3
0
    def parse_int(x):
        res = None
        try:
            res = ast.parse(x)
            utils_ast.mark_text_ranges(res, x + '\n')

        except SyntaxError as e:
            raise SyntaxError(str(e))
        except TypeError as e:
            raise TypeError(str(e))
        finally:
            if (res is None):
                res = False

        return(res)
Example #4
0
def build_and_mark(s):
	res = ast.parse(s)
	utils_ast.mark_text_ranges(res, s + '\n')
	return(res)
Example #5
0
def build_and_mark(s):
    res = ast.parse(s)
    utils_ast.mark_text_ranges(res, s + '\n')
    return (res)