Exemple #1
0
def parsing_error_recov02():
    parse_expr = Syntax.ndpt_dp_rvalue
    s = """
mcdp {
unp
}
""".strip()
    _s2, _expr, _commented = mark_unparsable(s, parse_expr)
def parsing_error_recov02():
    parse_expr = Syntax.ndpt_dp_rvalue
    s = """
mcdp {
unp
}
""".strip()
    _s2, _expr, _commented = mark_unparsable(s, parse_expr)
Exemple #3
0
def parsing_error_recov04():
    s="""   
mcdp {
 provides x [m]
    unp   requires a [m]
}""".strip()

    parse_expr = Syntax.ndpt_dp_rvalue


    _s2, _expr, commented = mark_unparsable(s, parse_expr)
    assert_equal(commented, set([2]))

    s="""   
mcdp {
 provides x [m]
    unp   
    requires a [m]
}""".strip()

    _s2, _expr, commented = mark_unparsable(s, parse_expr)

    
    assert_equal(commented, set([2]))
def parsing_error_recov04():
    s="""   
mcdp {
 provides x [m]
    unp   requires a [m]
}""".strip()

    parse_expr = Syntax.ndpt_dp_rvalue


    _s2, _expr, commented = mark_unparsable(s, parse_expr)
    assert_equal(commented, set([2]))

    s="""   
mcdp {
 provides x [m]
    unp   
    requires a [m]
}""".strip()

    _s2, _expr, commented = mark_unparsable(s, parse_expr)

    
    assert_equal(commented, set([2]))
Exemple #5
0
def format_syntax_error2(parse_expr, string, e):
    from mcdp_report.html import mark_unparsable
    string2, expr, _commented_lines = mark_unparsable(string, parse_expr)

    res = format_exception_for_ajax_response(e, quiet=(DPSyntaxError, ))
    if expr is not None:
        try:
            html = ast_to_html(string2,
                               ignore_line=None,
                               add_line_gutter=False,
                               encapsulate_in_precode=False,
                               parse_expr=parse_expr,
                               postprocess=None)

            res['highlight'] = html
        except DPSyntaxError:
            assert False, string2
    else:
        res['highlight'] = html_mark_syntax_error(string, e)

    return res
        def go():
            try:
                # XXX: inefficient; we parse twice
                parse_tree = parse_wrap(parse_expr, string)[0]
            except DPSemanticError as e:
                msg = 'I only expected a DPSyntaxError'
                raise_wrapped(DPInternalError, e, msg, exc=sys.exc_info())
            except DPSyntaxError as e:
                # This is the case in which we could not even parse
                from mcdp_report.html import mark_unparsable
                string2, expr, _commented_lines = mark_unparsable(string, parse_expr)
                
                res = format_exception_for_ajax_response(e, quiet=(DPSyntaxError,))
                if expr is not None:
                    try:
                        html = ast_to_html(string2,    ignore_line=None,
                                    add_line_gutter=False, encapsulate_in_precode=False, 
                                    parse_expr=parse_expr,   postprocess=None)
                
                        res['highlight'] = html
                    except DPSyntaxError:
                        assert False, string2
                else:
                    res['highlight'] = html_mark_syntax_error(string, e)
                 
                res['request'] = req
                return res
            
            try:
                class Tmp:
                    parse_tree_interpreted = None
                     
                def postprocess(block):
                    Tmp.parse_tree_interpreted = parse_refine(block, context)
                    return Tmp.parse_tree_interpreted
                
                try:
                    try:
                        highlight = ast_to_html(string,
                                                parse_expr=parse_expr,
                                                add_line_gutter=False,
                                                encapsulate_in_precode=False,
                                                postprocess=postprocess)
                    except DPSemanticError:
                        # Do it again without postprocess
                        highlight = ast_to_html(string,
                                                parse_expr=parse_expr,
                                                add_line_gutter=False,
                                                encapsulate_in_precode=False,
                                                postprocess=None)
                        raise
                    
                    thing = parse_eval(Tmp.parse_tree_interpreted, context)
                except (DPSemanticError, DPInternalError) as e:
                    highlight_marked = html_mark(highlight, e.where, "semantic_error")
                    self.last_processed2[key] = None  # XXX
                    res = format_exception_for_ajax_response(e, quiet=(DPSemanticError, DPInternalError))
                    res['highlight'] = highlight_marked
                    res['request'] = req
                    return res
                
                self.last_processed2[key] = thing
            except:
                self.last_processed2[key] = None  # XXX
                raise
            
            warnings = []
            for w in context.warnings:
                # w.msg
                warning = w.format_user()
                if w.where is not None:
                    highlight = html_mark(highlight, w.where, "language_warning")
                    
#                     wheres = format_where(w.where, context_before=0, mark=None, arrow=False, 
#                                           use_unicode=True, no_mark_arrow_if_longer_than=3)
#                     warning += '\n\n' + indent(wheres, '   ')
                warnings.append(warning.strip())
                    
            sep = '-' * 80
            language_warnings = ("\n\n" + sep + "\n\n").join(warnings)
            language_warnings_html = "\n".join(['<div class="language_warning">%s</div>' % w
                                      for w in warnings])
            
            return {'ok': True, 
                    'highlight': highlight,
                    'language_warnings': language_warnings, 
                    'language_warnings_html': language_warnings_html,
                    'request': req}
Exemple #7
0
def mark_unparsable_(s):
    parse_expr = Syntax.ndpt_dp_rvalue
    return mark_unparsable(s, parse_expr)
def mark_unparsable_(s):
    parse_expr = Syntax.ndpt_dp_rvalue
    return mark_unparsable(s, parse_expr)