def mark_errors(): s = """#comment mcdp { #@ syntax error }""" parse_expr = Syntax.ndpt_dp_rvalue x = parse_wrap(Syntax.ndpt_dp_rvalue, s)[0] context = Context() xr = parse_ndp_refine(x, context) suggestions = get_suggestions(xr) # make sure we can apply them _s2 = apply_suggestions(s, suggestions) def postprocess(block): x = parse_ndp_refine(block, context) return x html = ast_to_html(s, parse_expr=parse_expr, add_line_gutter=False, encapsulate_in_precode=False, postprocess=postprocess) text = project_html(html) s2 = """#comment mcdp { syntax error }""" assert_equal(text, s2) assert not '#@' in text
def check_syntax(filename, source, parse_expr=Syntax.ndpt_dp_rvalue): # @UnusedVariable # skip generated files (hack) if filename and 'drone_unc2_' in filename: return # print filename if filename is not None: source = open(filename).read() try: html = ast_to_html(source, parse_expr, ignore_line=lambda _lineno: False, add_line_gutter=False, encapsulate_in_precode=True, ) # print html.__repr__() source2 = project_html(html) # print source # print source2 # print indent(html, 'html |') assert_equal_string(s2_expected=source, s2=source2) except: logger.error('This happened to %r' % filename) raise
def max_len_of_pre_html(html): source2 = project_html(html) line_len = lambda _: len(unicode(_, 'utf-8').rstrip()) max_len = max(map(line_len, source2.split('\n'))) return max_len