def mdoc_structure_type((cu, die)): cv = (cu, die) # struct <name> " {" [<member>] " };" return bind(mdoc_name(cv), lambda name: bind(mdoc_decl_function_struct_type_getter(cv), lambda struct_getter: bind(unit(die.iter_children()), lambda members: bind(sequence([mdoc_member((cu, member)) for member in members]), lambda docMembers: unit(P.text("struct ") + name + P.space() + P.block(intersperse(docMembers, P.newline())) + P.text(";") + P.newline() + struct_getter)))))
def doc_decl_var(typeName, name, value): return typeName + P.space() + name + P.text(" = ") + value + P.text(";")
def doc_decl_function(retType, fname, params, body): assert body assert len(body) >= 2 assert body[0] == '{' return retType + P.space() + fname + P.text(" (") + intersperse(params, P.comma()) + P.text(") ") + body
def doc_exp_function_call(function_name, argList): return function_name + P.text("(") + intersperse(argList, P.comma() + P.space()) + P.text(")")
def mdoc_typedef_normal(cv): return bind(mdoc_name(cv), lambda name: bind(mdie_type(cv), lambda die_type: bind(mdoc_typeref(die_type), lambda srcType: unit(P.text("typedef ") + srcType + P.space() + name + P.text(";")))))
def mdoc_formalparameter(cv): # may not have name return bind(orElse(mdoc_name(cv), unit(P.space())), lambda name: bind(mdie_type(cv), lambda dieType: bind(mdoc_typeref(dieType), lambda typeref: unit(P.text(typeref) + P.space() + P.text(name)))))
def mdoc_member(cv): return bind(mdoc_name(cv), lambda name: bind(mdie_type(cv), lambda dieType: bind(mdoc_typeref(dieType), lambda typeref: unit(typeref + P.space() + name + P.text(";")))))
def mdoc_variable(cv): return bind(mdoc_name(cv), lambda name: bind(mdie_type(cv), lambda dieType: bind(mdoc_typeref(dieType), lambda typeref: unit(P.text(typeref) + P.space() + P.text(name) + P.text(";")))))