6.16.10.4. Document generator

Start python section to interscript/tanglers/python.py[4 /6 ] Next Prev First Last
   176: #line 192 "python_tangler.ipk"
   177: #-------------------------------------------------
   178: def weave_argument(weaver, indent, argument):
   179:   weaver.write_code_fragment(' '* indent)
   180:   weaver.write_code_fragment(argument.name, 'NAME')
   181:   if argument.protocol:
   182:     weaver.write_code_fragment(':', 'PUNCT')
   183:     weaver.write_code_fragment(' ')
   184:     weaver.write_code_fragment(argument.protocol, 'NAME')
   185:   if argument.default:
   186:     weaver.write_code_fragment('=', 'PUNCT')
   187:     weaver.write_code_fragment(argument.default)
   188:   if argument.description:
   189:     weaver.write_code_fragment(' ')
   190:     weaver.write_code_fragment(repr(argument.description), 'COMMENT')
   191: 
   192: def weave_arguments(weaver, indent, arguments):
   193:   for argument in arguments[:-1]:
   194:     weaver.start_code_line()
   195:     weave_argument(weaver, indent, argument)
   196:     weaver.write_code_fragment(',','PUNCT')
   197:     weaver.end_code_line()
   198:   weaver.start_code_line()
   199:   weave_argument(weaver, indent, arguments[-1])
   200: 
   201: def weave_function(
   202:   weaver,
   203:   indent,
   204:   name,
   205:   description=None,
   206:   arguments=None,
   207:   precondition=None,
   208:   result=None,
   209:   postcondition=None,
   210:   initial=None,
   211:   final=None,
   212:   body=None):
   213: 
   214:   weaver.start_code_line()
   215:   weaver.write_code_fragment(' '*indent)
   216:   weaver.write_code_fragment('function','KEYWORD')
   217:   weaver.write_code_fragment(' ')
   218:   weaver.write_code_fragment(name,'NAME')
   219:   weaver.write_code_fragment(':','PUNCT')
   220:   weaver.write_code_fragment(' ')
   221:   weaver.write_code_fragment('# '+description,'COMMENT')
   222:   weaver.end_code_line()
   223: 
   224:   if arguments:
   225:     weaver.start_code_line()
   226:     weaver.write_code_fragment(' '*(indent+2))
   227:     weaver.write_code_fragment('accepts','KEYWORD')
   228:     weaver.write_code_fragment(':','PUNCT')
   229:     weaver.end_code_line()
   230:     weave_arguments(weaver,indent+4,arguments)
   231:     weaver.end_code_line()
   232: 
   233:   if precondition:
   234:     weaver.start_code_line()
   235:     weaver.write_code_fragment(' '*(indent+2),)
   236:     weaver.write_code_fragment('precondition','KEYWORD')
   237:     weaver.write_code_fragment(':','PUNCT')
   238:     weaver.write_code_fragment(' ')
   239:     weaver.write_code_fragment(precondition)
   240:     weaver.end_code_line()
   241: 
   242:   if result:
   243:     weaver.start_code_line()
   244:     weaver.write_code_fragment(' '*(indent+2))
   245:     weaver.write_code_fragment('returns','KEYWORD')
   246:     weaver.end_code_line()
   247:     weave_arguments(weaver,indent+4,result)
   248:     weaver.end_code_line()
   249: 
   250:   if postcondition:
   251:     weaver.start_code_line()
   252:     weaver.write_code_fragment(' '*(indent+2))
   253:     weaver.write_code_fragment('postcondition','KEYWORD')
   254:     weaver.write_code_fragment(':','PUNCT')
   255:     weaver.write_code_fragment(' ')
   256:     weaver.write_code_fragment(postcondition)
   257:     weaver.end_code_line()
   258: 
   259:   if body:
   260:     for line in body:
   261:       weaver.start_code_line()
   262:       weaver.write_code_fragment(' '*(indent+2))
   263:       weaver.write_code_fragment(line)
   264:       weaver.end_code_line()
   265: 
End python section to interscript/tanglers/python.py[4]