MCPcopy Create free account
hub / github.com/defold/defold / parse_document

Function parse_document

engine/docs/script_doc.py:509–564  ·  view source on GitHub ↗
(doc_str, file=None)

Source from the content-addressed store, hash-verified

507 return False
508
509def parse_document(doc_str, file=None):
510 doc = script_doc_ddf_pb2.Document()
511 lst = re.findall(r'/\*[\*#](.*?)\*/', doc_str, re.DOTALL)
512 element_list = []
513 doc_info = None
514 for comment_str in lst:
515 element = _parse_comment(comment_str)
516 if type(element) is script_doc_ddf_pb2.Element:
517 element_list.append(element)
518 elif type(element) is script_doc_ddf_pb2.Info:
519 doc_info = element
520
521 if doc_info:
522 doc.info.CopyFrom(doc_info)
523
524 for i, e in enumerate(element_list):
525 doc.elements.add().MergeFrom(e)
526
527 if doc.info.language == "":
528 if doc.info.namespace.startswith("dm"):
529 doc.info.language = "C++"
530 else:
531 doc.info.language = "Lua"
532
533 if doc.info.name != "Editor":
534 print("Validating %s types in %s (%s) %s" % (doc.info.language, doc.info.name, doc.info.path, file))
535 errors = []
536 warnings = []
537 if doc.info.language == "Lua":
538 for element in doc.elements:
539 for param in element.parameters:
540 for t in param.types:
541 if param.name == "...":
542 continue
543 if not validate_lua_type(t, doc):
544 errors.append("'%s' has unknown type '%s' for parameter '%s' in file %s" % (element.name, t, param.name, file))
545 for returnvalue in element.returnvalues:
546 for t in returnvalue.types:
547 if not validate_lua_type(t, doc):
548 errors.append("'%s' has unknown type '%s' for return value '%s' in file %s" % (element.name, t, returnvalue.name, file))
549 elif doc.info.language == "C++":
550 for element in doc.elements:
551 for param in element.parameters:
552 for t in param.types:
553 if t == "":
554 warnings.append("'%s' has no type for parameter '%s' in file %s" % (element.name, param.name, file))
555 elif not validate_cpp_type(t, doc):
556 errors.append("'%s' has unknown type '%s' for parameter '%s' in file %s" % (element.name, t, param.name, file))
557
558 for warning in warnings:
559 print(" WARNING", warning)
560 for err in errors:
561 print(" ERROR", err)
562 if len(errors) > 0: raise Exception("Errors occurred when generating documentation")
563 # if len(warnings) > 0: sys.exit(1)
564 return doc
565
566def message_to_dict(message):

Callers 4

to_protobufFunction · 0.85
to_jsonFunction · 0.85
to_script_apiFunction · 0.85
to_lua_annotationFunction · 0.85

Calls 6

validate_lua_typeFunction · 0.85
validate_cpp_typeFunction · 0.85
appendMethod · 0.80
_parse_commentFunction · 0.70
addMethod · 0.65
printFunction · 0.50

Tested by

no test coverage detected