refactor python code extractor: extract function

This commit is contained in:
Thibault Kruse 2016-09-10 09:09:37 +09:00
parent 8e282fa90c
commit 1842b88c21

View File

@ -115,8 +115,17 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co
codefile = os.path.join(codedir, '%s%s.cpp' % (name, index))
if fenced:
text_filehandle.write('\n')
if (has_actual_code and not has_question_marks):
# add commonly used headers, so that lines can compile
write_with_harness(codefile, sourcefile, start_linenum, linebuffer)
return (line, linenum)
def write_with_harness(codefile, sourcefile, start_linenum, linebuffer):
'''write output with additional lines to make code likely compilable'''
# add commonly used headers, so that lines can likely compile.
# This is work in progress, the main issue remains handling class
# declarations in in-function code differently
with io.open(codefile, 'w') as code_filehandle:
code_filehandle.write('''\
#include<stdio.h> // by md-split
@ -137,7 +146,6 @@ using namespace std; // by md-split
# TODO: if not toplevel code, wrap inside class
for codeline in linebuffer:
code_filehandle.write(codeline)
return (line, linenum)
def is_code(line, indent_depth = 4):