mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
refactor python code extractor: extract function
This commit is contained in:
parent
8e282fa90c
commit
1842b88c21
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user