(options, args=None, output=sys.stdout, lines=None)
| 547 | |
| 548 | |
| 549 | def main(options, args=None, output=sys.stdout, lines=None): |
| 550 | genline = next_line(args, lines) |
| 551 | |
| 552 | comment_set = [] |
| 553 | token_name = None |
| 554 | |
| 555 | # Create a new 'master' that serves as the coordinator for the file generation |
| 556 | master = Master() |
| 557 | for i in options.include: |
| 558 | master.add_include('#include <{}>'.format(i)) |
| 559 | |
| 560 | try: |
| 561 | while True: |
| 562 | ln, line = next(genline) |
| 563 | tokens = line.split(',') |
| 564 | token_type = tokens[0] |
| 565 | |
| 566 | if not bool(line): |
| 567 | master.add_comments(comment_set) |
| 568 | comment_set = [] |
| 569 | token_name = None |
| 570 | continue |
| 571 | |
| 572 | if len(tokens) > 2: |
| 573 | token_name = tokens[1] |
| 574 | |
| 575 | if token_type == 'subtype': |
| 576 | subtype, _, _ = master.add_type(tokens[1]) |
| 577 | |
| 578 | subtype.add_comments(list(comment_set)) |
| 579 | comment_set = [] |
| 580 | elif token_type == 'subtypedata': |
| 581 | subtype = master.find_type(tokens[1]) |
| 582 | if not subtype: |
| 583 | raise ValueError('Unknown subtype {} for data.\nat {}:{}' |
| 584 | .format(tokens[1], ln, line)) |
| 585 | type_obj, collapse, optional = master.add_type(tokens[3], tokens[2], tokens[1]) |
| 586 | if optional: |
| 587 | raise ValueError('Subtypes cannot have optional fields {}.{}\n at {}:{}' |
| 588 | .format(subtype.name, tokens[2], ln, line)) |
| 589 | if collapse: |
| 590 | count = 1 |
| 591 | else: |
| 592 | count = tokens[4] |
| 593 | |
| 594 | if tokens[3] in master.tlvs: |
| 595 | type_obj.tlv = master.tlvs[tokens[3]] |
| 596 | |
| 597 | subtype.add_data_field(tokens[2], type_obj, count, comments=list(comment_set), |
| 598 | optional=optional) |
| 599 | comment_set = [] |
| 600 | elif token_type == 'tlvtype': |
| 601 | # Hack: modern spec assumes tlvs, so if there's a type to |
| 602 | # attach this to, do it now, by assuming it's the same name |
| 603 | # with _tlvs appended. |
| 604 | if tokens[1].endswith("_tlvs"): |
| 605 | container_name = tokens[1][:-5] |
| 606 | msg = master.find_message(container_name) |
no test coverage detected