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,10 +115,19 @@ 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
|
||||
with io.open(codefile, 'w') as code_filehandle:
|
||||
code_filehandle.write('''\
|
||||
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
|
||||
#include<stdlib.h> // by md-split
|
||||
#include<tuple> // by md-split
|
||||
|
@ -134,10 +143,9 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co
|
|||
using namespace std; // by md-split
|
||||
// %s : %s
|
||||
''' % (sourcefile, start_linenum))
|
||||
# TODO: if not toplevel code, wrap inside class
|
||||
for codeline in linebuffer:
|
||||
code_filehandle.write(codeline)
|
||||
return (line, linenum)
|
||||
# TODO: if not toplevel code, wrap inside class
|
||||
for codeline in linebuffer:
|
||||
code_filehandle.write(codeline)
|
||||
|
||||
|
||||
def is_code(line, indent_depth = 4):
|
||||
|
|
Loading…
Reference in New Issue
Block a user